Class Pwm
The four register bytes for one PCA9685 channel.
public static class Pwm
- Inheritance
-
Pwm
- Inherited Members
Remarks
Each call returns them in the channel's own register order, so they can be written in a single bus transaction.
Methods
Counts(ReadOnlySpan<byte>)
Reads a setting back from the four register bytes a channel holds.
public static (ushort On, ushort Off) Counts(ReadOnlySpan<byte> bytes)
Parameters
bytesReadOnlySpan<byte>The four channel registers.
Returns
Remarks
The inverse of the builders above, so a caller can read a channel off the bus and see what it is set to rather than decoding the registers by hand.
Exceptions
- PamojaException
The registers are not four bytes.
Duty(ushort)
Builds a setting with no phase delay: on at count 0, off at off.
public static byte[] Duty(ushort off)
Parameters
offushortThe count at which the output goes low, which sets the duty.
Returns
- byte[]
The four register bytes.
FromCounts(ushort, ushort)
Builds a setting from explicit on and off counts.
public static byte[] FromCounts(ushort on, ushort off)
Parameters
Returns
- byte[]
The four register bytes; counts are masked to 12 bits.
FullOff()
The setting that holds a channel continuously low, the power-on state.
public static byte[] FullOff()
Returns
- byte[]
The four register bytes. This is not the same as a zero duty, which still glitches high for one count.
FullOn()
The setting that holds a channel continuously high.
public static byte[] FullOn()
Returns
- byte[]
The four register bytes.
Servo(uint, uint)
Builds the setting that drives a hobby servo to a pulse width.
public static byte[] Servo(uint pulseMicros, uint updateRateHz = 50)
Parameters
pulseMicrosuintThe high-pulse width in microseconds. Typical travel is about 1000 to 2000.
updateRateHzuintThe PWM frequency the controller is set to.
Returns
- byte[]
The four register bytes.