Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class PwmChannel
- Object
- 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
Methods
public int getChip() | The PWM controller number. |
public int getChannel() | The channel within the controller. |
public void configure(long periodNanos, long dutyNanos, boolean enabled)
throws HardwareException | Sets the period, the high time and whether the output runs. |
public void setDutyCycle(double fraction)
throws HardwareException | Sets the duty cycle as a fraction of the current period, keeping the period and enabled state. |
public long getPeriodNanos() | The configured period in nanoseconds, 0 before configure(long, long, boolean). |
public long getDutyNanos() | The configured high time in nanoseconds. |
public boolean isEnabled() | true while the output runs. |
public void close() | Disables the output and releases the channel. |
Inherited methods
Method details
getChip
public int getChip()The PWM controller number.
getChannel
public int getChannel()The channel within the controller.
configure
public void configure(long periodNanos, long dutyNanos, boolean enabled)
throws HardwareExceptionSets 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
setDutyCycle
public void setDutyCycle(double fraction)
throws HardwareExceptionSets the duty cycle as a fraction of the current period, keeping the
period and enabled state.
Throws
HardwareException- when no period was configured yet
getPeriodNanos
public long getPeriodNanos()The configured period in nanoseconds,
0 before configure(long, long, boolean).getDutyNanos
public long getDutyNanos()The configured high time in nanoseconds.
isEnabled
public boolean isEnabled()true while the output runs.close
public void close()Disables the output and releases the channel. Closing twice is harmless.