Commit b26b7884 authored by carlosperate's avatar carlosperate

Fix analogWrite to list only PWM pins and warn if input is out of range.

Fixes #30
parent bd5bfff6
......@@ -124,7 +124,7 @@ Blockly.Blocks['io_analogwrite'] = {
this.appendDummyInput('')
.appendField('set analogue pin#')
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.analogPins), 'PIN');
Blockly.Arduino.Boards.selected.pwmPins), 'PIN');
this.appendValueInput('NUM', Blockly.StaticTyping.BlocklyType.NUMBER)
.appendField('to')
.setCheck(Blockly.StaticTyping.BlocklyType.NUMBER);
......@@ -138,7 +138,7 @@ Blockly.Blocks['io_analogwrite'] = {
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, 'PIN', 'analogPins');
Blockly.Arduino.Boards.refreshBlockFieldDropdown(this, 'PIN', 'pwmPins');
},
/** @return {!string} The type of input value for the block, an integer. */
getBlockType: function() {
......
......@@ -94,6 +94,14 @@ Blockly.Arduino['io_analogwrite'] = function(block) {
var pinSetupCode = 'pinMode(' + pin + ', OUTPUT);';
Blockly.Arduino.addSetup('io_' + pin, pinSetupCode, false);
// Warn if the input value is out of range
if ( (stateOutput < 0) || (stateOutput > 255)) {
block.setWarningText('The analgue value must be between 0 and 255',
'pwm_value');
} else {
block.setWarningText(null, 'pwm_value');
}
var code = 'analogWrite(' + pin + ',' + stateOutput + ');\n';
return code;
};
......
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