new LED(pin, active_highopt, initial_valueopt)
- Source:
Represents a light emitting diode (LED).
Connect the cathode (short leg, flat side) of the LED to a ground pin; connect the anode (longer leg) to a limiting resistor; connect the other side of the limiting resistor to a GPIO pin (the limiting resistor can be placed either side of the LED).
Example
const LED = require('gpiozero').LED;
var led = new LED(17);
led.on();
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pin |
int | Pin | The GPIO pin (in BCM numbering) or an instance of Pin that the LED is connected to. | |
active_high |
boolean |
<optional> |
If ``True`` (the default), the LED will operate normally with the circuit described above. If ``False`` you should wire the cathode to the GPIO pin, and the anode to a 3V3 pin (via a limiting resistor). |
initial_value |
boolean |
<optional> |
If `false` (the default), the device will be off initially. If `undefined`, the device will be left in whatever state the pin is found in when configured for output (warning: this can be on). If `true`, the device will be switched on initially. |
Extends
Methods
active_high(valueopt)
- Source:
- Inherited From:
This property can be set after construction; be warned that changing it
will invert value (i.e. changing this property doesn't change
the device's pin state - it just changes how that state is interpreted).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
boolean |
<optional> |
When ``true``, the value property is ``true`` when the device's pin is high. When ``false`` the value property is ``true`` when the device's pin is low (i.e. the value is inverted). |
blink(on_time, off_time, n, {@callback})
- Source:
- Inherited From:
Make the device turn on and off repeatedly.
Parameters:
Name | Type | Description |
---|---|---|
on_time |
float | Number of seconds on. Defaults to 1 second. |
off_time |
float | Number of seconds off. Defaults to 1 second. |
n |
int | Number of times to blink; ``None`` (the default) means forever. |
{@callback} |
callback - Function to be called upon completion in the form (error, data). |
close()
- Source:
- Inherited From:
Close the device and remove the pin allocation allowing it to be reused.
closed() → {boolean}
- Source:
- Inherited From:
Returns:
- Is ``true`` is no pin is allocated.
- Type
- boolean
is_active() → {boolean}
- Source:
- Inherited From:
Returns:
- Is true is the device value is currently set.
- Type
- boolean
is_lit() → {boolean}
- Source:
Friendly name for is_active.
Returns:
- Is true is LED is lit.
- Type
- boolean
off()
- Source:
- Inherited From:
Turns the device off.
on()
- Source:
- Inherited From:
Turns the device on.
pin() → {undefined|*|int|Pin}
- Source:
- Inherited From:
Returns:
- The Pin that the device is connected to. This will be ``undefined``
if the device has been closed (see the :meth:`close` method). When dealing with GPIO pins, query ``pin.number``
to discover the GPIO pin (in BCM numbering) that the device is connected to.
- Type
- undefined | * | int | Pin
toggle()
- Source:
- Inherited From:
Reverse the state of the device. If it's on, turn it off; if it's off, turn it on.
toString() → {string}
- Source:
- Inherited From:
Returns:
- Description of the device.
- Type
- string
value(valueopt) → {boolean|float}
- Source:
- Inherited From:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
boolean | float |
<optional> |
When supplied the device output is changed to the value. |
Returns:
- When value is undefined, the function returns the current value of the device.
- Type
- boolean | float