PWMOutputDevice

PWMOutputDevice

new PWMOutputDevice(pin, active_high, initial_value, frequency)

Source:
Generic output device configured for pulse-width modulation (PWM).
Parameters:
Name Type Description
pin int | Pin The GPIO pin which the device is attached to.
active_high boolean If ``true`` (the default), the on method will set the GPIO to HIGH. If ``false``, the on method will set the GPIO to LOW (the off method always does the opposite).
initial_value int If ``0`` (the default), the device's duty cycle will be 0 initially. Other values between 0 and 1 can be specified as an initial duty cycle. Note that ``undefined`` cannot be specified (unlike the parent class) as there is no way to tell PWM not to alter the state of the pin.
frequency int The frequency (in Hz) of pulses emitted to drive the device. Defaults to 100Hz.
Throws:
OutputDeviceBadValue - When intial_value is ``undefined``.

Methods

Source:
Make the device turn on and off repeatedly.
Parameters:
Name Type Attributes Description
on_time float <optional>
Number of seconds on. Defaults to 1 second.
off_time float <optional>
Number of seconds off. Defaults to 1 second.
fade_in_time float <optional>
Number of seconds to spend fading in. Defaults to 0.
fade_out_time float <optional>
Number of seconds to spend fading out. Defaults to 0.
n int <optional>
Number of times to blink; ``undefined`` (the default) means forever.
{@callback} [callback] - Function to be called after n loops.

close()

Source:
Stop any actions such as blink and unlink from pin.

frequency(valueopt) → {int}

Source:
Sets or Gets the device frequency.
Parameters:
Name Type Attributes Description
value int <optional>
The new frequency for the device.
Returns:
- If value is undefined then the current device frequency is returned.
Type
int

is_active() → {boolean}

Source:
Returns:
- If the device has a value other than 0 then true.
Type
boolean

off()

Source:
Turn the device off.

on()

Source:
Turn the device fully on.

pulse(fade_in_timeopt, fade_out_timeopt, nopt, {@callback})

Source:
Make the device fade in and out repeatedly.
Parameters:
Name Type Attributes Description
fade_in_time float <optional>
Number of seconds to spend fading in. Defaults to 0.
fade_out_time float <optional>
Number of seconds to spend fading out. Defaults to 0.
n int <optional>
Number of times to blink; ``undefined`` (the default) means forever.
{@callback} [callback] - Function to be called after n loops.

toggle()

Source:
Toggle the state of the device. If the device is currently off (value` is 0.0), this changes it to "fully" on (`value` is 1.0). If the device has a duty cycle (`value`) of 0.1, this will toggle it to 0.9, and so on.

value(valueopt) → {float}

Source:
The duty cycle of the PWM device. 0.0 is off, 1.0 is fully on. Values in between may be specified for varying levels of power in the device.
Parameters:
Name Type Attributes Description
value float <optional>
When defined then sets the device duty cycle.
Returns:
- When value is undefined then the current duty cycle is returned.
Type
float