Skip to content

Commit

Permalink
updated pwm blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanaculic committed Nov 5, 2024
1 parent ee235d0 commit b38d194
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function (blockly) {
Blockly.Python['pwm_initialize'] = function(block) {
Blockly.Python.import_machine();
var value_pin = Blockly.Python.valueToCode(block, 'pin', Blockly.Python.ORDER_ATOMIC);
var frequency = block.getFieldValue('frequency').toString();
//var frequency = block.getFieldValue('frequency').toString();

var code = pin_name + ' = machine.PWM(machine.Pin(' + value_pin + '))\n';

Check failure on line 48 in source/plugins/languages/visual/libraries/micropython/visual/code_micropython.js

View workflow job for this annotation

GitHub Actions / format

'pin_name' is not defined
return code;
Expand All @@ -52,7 +52,7 @@ module.exports = function (blockly) {
Blockly.Python['pwm_set_frequency'] = function(block) {
Blockly.Python.import_machine();
var frequency = Blockly.Python.valueToCode(block, 'frequency', Blockly.Python.ORDER_ATOMIC);
var pin_name = block.getFieldValue('pin').toString();
var pin_name = block.getFieldValue('pin_name').toString();

var code = pin_name + '.frequency(' + frequency + ')\n';
return code;
Expand All @@ -61,7 +61,7 @@ module.exports = function (blockly) {
Blockly.Python['pwm_set_duty_cycle'] = function(block) {
Blockly.Python.import_machine();
var duty_cycle = Blockly.Python.valueToCode(block, 'duty_cycle', Blockly.Python.ORDER_ATOMIC);
var pin_name = block.getFieldValue('pin').toString();
var pin_name = block.getFieldValue('pin_name').toString();

duty_cycle = parseInt(Math.floor(Math.min(100, Math.max (duty_cycle, 0)) * 65535 / 100));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ module.exports = function (blockly) {
this.appendValueInput('frequency')
.appendField('Set frequency');
this.appendDummyInput()
.appendField('Hz for pin');
this.appendValueInput('pin');
.appendField('Hz for pin')
.appendField(new Blockly.FieldTextInput('pinName1'), 'pin_name');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(false);
Expand All @@ -243,8 +243,8 @@ module.exports = function (blockly) {
this.appendValueInput('duty_cycle')
.appendField('Set duty cycle');
this.appendDummyInput()
.appendField('% for pin');
this.appendValueInput('pin');
.appendField('% for pin')
.appendField(new Blockly.FieldTextInput('pinName1'), 'pin_name');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(false);
Expand Down

0 comments on commit b38d194

Please sign in to comment.