diff --git a/package.json b/package.json index e6dc0e0..24cc8ca 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dist", "media" ], - "version": "3.3.1", + "version": "3.3.2", "description": "Leaphy custom Blockly blocks and arduino code generator", "name": "@leaphy-robotics/leaphy-blocks" } diff --git a/src/generators/arduino/leaphy_original.ts b/src/generators/arduino/leaphy_original.ts index dabbd49..6b3c77f 100644 --- a/src/generators/arduino/leaphy_original.ts +++ b/src/generators/arduino/leaphy_original.ts @@ -37,9 +37,13 @@ function getCodeGenerators(arduino: Arduino) { arduino.forBlock["leaphy_original_set_motor"] = function (block) { const dropdown_Type = block.getFieldValue("MOTOR_TYPE"); - const speed = + let speed = arduino.valueToCode(block, "MOTOR_SPEED", arduino.ORDER_ATOMIC) || "100"; + // Map the speed to a range of 150 - 255 to compensate for low PWM signal voltage + if (parseInt(speed) > 0) { + speed = `map(${speed}, 0, 255, 150, 255)`; + } arduino.addInclude( "include_leaphy_original", '#include "Leaphyoriginal1.h"', @@ -75,7 +79,7 @@ function getCodeGenerators(arduino: Arduino) { let direction = block.getFieldValue( "MOTOR_DIRECTION", ) as MotorDirection; - const speed = + let speed = arduino.valueToCode(block, "MOTOR_SPEED", arduino.ORDER_ATOMIC) || "100"; arduino.addInclude( @@ -85,6 +89,10 @@ function getCodeGenerators(arduino: Arduino) { // Set different motor pins for nano robots if (arduino.robotType.includes("nano")) { + // Map the speed to a range of 150 - 255 to compensate for low PWM signal voltage + if (parseInt(speed) > 0) { + speed = `map(${speed}, 0, 255, 150, 255)`; + } const directionMap: Record = { [MotorDirection.FORWARD]: 2, [MotorDirection.BACKWARD]: 1,