Class PwmChannel

java.lang.Object
com.codename1.hardware.PwmChannel

public final class PwmChannel extends Object

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 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 HardwareException

      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

      public void setDutyCycle(double fraction) throws HardwareException

      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, 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.