Class PwmChannel
java.lang.Object
com.codename1.hardware.PwmChannel
A hardware PWM channel, opened through Hardware.openPwm(int, int).
PwmChannel servo = Hardware.getInstance().openPwm(0, 0);
servo.configure(20000000L, 1500000L, true); // 50 Hz, 1.5 ms pulse: centred
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disables the output and releases the channel.voidconfigure(long periodNanos, long dutyNanos, boolean enabled) Sets the period, the high time and whether the output runs.intThe channel within the controller.intgetChip()The PWM controller number.longThe configured high time in nanoseconds.longThe configured period in nanoseconds,0beforeconfigure(long, long, boolean).booleantruewhile the output runs.voidsetDutyCycle(double fraction) Sets the duty cycle as a fraction of the current period, keeping the period and enabled state.
-
Method Details
-
getChip
public int getChip()The PWM controller number. -
getChannel
public int getChannel()The channel within the controller. -
configure
Sets the period, the high time and whether the output runs.
Throws
HardwareException: when the duty exceeds the period, the controller rejects the values, or the channel is closed
- Throws:
HardwareException
-
setDutyCycle
Sets the duty cycle as a fraction of the current period, keeping the period and enabled state.
Throws
HardwareException: when no period was configured yet
- Throws:
HardwareException
-
getPeriodNanos
public long getPeriodNanos()The configured period in nanoseconds,0beforeconfigure(long, long, boolean). -
getDutyNanos
public long getDutyNanos()The configured high time in nanoseconds. -
isEnabled
public boolean isEnabled()truewhile the output runs. -
close
public void close()Disables the output and releases the channel. Closing twice is harmless.
-