Commit b2882aee authored by carlosperate's avatar carlosperate

Add Grove joystick and temperature module blocks.

parent dff25dd5
......@@ -16,7 +16,9 @@
" </value>",
" </block>",
" <block type=\"grove_button\"></block>",
" <block type=\"grove_joystick\"></block>",
" <block type=\"grove_pir\"></block>",
" <block type=\"grove_temperature\"></block>",
" <block type=\"grove_lcd_rgb\">",
" <value name=\"LINE_1\">",
" <block type=\"text\">",
......
......@@ -8,5 +8,10 @@ These blocks are still under development and more will be added soon. These are
* [LED](http://www.seeedstudio.com/wiki/Grove_-_LED)
* [Button](http://www.seeedstudio.com/wiki/Grove_-_Button)
* [Thumb Joystick](http://www.seeedstudio.com/wiki/Grove_-_Thumb_Joystick)
* [PIR Motion Sensor](http://www.seeedstudio.com/wiki/Grove_-_PIR_Motion_Sensor)
* [Temperature Sensor](http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor_V1.2)
* [LCD RGB Backlight](http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight) (only basic functionality), requires [this library](https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight) to be installed
All images from the `img` folder are license under [Creative Commons Attribution-ShareAlike License 3.0](http://creativecommons.org/licenses/by-sa/3.0/) as part of the SeeedStudio documentation. Minor modifications were made to remove their background, and the resulting files are also under the [Creative Commons Attribution-ShareAlike License 3.0](http://creativecommons.org/licenses/by-sa/3.0/) license.
......@@ -44,7 +44,7 @@ Blockly.Blocks['grove_led'] = {
this, 'CONNECTOR', 'groveDigital');
},
/**
* Returns a list with the connector used pins, either one or both.
* Returns a list with the connector used pins. For this block just the first.
* @this Blockly.Block
* @return {!Array<string>} List of used pins by this block.
*/
......@@ -72,10 +72,50 @@ Blockly.Blocks['grove_button'] = {
},
/** Updates the content of the the pin related fields. */
updateFields: Blockly.Blocks['grove_led'].updateFields,
/** Returns a list with the connector used pins, either one or both. */
/** Returns a list with the connector pins used. For this, just the first. */
connectorPinUsage: Blockly.Blocks['grove_led'].connectorPinUsage,
};
Blockly.Blocks['grove_joystick'] = {
/**
* Grove Joystick module block definition.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://www.seeedstudio.com/wiki/Grove_-_Thumb_Joystick');
this.setColour(Blockly.Blocks.groove.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldImage(
'/blocks/grove/img/joystick.png', 32, 32))
.appendField(Blockly.Msg.BLOCKS_GROVE_JOYSTICK)
.appendField(new Blockly.FieldDropdown(
[['x', '0'], ['y', '1']]), 'AXIS')
.appendField(Blockly.Msg.BLOCKS_GROVE_JOYSTICK_2)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.groveAnalog), 'CONNECTOR');
this.setOutput(true, Blockly.Types.NUMBER.basicType);
this.setTooltip(Blockly.Msg.BLOCKS_GROVE_JOYSTICK_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'CONNECTOR', 'groveAnalog');
},
/**
* Returns a list with the connector used pins. For this block both analogues.
* @this Blockly.Block
* @return {!Array<string>} List of used pins by this block.
*/
connectorPinUsage: function() {
var x = this.getFieldValue('CONNECTOR');
var y = 'A' + (parseInt(x.replace(/^\D+/g, '')) + 1);
return [x, y];
}
};
Blockly.Blocks['grove_pir'] = {
/**
* Grove PIR Motion Sensor module block definition.
......@@ -95,7 +135,31 @@ Blockly.Blocks['grove_pir'] = {
},
/** Updates the content of the the pin related fields. */
updateFields: Blockly.Blocks['grove_led'].updateFields,
/** Returns a list with the connector used pins, either one or both. */
/** Returns a list with the connector pins used. For this, just the first. */
connectorPinUsage: Blockly.Blocks['grove_led'].connectorPinUsage,
};
Blockly.Blocks['grove_temperature'] = {
/**
* Grove Temperature Sensor module block definition.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl(
'http://www.seeedstudio.com/wiki/Grove_-_Temperature_Sensor_V1.2');
this.setColour(Blockly.Blocks.groove.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldImage(
'/blocks/grove/img/temperature.png', 32, 32))
.appendField(Blockly.Msg.BLOCKS_GROVE_TEMPERATURE)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.groveAnalog), 'CONNECTOR');
this.setOutput(true, Blockly.Types.NUMBER.basicType);
this.setTooltip(Blockly.Msg.BLOCKS_GROVE_TEMPERATURE_TIP);
},
/** Updates the content of the the pin related fields.In this case analog. */
updateFields: Blockly.Blocks['grove_joystick'].updateFields,
/** Returns a list with the connector pins used. For this, just the first. */
connectorPinUsage: Blockly.Blocks['grove_led'].connectorPinUsage,
};
......
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="grove_lcd_rgb" x="4" y="94">
<value name="LINE_1">
<block type="text_join">
<mutation items="4"></mutation>
<value name="ADD0">
<block type="text">
<field name="TEXT">x: </field>
</block>
</value>
<value name="ADD1">
<block type="grove_joystick">
<field name="CONNECTOR">A0</field>
<field name="AXIS">0</field>
</block>
</value>
<value name="ADD2">
<block type="text">
<field name="TEXT">; y: </field>
</block>
</value>
<value name="ADD3">
<block type="grove_joystick">
<field name="CONNECTOR">A0</field>
<field name="AXIS">1</field>
</block>
</value>
</block>
</value>
<next>
<block type="time_delay">
<value name="DELAY_TIME_MILI">
<block type="math_number">
<field name="NUM">500</field>
</block>
</value>
</block>
</next>
</block>
</xml>
\ No newline at end of file
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="serial_setup" x="81" y="18">
<field name="SERIAL_ID">Serial</field>
<field name="SPEED">9600</field>
</block>
<block type="serial_print" x="81" y="124">
<field name="SERIAL_ID">Serial</field>
<field name="NEW_LINE">TRUE</field>
<value name="CONTENT">
<block type="text_join">
<mutation items="3"></mutation>
<value name="ADD0">
<block type="text">
<field name="TEXT">Temperature is: </field>
</block>
</value>
<value name="ADD1">
<block type="grove_temperature">
<field name="CONNECTOR">A1</field>
</block>
</value>
<value name="ADD2">
<block type="text">
<field name="TEXT"> ºC</field>
</block>
</value>
</block>
</value>
<next>
<block type="time_delay">
<value name="DELAY_TIME_MILI">
<block type="math_number">
<field name="NUM">500</field>
</block>
</value>
</block>
</next>
</block>
</xml>
\ No newline at end of file
......@@ -44,4 +44,5 @@ Blockly.Arduino.Groove.extendPinTypes = function() {
Blockly.Arduino.PinTypes.GROVE_BUTTON = 'GROVE BUTTON';
Blockly.Arduino.PinTypes.GROVE_JOYSTICK = 'GROVE JOYSTICK';
Blockly.Arduino.PinTypes.GROVE_PIR = 'GROVE PIR';
Blockly.Arduino.PinTypes.GROVE_TEMPERATURE = 'GROVE TEMPERATURE';
};
......@@ -55,6 +55,31 @@ Blockly.Arduino['grove_button'] = function(block) {
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
/**
* Function for reading Grove Joystick axis value. Connector uses both pins.
* Arduino code: setup { pinMode(X, INPUT);
pinMode(Y, INPUT); }
* loop { digitalRead(X or Y); }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {array} Completed code with order of operation.
*/
Blockly.Arduino['grove_joystick'] = function(block) {
var pins = block.connectorPinUsage();
var axis = block.getFieldValue('AXIS');
Blockly.Arduino.reservePin(block, pins[0],
Blockly.Arduino.PinTypes.GROVE_JOYSTICK, 'this Grove module');
Blockly.Arduino.reservePin(block, pins[1],
Blockly.Arduino.PinTypes.GROVE_JOYSTICK, 'this Grove module');
var pinSetupCode = 'pinMode(' + pins[0] + ', INPUT);';
Blockly.Arduino.addSetup('grove_joystic_' + pins[0], pinSetupCode, false);
pinSetupCode = 'pinMode(' + pins[1] + ', INPUT);';
Blockly.Arduino.addSetup('grove_joystick_' + pins[1], pinSetupCode, false);
var code = 'analogRead(' + pins[axis] + ')';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
/**
* Function for reading Grove PIR sensor state. Connector uses only 1 pin.
* Arduino code: setup { pinMode(X, INPUT); }
......@@ -74,10 +99,34 @@ Blockly.Arduino['grove_pir'] = function(block) {
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
/**
* Function for reading Grove Temperature sensor. Connector uses both one pin.
* Value is calculate on centigrades based on data sheet information.
* Arduino code: setup { pinMode(X, INPUT) }
* loop { 1.0/(log((1023.0/((float)analogRead(X))-1.0))/
4275+1/298.15)-273.15; }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {array} Completed code with order of operation.
*/
Blockly.Arduino['grove_temperature'] = function(block) {
var pins = block.connectorPinUsage();
Blockly.Arduino.reservePin(block, pins[0],
Blockly.Arduino.PinTypes.GROVE_TEMPERATURE, 'this Grove module');
var pinSetupCode = 'pinMode(' + pins[0] + ', INPUT);';
Blockly.Arduino.addSetup('grove_temperature_' + pins[0], pinSetupCode, false);
var code = '1.0/(log((1023.0/((float)analogRead(' + pins[0] + '))-1.0))' +
'/4275+1/298.15)-273.15';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
/**
* Function setting a Grove LCD RGB Backlight message. Connector uses I2C.
* Arduino code: setup { pinMode(X, INPUT); }
* loop { digitalRead(X); }
* Arduino code: setup { lcd.begin(16, 2);
lcd.setRGB(0, 255, 0); }
* loop { lcd.clear();
lcd.print(X); }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {array} Completed code with order of operation.
*/
......@@ -98,6 +147,6 @@ Blockly.Arduino['grove_lcd_rgb'] = function(block) {
Blockly.Arduino.addSetup('grove_lcd_rgb_init', 'lcd.begin(16, 2);', false);
Blockly.Arduino.addSetup('grove_lcd_rgb_colour', 'lcd.setRGB(0, 255, 0);');
var code = 'lcd.clear();\nlcd.print(' + line1Text + ');';
var code = 'lcd.clear();\nlcd.print(' + line1Text + ');\n';
return code;
};
......@@ -24,13 +24,22 @@ Blockly.Msg.BLOCKS_GROVE_LED = 'set Grove LED on connector';
Blockly.Msg.BLOCKS_GROVE_LED_TIP = 'Turns the LED On (HIGH) or Off (LOW).';
/// Button block
Blockly.Msg.BLOCKS_GROVE_BUTTON = 'read Grove Button on connector';
Blockly.Msg.BLOCKS_GROVE_BUTTON = 'read Grove Button pressed state on connector';
Blockly.Msg.BLOCKS_GROVE_BUTTON_TIP = 'Set to HIGH when the button is pressed, otherwise LOW.';
/// Joystick block
Blockly.Msg.BLOCKS_GROVE_JOYSTICK = 'read Grove Joystick axis';
Blockly.Msg.BLOCKS_GROVE_JOYSTICK_2 = 'on connector';
Blockly.Msg.BLOCKS_GROVE_JOYSTICK_TIP = 'Reads the joystick position value from 200-800.';
/// PIR block
Blockly.Msg.BLOCKS_GROVE_PIR = 'read Grove PIR on connector';
Blockly.Msg.BLOCKS_GROVE_PIR = 'read Grove PIR state on connector';
Blockly.Msg.BLOCKS_GROVE_PIR_TIP = 'On motion sense it outputs HIGH, otherwise LOW.';
/// Temperature block
Blockly.Msg.BLOCKS_GROVE_TEMPERATURE = 'read Grove Temperature on connector';
Blockly.Msg.BLOCKS_GROVE_TEMPERATURE_TIP = 'Returns the temperate in ºC.';
/// LCD RGB block
Blockly.Msg.BLOCKS_GROVE_LCD_RGB = 'set LCD RGB text to';
Blockly.Msg.BLOCKS_GROVE_LCD_RGB = 'set Grove LCD RGB text to';
Blockly.Msg.BLOCKS_GROVE_LCD_RGB_TIP = 'Sets the text on the LCD display.';
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment