basic101.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. 'use strict';
  2. goog.provide('Blockly.Blocks.basic101');
  3. goog.require('Blockly.Blocks');
  4. Blockly.Blocks.basic101.hue = 15;
  5. Blockly.Blocks['read_button'] = {
  6. init: function() {
  7. this.interpolate_(Blockly.Msg.BASIC_READBUTTON, [{
  8. "type": "input_value",
  9. "name": "PINSNUM",
  10. "check": Blockly.Types.NUMBER.checkList,
  11. }]);
  12. this.setInputsInline(true);
  13. this.setOutput(true, Blockly.Types.BOOLEAN.output);
  14. this.setColour(Blockly.Blocks.basic101.hue);
  15. this.setTooltip("");
  16. this.setHelpUrl("");
  17. },
  18. getBlockType: function() {
  19. return Blockly.Types.BOOLEAN;
  20. }
  21. };
  22. Blockly.Blocks['basic101_dropdown_button'] = {
  23. /**
  24. * Block for creating a digtial pin selector.
  25. * @this Blockly.Block
  26. */
  27. init: function() {
  28. this.appendDummyInput()
  29. .appendField(new Blockly.FieldDropdown([
  30. ["8", "8"],
  31. ["9", "9"],
  32. ["12", "12"],
  33. ["13", "13"]
  34. ]), 'SELECTPIN');
  35. this.setOutput(true, Blockly.Types.NUMBER.output);
  36. this.setColour(Blockly.Blocks.io.HUE);
  37. },
  38. /** @return {!string} The type of return value for the block, an integer. */
  39. getBlockType: function() {
  40. return Blockly.Types.NUMBER;
  41. }
  42. };
  43. Blockly.Blocks['read_knob'] = {
  44. init: function() {
  45. this.interpolate_(Blockly.Msg.BASIC_READKNOB, [{
  46. "type": "input_value",
  47. "name": "PINSNUM",
  48. "check": Blockly.Types.NUMBER.checkList,
  49. }]);
  50. this.setInputsInline(true);
  51. this.setOutput(true, Blockly.Types.NUMBER.output);
  52. this.setColour(Blockly.Blocks.basic101.hue);
  53. this.setTooltip("");
  54. this.setHelpUrl("");
  55. },
  56. getBlockType: function() {
  57. return Blockly.Types.NUMBER;
  58. }
  59. };
  60. Blockly.Blocks['basic101_dropdown_knob'] = {
  61. /**
  62. * Block for creating a digtial pin selector.
  63. * @this Blockly.Block
  64. */
  65. init: function() {
  66. this.appendDummyInput()
  67. .appendField(new Blockly.FieldDropdown([
  68. ["A3", "A3"]
  69. ]), 'SELECTPIN');
  70. this.setOutput(true, Blockly.Types.NUMBER.output);
  71. this.setColour(Blockly.Blocks.io.HUE);
  72. },
  73. /** @return {!string} The type of return value for the block, an integer. */
  74. getBlockType: function() {
  75. return Blockly.Types.NUMBER;
  76. }
  77. };
  78. Blockly.Blocks['analog_light'] = {
  79. init: function() {
  80. this.interpolate_(Blockly.Msg.BASIC_SETANALOGLED, [{
  81. "type": "input_value",
  82. "name": "PINSNUM",
  83. "check": Blockly.Types.NUMBER.checkList
  84. },
  85. {
  86. "type": "input_value",
  87. "name": "BRIGHTNESS",
  88. "check": Blockly.Types.NUMBER.checkList
  89. }
  90. ]);
  91. this.setInputsInline(true);
  92. this.setPreviousStatement(true);
  93. this.setNextStatement(true);
  94. this.setColour(Blockly.Blocks.basic101.hue);
  95. this.setTooltip('');
  96. this.setHelpUrl('');
  97. },
  98. onchange: function() {
  99. var bright = Blockly.Python.valueToCode(this, "BRIGHTNESS", Blockly.Python.ORDER_ATOMIC)
  100. if (bright > 255 || bright < 0) {
  101. this.setWarningText(Blockly.Msg.BASIC_LIGHT_WARNING, 'light');
  102. } else {
  103. this.setWarningText(null, 'light');
  104. }
  105. },
  106. getBlockType: function() {
  107. return Blockly.Types.NUMBER;
  108. }
  109. };
  110. Blockly.Blocks['basic101_dropdown_analog_light'] = {
  111. /**
  112. * Block for creating a digtial pin selector.
  113. * @this Blockly.Block
  114. */
  115. init: function() {
  116. this.appendDummyInput()
  117. .appendField(new Blockly.FieldDropdown([
  118. ["3", "3"],
  119. ["5", "5"],
  120. ["6", "6"],
  121. ]), 'SELECTPIN');
  122. this.setOutput(true, Blockly.Types.NUMBER.output);
  123. this.setColour(Blockly.Blocks.io.HUE);
  124. },
  125. /** @return {!string} The type of return value for the block, an integer. */
  126. getBlockType: function() {
  127. return Blockly.Types.NUMBER;
  128. }
  129. };
  130. Blockly.Blocks['digital_light'] = {
  131. init: function() {
  132. this.interpolate_(Blockly.Msg.BASIC_SETDIGITALLED, [{
  133. "type": "input_value",
  134. "name": "PINSNUM",
  135. "check": Blockly.Types.NUMBER.checkList
  136. }]);
  137. this.setInputsInline(true);
  138. this.setPreviousStatement(true);
  139. this.setNextStatement(true);
  140. this.setColour(Blockly.Blocks.basic101.hue);
  141. this.setTooltip('');
  142. this.setHelpUrl('');
  143. }
  144. };
  145. Blockly.Blocks['basic101_dropdown_digital_light'] = {
  146. /**
  147. * Block for creating a digtial pin selector.
  148. * @this Blockly.Block
  149. */
  150. init: function() {
  151. this.appendDummyInput()
  152. .appendField(new Blockly.FieldDropdown([
  153. ["0", "0"],
  154. ["1", "1"],
  155. ["2", "2"],
  156. ["3", "3"],
  157. ["4", "4"],
  158. ["5", "5"],
  159. ["6", "6"],
  160. ]), 'SELECTPIN');
  161. this.setOutput(true, Blockly.Types.NUMBER.output);
  162. this.setColour(Blockly.Blocks.io.HUE);
  163. },
  164. /** @return {!string} The type of return value for the block, an integer. */
  165. getBlockType: function() {
  166. return Blockly.Types.NUMBER;
  167. }
  168. };
  169. Blockly.Blocks['nolight'] = {
  170. init: function() {
  171. this.interpolate_(Blockly.Msg.BASIC_NOLCD, [{
  172. "type": "input_value",
  173. "name": "PINSNUM",
  174. "check": Blockly.Types.NUMBER.checkList
  175. }]);
  176. this.setInputsInline(true);
  177. this.setPreviousStatement(true);
  178. this.setNextStatement(true);
  179. this.setColour(Blockly.Blocks.basic101.hue);
  180. this.setTooltip();
  181. this.setHelpUrl('');
  182. }
  183. };
  184. Blockly.Blocks['basic101_dropdown_nolight'] = {
  185. /**
  186. * Block for creating a digtial pin selector.
  187. * @this Blockly.Block
  188. */
  189. init: function() {
  190. this.appendDummyInput()
  191. .appendField(new Blockly.FieldDropdown([
  192. ["0", "0"],
  193. ["1", "1"],
  194. ["2", "2"],
  195. ["3", "3"],
  196. ["4", "4"],
  197. ["5", "5"],
  198. ["6", "6"],
  199. ]),
  200. 'SELECTPIN');
  201. this.setOutput(true, Blockly.Types.NUMBER.output);
  202. this.setColour(Blockly.Blocks.io.HUE);
  203. },
  204. /** @return {!string} The type of return value for the block, an integer. */
  205. getBlockType: function() {
  206. return Blockly.Types.NUMBER;
  207. }
  208. };
  209. Blockly.Blocks['tone'] = {
  210. init: function() {
  211. this.interpolate_(Blockly.Msg.BASIC_SETTONE, [{
  212. "type": "input_value",
  213. "name": "PINSNUM",
  214. "check": Blockly.Types.NUMBER.checkList
  215. },
  216. {
  217. "type": "input_value",
  218. "name": "FREQUENCY",
  219. "check": Blockly.Types.NUMBER.checkList
  220. }
  221. ]);
  222. this.setInputsInline(true);
  223. this.setPreviousStatement(true);
  224. this.setNextStatement(true);
  225. this.setColour(Blockly.Blocks.basic101.hue);
  226. this.setTooltip(Blockly.Msg.BASIC_TONE_TIP);
  227. this.setHelpUrl('https://www.arduino.cc/en/Reference/tone');
  228. },
  229. onchange: function() {
  230. var freq = Blockly.Python.valueToCode(this, "FREQUENCY", Blockly.Python.ORDER_ATOMIC)
  231. if (freq < 31 || freq > 65535) {
  232. this.setWarningText(Blockly.Msg.BASIC_TONE_WARNING, 'io_tone');
  233. } else {
  234. this.setWarningText(null, 'io_tone');
  235. }
  236. },
  237. /** @return {!string} The type of input value for the block, an integer. */
  238. getBlockType: function() {
  239. return Blockly.Types.NUMBER;
  240. }
  241. };
  242. Blockly.Blocks['basic101_dropdown_tone'] = {
  243. /**
  244. * Block for creating a digtial pin selector.
  245. * @this Blockly.Block
  246. */
  247. init: function() {
  248. this.appendDummyInput()
  249. .appendField(new Blockly.FieldDropdown([
  250. ["11", "11"]
  251. ]),
  252. 'SELECTPIN');
  253. this.setOutput(true, Blockly.Types.NUMBER.output);
  254. this.setColour(Blockly.Blocks.io.HUE);
  255. },
  256. /** @return {!string} The type of return value for the block, an integer. */
  257. getBlockType: function() {
  258. return Blockly.Types.NUMBER;
  259. }
  260. };
  261. Blockly.Blocks['notone'] = {
  262. init: function() {
  263. this.interpolate_(Blockly.Msg.BASIC_NOTONE, [{
  264. "type": "input_value",
  265. "name": "PINSNUM",
  266. "check": Blockly.Types.NUMBER.checkList
  267. }]);
  268. this.setInputsInline(true);
  269. this.setPreviousStatement(true);
  270. this.setNextStatement(true);
  271. this.setColour(Blockly.Blocks.basic101.hue);
  272. this.setTooltip(Blockly.Msg.BASIC_NOTONE_TIP);
  273. this.setHelpUrl('https://www.arduino.cc/en/Reference/noTone');
  274. }
  275. };
  276. Blockly.Blocks['basic101_dropdown_notone'] = {
  277. /**
  278. * Block for creating a digtial pin selector.
  279. * @this Blockly.Block
  280. */
  281. init: function() {
  282. this.appendDummyInput()
  283. .appendField(new Blockly.FieldDropdown([
  284. ["11", "11"]
  285. ]),
  286. 'SELECTPIN');
  287. this.setOutput(true, Blockly.Types.NUMBER.output);
  288. this.setColour(Blockly.Blocks.io.HUE);
  289. },
  290. /** @return {!string} The type of return value for the block, an integer. */
  291. getBlockType: function() {
  292. return Blockly.Types.NUMBER;
  293. }
  294. };
  295. Blockly.Blocks['basic101_dropdown_digital'] = {
  296. /**
  297. * Block for creating a digtial pin selector.
  298. * @this Blockly.Block
  299. */
  300. init: function() {
  301. this.appendDummyInput()
  302. .appendField(new Blockly.FieldDropdown(
  303. Blockly.Python.Boards.selected.digitalPins), 'SELECTPIN');
  304. this.setOutput(true, Blockly.Types.NUMBER.output);
  305. this.setColour(Blockly.Blocks.io.HUE);
  306. },
  307. /** @return {!string} The type of return value for the block, an integer. */
  308. getBlockType: function() {
  309. return Blockly.Types.NUMBER;
  310. }
  311. };
  312. Blockly.Blocks['basic101_dropdown_analog'] = {
  313. /**
  314. * Block for creating a analog pin selector.
  315. * @this Blockly.Block
  316. */
  317. init: function() {
  318. this.appendDummyInput()
  319. .appendField(new Blockly.FieldDropdown(
  320. Blockly.Python.Boards.selected.analogPins), 'SELECTPIN');
  321. this.setOutput(true, Blockly.Types.NUMBER.output);
  322. this.setColour(Blockly.Blocks.io.HUE);
  323. },
  324. /** @return {!string} The type of return value for the block, an integer. */
  325. getBlockType: function() {
  326. return Blockly.Types.NUMBER;
  327. }
  328. };
  329. Blockly.Blocks['basic101_dropdown_pwm'] = {
  330. /**
  331. * Block for creating a analog pin selector.
  332. * @this Blockly.Block
  333. */
  334. init: function() {
  335. this.appendDummyInput()
  336. .appendField(new Blockly.FieldDropdown(
  337. Blockly.Python.Boards.selected.pwmPins), 'SELECTPIN');
  338. this.setOutput(true, Blockly.Types.NUMBER.output);
  339. this.setColour(Blockly.Blocks.io.HUE);
  340. },
  341. /** @return {!string} The type of return value for the block, an integer. */
  342. getBlockType: function() {
  343. return Blockly.Types.NUMBER;
  344. }
  345. };
  346. Blockly.Blocks['counter_button_setup'] = {
  347. init: function() {
  348. this.appendDummyInput()
  349. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_motorDriver.png", 140, 40, "15"));
  350. .appendField(new Blockly.FieldImage("./../blockly/media/main-sensor101-counter.png", 50, 40, "15"));
  351. this.appendDummyInput()
  352. .appendField(Blockly.Msg.BASIC_COUNTER_SETUP)
  353. this.appendDummyInput()
  354. .appendField(Blockly.Msg.BASIC_COUNTER_SETTING)
  355. .appendField(new Blockly.FieldDropdown(Blockly.Python.Boards.selected.digitalPins), 'PINSNUM');
  356. // this.interpolate_(Blockly.Msg.BASIC_COUNTER_SETUP, [
  357. // {
  358. // "type": "input_value",
  359. // "name": "PINSNUM",
  360. // "check": Blockly.Types.NUMBER.checkList,
  361. // }
  362. // ]);
  363. //this.setInputsInline(true);
  364. //this.setOutput(true, Blockly.Types.BOOLEAN.output);
  365. this.setColour(Blockly.Blocks.basic101.hue);
  366. this.setTooltip("");
  367. this.setHelpUrl("");
  368. },
  369. /** @return {!string} The type of return value for the block, an integer. */
  370. getBlockType: function() {
  371. return Blockly.Types.NUMBER;
  372. }
  373. };
  374. Blockly.Blocks['read_counter'] = {
  375. init: function() {
  376. this.interpolate_(Blockly.Msg.BASIC_READCOUNTER, [{
  377. "type": "input_value",
  378. "name": "PINSNUM",
  379. "check": Blockly.Types.NUMBER.checkList,
  380. }]);
  381. this.setInputsInline(true);
  382. this.setOutput(true, Blockly.Types.NUMBER.output);
  383. this.setColour(Blockly.Blocks.basic101.hue);
  384. this.setTooltip("");
  385. this.setHelpUrl("");
  386. },
  387. getBlockType: function() {
  388. return Blockly.Types.NUMBER;
  389. }
  390. };
  391. Blockly.Blocks['basic101_counter_dropdown_button'] = {
  392. /**
  393. * Block for creating a digtial pin selector.
  394. * @this Blockly.Block
  395. */
  396. init: function() {
  397. this.appendDummyInput()
  398. .appendField(new Blockly.FieldDropdown([
  399. ["8", "8"],
  400. ["9", "9"],
  401. ]), 'SELECTPIN');
  402. this.setOutput(true, Blockly.Types.NUMBER.output);
  403. this.setColour(Blockly.Blocks.io.HUE);
  404. },
  405. /** @return {!string} The type of return value for the block, an integer. */
  406. getBlockType: function() {
  407. return Blockly.Types.NUMBER;
  408. }
  409. };