public class PWMComponent extends java.lang.Object implements Component
To generate PWM signal, you can choose to use either:
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_RPI_PWM_CLOCK_FREQUENCY
Default Raspberry Pi PWM clock frequency: 19.2MHz.
|
static int |
PCA9685_PULSE_TICKS
With the PCA9685, a pulse is composed of 4096 ticks (12bits value).
|
protected int |
pinNumber
The WiringPi pin number corresponding to the PWMPin pin.
|
Constructor and Description |
---|
PWMComponent(PCA9685 pca9685,
PCA9685.PCA9685Channel channel,
int rangeGenerator)
Constructor for a PWM component, using a PCA9685 module to generate PWM signals.
|
PWMComponent(PWMPin pin,
int rangeGenerator)
Constructor for a PWM component, using a RPi hardware PWM pin to generate PWM signals.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getType()
Get the String representation of the type of the component.
|
void |
setPWM(int off)
Sets for each full pulse of the PWM signal, the tick where the signal turns off (low).
|
void |
setPWM(int off,
long millis)
Uses the
setPWM(int) method to set the PWM signal with the off parameter,
for a duration of millis milliseconds, and then stops the signal. |
void |
setPWMFreq(double frequency)
Sets the PWM frequency, which determines how many full pulses per second are generated.
|
public static final int DEFAULT_RPI_PWM_CLOCK_FREQUENCY
protected int pinNumber
This is used for performance reasons with components requiring microseconds delays.
pin
public static final int PCA9685_PULSE_TICKS
public PWMComponent(PCA9685 pca9685, PCA9685.PCA9685Channel channel, int rangeGenerator)
Advantage: 16 channels on each PCA9685.
Disadvantage: target frequency must be an integer values, only between 40 and 1000Hz.
pca9685
- the pca9685 module used to generate PWM signals.channel
- the target channel on the pca9685 to generate the PWM signals.rangeGenerator
- the value used to define the range of values that can be used
to define a signal. The tick when the signal turn off for each pulse must then be between 0 and rangeGenerator.
! Attention ! when using the PCA9685, the maximum rangeGenerator is 4096 (maximum 12-bits value). Must be >= 1.public PWMComponent(PWMPin pin, int rangeGenerator)
Advantage: wide range of PWM frequencies, with continuous values.
Disadvantage: only 2 hardware PWM pins on recent RPi.
pin
- the PWMPin used to generate PWM signal.rangeGenerator
- the value used to define the range of values that can be used
to define a signal. The tick when the signal turn off for each pulse must then be between 0 and rangeGenerator.
Must be >= 1.PWMPin
public void setPWMFreq(double frequency)
Depending on the selected mode (Raspberry Pi PWM pin or PCA9685), the maximum available frequency is different.
frequency
- the new PWM frequency.public void setPWM(int off)
The rangeGenerator is used to define the range of values that the off tick can take. As an example, a rangeGenerator of 20000 and an off value of 5000 means that each PWM full pulse is composed of 25% high signal, followed by 75% of low signal.
! Attention ! when using the PCA9685, the maximum rangeGenerator is 4096 (maximum 12-bits value).
If you use a higher value for the off than for the rangeGenerator, we will set the off value to the rangeGenerator value.
Note that an off value of zero will stop the PWM signal.
off
- the tick where the signal turns off (low). 0 to stop the PWM signal.setPWM(int, long)
public void setPWM(int off, long millis)
setPWM(int)
method to set the PWM signal with the off parameter,
for a duration of millis milliseconds, and then stops the signal.off
- the tick where the signal turns off (low).millis
- the duration of the PWM signal, in milliseconds.setPWM(int)