Skip to content

Commit

Permalink
fix: set correct right servo motor direction (#128)
Browse files Browse the repository at this point in the history
* fix: add newlines before setup()
* chore: bump version
  • Loading branch information
rmoesbergen authored Oct 13, 2024
1 parent b608f5f commit 8e2c8e2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dist",
"media"
],
"version": "3.2.1",
"version": "3.2.2",
"description": "Leaphy custom Blockly blocks and arduino code generator",
"name": "@leaphy-robotics/leaphy-blocks"
}
2 changes: 1 addition & 1 deletion src/generators/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class Arduino extends Blockly.Generator {
definitions.join("\n") +
declarations.join("\n");
const setup =
"void setup() {\n\t" +
"\n\nvoid setup() {\n\t" +
setups.join("\n ") +
`\n ${userSetup}\n}\n\n`;
const loop = "void loop() {\n " + code.replace(/\n/g, "\n ") + "\n}";
Expand Down
3 changes: 2 additions & 1 deletion src/generators/arduino/leaphy_original.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ function getCodeGenerators(arduino: Arduino) {
const motor = block.getFieldValue("MOTOR");
const speed =
arduino.valueToCode(block, "SPEED", arduino.ORDER_ATOMIC) || "100";
const direction = motor == "left" ? 1 : -1;

return `servo_${motor}.write(90 + 90*${speed}/100);\n`;
return `servo_${motor}.write(90 + 90*${speed}/100*${direction});\n`;
};

arduino.forBlock["leaphy_original_servo_move"] = function (block) {
Expand Down

0 comments on commit 8e2c8e2

Please sign in to comment.