20170901 【资料1】API-LED

树莓派Python课程 徐 自远 665℃

http://gpiozero.readthedocs.io/en/stable/api_output.html#led

12.1. LED

classgpiozero.LED(pin*active_high=Trueinitial_value=Falsepin_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:

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. If False 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. If None, the LED will be left in whatever state the pin is found in when configured for output (warning: this can be on). If True, 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).
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. If False, 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 and False otherwise. This property is usually derived from value. Unlike value, this is always a boolean.
pin
The Pin that the device is connected to. This will be None if the device has been closed (see the close() method). When dealing with GPIO pins, query pin.number to discover the GPIO pin (in BCM numbering) that the device is connected to.

转载请注明:徐自远的乱七八糟小站 » 20170901 【资料1】API-LED

喜欢 (7)

苏ICP备18041234号-1 bei_an 苏公网安备 32021402001397号