-
Notifications
You must be signed in to change notification settings - Fork 1
PWM & LED
>>> import navio
>>> nio = navio.Navio()
>>> # Set LED RGB value
>>> nio.PWM_set_led(255, 0, 0) # red
>>> nio.PWM_set_led(0, 255, 0) # green
>>> nio.PWM_set_led(0, 0, 255) # blue
>>> nio.PWM_set_led(125, 125, 125) # approx half-intensity white
>>> nio.PWM_set_led() # off
>>> # Set PWM output
>>> # Available channels is 1 - 13
>>> # Available values are 0 - 4095
>>> nio.PWM_set(4, 2048) # set channel 4 to a value of 2048
instance method PWM_get_frequency()
Get the current PWM operating frequency.
Returns: (float) The current PWM frequency.
instance method PWM_set_frequency(frequency)
Set the PWM operating frequency. As the output frequency is created by applying a divider on the internal 25MHz clock, the exact frequency might differ from what you set here. The actual set frequency is the returned value.
Returns: (float) The actual frequency set.
Parameters:
- frequency: (float) PWM frequency in Hz. Valid frequency range is 24.0 to 1526.0 Hz.
raises ValueError if you try to set an out-of-range frequency.
instance method PWM_set_led(R = 0, G = 0, B = 0)
Set the RGB values (0-255) of the on-board LED.
Returns: None
Parameters:
- R: (int) The value to be set for the red LED.
- G: (int) The value to be set for the green LED.
- B: (int) The value to be set for the blue LED.
raises OverflowError if values are not within the range 0-255.
instance method PWM_set_pulse(channel, length = 0, offset = 0)
Set the PWM pulse length (0-4095) of the specified channel (1-13).
Returns: None
Parameters:
- channel: (int) The PWM channel to set the pulse for.
- length: (int) The length of the PWM pulse to set.
- offset: (int) The offset to start the pulse at.
raises ValueError if channel < 1 or channel > 13 (will raise OverflowError if channel > 254 or negative).
raises ValueError if length < 0 or length > 4095.
instance method PWM_set_pulse_ms(channel, ms)
Set the PWM pulse length in milliseconds for the specified channel.
Returns: None
Parameters:
- channel: (int) The PWM channel to set the pulse for.
- ms: (int) The length of the PWM pulse in ms.
raises ValueError if channel < 1 or channel > 13 (will raise OverflowError if channel > 254 or negative).
instance method PWM_set_pulse_us(channel, us)
Set the PWM pulse length in microseconds for the specified channel.
Returns: None
Parameters:
- channel: (int) The PWM channel to set the pulse for.
- us: (int) The length of the PWM pulse in us.
raises ValueError if channel < 1 or channel > 13 (will raise OverflowError if channel > 254 or negative).