diff --git a/java/libraries/io/src/processing/io/PWM.java b/java/libraries/io/src/processing/io/PWM.java index 7c2406dcf..6ea050a11 100644 --- a/java/libraries/io/src/processing/io/PWM.java +++ b/java/libraries/io/src/processing/io/PWM.java @@ -157,17 +157,19 @@ public class PWM { public void set(int period, float duty) { // set period String fn = fn = String.format("/sys/class/pwm/%s/pwm%d/period", chip, channel); + // convert to nanoseconds int ret = NativeInterface.writeFile(fn, String.format("%d", (int)(1000000000 / period))); if (ret < 0) { throw new RuntimeException(fn + ": " + NativeInterface.getError(ret)); } // set duty cycle - fn = fn = String.format("/sys/class/pwm/%s/pwm%d/duty", chip, channel); + fn = fn = String.format("/sys/class/pwm/%s/pwm%d/duty_cycle", chip, channel); if (duty < 0.0 || 1.0 < duty) { System.err.println("Duty cycle must be between 0.0 and 1.0."); throw new IllegalArgumentException("Illegal argument"); } + // convert to nanoseconds ret = NativeInterface.writeFile(fn, String.format("%d", (int)((1000000000 * duty) / period))); if (ret < 0) { throw new RuntimeException(fn + ": " + NativeInterface.getError(ret));