http://gpiozero.readthedocs.io/en/stable/api_output.html#led
12.1. LED
- class
gpiozero.
LED
(pin, *, active_high=True, initial_value=False, pin_factory=None)[source] - Extends
DigitalOutputDevice
and 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).
The following example will light the LED:
Python1234from gpiozero import LEDled = LED(17)led.on()Parameters: - pin (int) – The GPIO pin which the LED is attached to. See Pin Numbering for valid pin numbers.
- active_high (bool) – If
True
(the default), the LED will operate normally with the circuit described above. IfFalse
you should wire the cathode to the GPIO pin, and the anode to a 3V3 pin (via a limiting resistor). - initial_value (bool) – If
False
(the default), the LED will be off initially. IfNone
, the LED will be left in whatever state the pin is found in when configured for output (warning: this can be on). IfTrue
, the LED will be switched on initially. - pin_factory (Factory) – See API – Pins for more information (this is an advanced feature which most users can ignore).
blink
(on_time=1, off_time=1, n=None, background=True)- Make the device turn on and off repeatedly.
Parameters: - 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. - background (bool) – If
True
(the default), start a background thread to continue blinking and return immediately. IfFalse
, only return when the blink is finished (warning: the default value of n will result in this method never returning).
off
()- Turns the device off.
on
()- Turns the device on.
toggle
()- Reverse the state of the device. If it’s on, turn it off; if it’s off, turn it on.
is_lit
- Returns
True
if the device is currently active andFalse
otherwise. This property is usually derived fromvalue
. Unlikevalue
, this is always a boolean.
pin
- The
Pin
that the device is connected to. This will beNone
if the device has been closed (see theclose()
method). When dealing with GPIO pins, querypin.number
to discover the GPIO pin (in BCM numbering) that the device is connected to.
转载请注明:徐自远的乱七八糟小站 » 20170901 【资料1】API-LED