13
13
import Blockly from "blockly/core" ;
14
14
import { selectedBoard } from "../helpers/board" ;
15
15
import * as Types from "../helpers/types" ;
16
+ import { getColour } from "../helpers/colour" ;
16
17
17
18
Blockly . Blocks [ "io_digitalwrite" ] = {
18
19
/**
@@ -21,7 +22,7 @@ Blockly.Blocks["io_digitalwrite"] = {
21
22
*/
22
23
init : function ( ) {
23
24
this . setHelpUrl ( "http://arduino.cc/en/Reference/DigitalWrite" ) ;
24
- this . setColour ( 250 ) ;
25
+ this . setColour ( getColour ( ) . io ) ;
25
26
this . appendValueInput ( "STATE" )
26
27
. appendField ( Blockly . Msg . ARD_DIGITALWRITE )
27
28
. appendField (
@@ -55,7 +56,7 @@ Blockly.Blocks["io_digitalread"] = {
55
56
*/
56
57
init : function ( ) {
57
58
this . setHelpUrl ( "http://arduino.cc/en/Reference/DigitalRead" ) ;
58
- this . setColour ( 250 ) ;
59
+ this . setColour ( getColour ( ) . io ) ;
59
60
this . appendDummyInput ( )
60
61
. appendField ( Blockly . Msg . ARD_DIGITALREAD )
61
62
. appendField (
@@ -89,7 +90,7 @@ Blockly.Blocks["io_builtin_led"] = {
89
90
*/
90
91
init : function ( ) {
91
92
this . setHelpUrl ( "http://arduino.cc/en/Reference/DigitalWrite" ) ;
92
- this . setColour ( 250 ) ;
93
+ this . setColour ( getColour ( ) . io ) ;
93
94
this . appendValueInput ( "STATE" )
94
95
. appendField ( Blockly . Msg . ARD_BUILTIN_LED )
95
96
. appendField (
@@ -127,7 +128,7 @@ Blockly.Blocks["io_analogwrite"] = {
127
128
*/
128
129
init : function ( ) {
129
130
this . setHelpUrl ( "http://arduino.cc/en/Reference/AnalogWrite" ) ;
130
- this . setColour ( 250 ) ;
131
+ this . setColour ( getColour ( ) . io ) ;
131
132
this . appendValueInput ( "NUM" )
132
133
. appendField ( Blockly . Msg . ARD_ANALOGWRITE )
133
134
. appendField ( new Blockly . FieldDropdown ( selectedBoard ( ) . pwmPins ) , "PIN" )
@@ -158,7 +159,7 @@ Blockly.Blocks["io_analogread"] = {
158
159
*/
159
160
init : function ( ) {
160
161
this . setHelpUrl ( "http://arduino.cc/en/Reference/AnalogRead" ) ;
161
- this . setColour ( 250 ) ;
162
+ this . setColour ( getColour ( ) . io ) ;
162
163
this . appendDummyInput ( )
163
164
. appendField ( Blockly . Msg . ARD_ANALOGREAD )
164
165
. appendField (
@@ -188,7 +189,7 @@ Blockly.Blocks["io_highlow"] = {
188
189
*/
189
190
init : function ( ) {
190
191
this . setHelpUrl ( "http://arduino.cc/en/Reference/Constants" ) ;
191
- this . setColour ( 250 ) ;
192
+ this . setColour ( getColour ( ) . io ) ;
192
193
this . appendDummyInput ( ) . appendField (
193
194
new Blockly . FieldDropdown ( [
194
195
[ Blockly . Msg . ARD_HIGH , "HIGH" ] ,
@@ -228,7 +229,7 @@ Blockly.Blocks["io_pulsein"] = {
228
229
] ,
229
230
output : Types . NUMBER . typeName ,
230
231
inputsInline : true ,
231
- colour : 250 ,
232
+ colour : getColour ( ) . io ,
232
233
tooltip : Blockly . Msg . ARD_PULSE_TIP ,
233
234
helpUrl : "https://www.arduino.cc/en/Reference/PulseIn" ,
234
235
} ) ;
@@ -268,7 +269,7 @@ Blockly.Blocks["io_pulsetimeout"] = {
268
269
] ,
269
270
output : Types . NUMBER . typeName ,
270
271
inputsInline : true ,
271
- colour : 250 ,
272
+ colour : getColour ( ) . io ,
272
273
tooltip : Blockly . Msg . ARD_PULSETIMEOUT_TIP ,
273
274
helpUrl : "https://www.arduino.cc/en/Reference/PulseIn" ,
274
275
} ) ;
@@ -278,3 +279,37 @@ Blockly.Blocks["io_pulsetimeout"] = {
278
279
return Types . NUMBER . typeName ;
279
280
} ,
280
281
} ;
282
+
283
+ Blockly . Blocks [ "io_analogreadmillivolt" ] = {
284
+ /**
285
+ * Block for reading an analogue input.
286
+ * @this Blockly.Block
287
+ */
288
+ init : function ( ) {
289
+ this . setHelpUrl (
290
+ "https://docs.espressif.com/projects/arduino-esp32/en/latest/api/adc.html"
291
+ ) ;
292
+ this . setColour ( getColour ( ) . io ) ;
293
+ this . appendDummyInput ( )
294
+ . appendField ( Blockly . Msg . ARD_ANALOGREADMILIVOLT )
295
+ . appendField ( "Port:" )
296
+ . appendField (
297
+ new Blockly . FieldDropdown ( selectedBoard ( ) . digitalPorts ) ,
298
+ "Port"
299
+ ) ;
300
+
301
+ this . setOutput ( true , Types . NUMBER . typeName ) ;
302
+ this . setTooltip ( Blockly . Msg . ARD_ANALOGREADMILIVOLT_TIP ) ;
303
+ } ,
304
+ /** @return {!string } The type of return value for the block, an integer. */
305
+ getBlockType : function ( ) {
306
+ return Types . NUMBER . typeName ;
307
+ } ,
308
+ /**
309
+ * Updates the content of the the pin related fields.
310
+ * @this Blockly.Block
311
+ */
312
+ updateFields : function ( ) {
313
+ Blockly . Arduino . Boards . refreshBlockFieldDropdown ( this , "PIN" , "analogPins" ) ;
314
+ } ,
315
+ } ;
0 commit comments