mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Add more ledboard examples
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
from gpiozero import LEDBoard
|
from gpiozero import LEDBoard
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
leds = LEDBoard(5, 6, 13, 19, 26, pwm=True)
|
leds = LEDBoard(5, 6, 13, 19, 26)
|
||||||
|
|
||||||
leds.value = (0.2, 0.4, 0.6, 0.8, 1.0)
|
for led in leds:
|
||||||
|
led.on()
|
||||||
|
sleep(1)
|
||||||
|
led.off()
|
||||||
|
|||||||
8
docs/examples/led_board_3.py
Normal file
8
docs/examples/led_board_3.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from gpiozero import LEDBoard
|
||||||
|
from signal import pause
|
||||||
|
|
||||||
|
leds = LEDBoard(5, 6, 13, 19, 26, pwm=True)
|
||||||
|
|
||||||
|
leds.value = (0.2, 0.4, 0.6, 0.8, 1.0)
|
||||||
|
|
||||||
|
pause()
|
||||||
11
docs/examples/led_board_4.py
Normal file
11
docs/examples/led_board_4.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from gpiozero import LEDBoard
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
leds = LEDBoard(2, 3, 4, 5, 6, 7, 8, 9)
|
||||||
|
|
||||||
|
leds[0].on() # first led on
|
||||||
|
sleep(1)
|
||||||
|
leds[7].on() # last led on
|
||||||
|
sleep(1)
|
||||||
|
leds[-1].off() # last led off
|
||||||
|
sleep(1)
|
||||||
24
docs/examples/led_board_5.py
Normal file
24
docs/examples/led_board_5.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from gpiozero import LEDBoard
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
leds = LEDBoard(2, 3, 4, 5, 6, 7, 8, 9)
|
||||||
|
|
||||||
|
for led in leds[3:]: # leds 3 and onward
|
||||||
|
led.on()
|
||||||
|
sleep(1)
|
||||||
|
leds.off()
|
||||||
|
|
||||||
|
for led in leds[:2]: # leds 0 and 1
|
||||||
|
led.on()
|
||||||
|
sleep(1)
|
||||||
|
leds.off()
|
||||||
|
|
||||||
|
for led in leds[::2]: # even leds (0, 2, 4...)
|
||||||
|
led.on()
|
||||||
|
sleep(1)
|
||||||
|
leds.off()
|
||||||
|
|
||||||
|
for led in leds[1::2]: # odd leds (1, 3, 5...)
|
||||||
|
led.on()
|
||||||
|
sleep(1)
|
||||||
|
leds.off()
|
||||||
11
docs/examples/led_board_6.py
Normal file
11
docs/examples/led_board_6.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from gpiozero import LEDBoard
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
leds = LEDBoard(red=2, green=3, blue=4)
|
||||||
|
|
||||||
|
leds.red.on()
|
||||||
|
sleep(1)
|
||||||
|
leds.green.on()
|
||||||
|
sleep(1)
|
||||||
|
leds.blue.on()
|
||||||
|
sleep(1)
|
||||||
15
docs/examples/led_board_7.py
Normal file
15
docs/examples/led_board_7.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from gpiozero import LEDBoard
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
leds = LEDBoard(red=LEDBoard(top=2, bottom=3), green=LEDBoard(top=4, bottom=5))
|
||||||
|
|
||||||
|
leds.red.on() ## both reds on
|
||||||
|
sleep(1)
|
||||||
|
leds.green.on() # both greens on
|
||||||
|
sleep(1)
|
||||||
|
leds.off() # all off
|
||||||
|
sleep(1)
|
||||||
|
leds.red.top.on() # top red on
|
||||||
|
sleep(1)
|
||||||
|
leds.green.bottom.on() # bottom green on
|
||||||
|
sleep(1)
|
||||||
@@ -162,10 +162,34 @@ A collection of LEDs can be accessed using :class:`LEDBoard`:
|
|||||||
|
|
||||||
.. literalinclude:: examples/led_board_1.py
|
.. literalinclude:: examples/led_board_1.py
|
||||||
|
|
||||||
|
You can also iterate over the LEDs one-by-one:
|
||||||
|
|
||||||
|
.. literalinclude:: examples/led_board_2.py
|
||||||
|
|
||||||
Using :class:`LEDBoard` with ``pwm=True`` allows each LED's brightness to be
|
Using :class:`LEDBoard` with ``pwm=True`` allows each LED's brightness to be
|
||||||
controlled:
|
controlled:
|
||||||
|
|
||||||
.. literalinclude:: examples/led_board_2.py
|
.. literalinclude:: examples/led_board_3.py
|
||||||
|
|
||||||
|
:class:`LEDBoard` also supports indexing. This means you can access the
|
||||||
|
individual :class:`LED` objects using ``leds[i]`` where ``i`` is an integer
|
||||||
|
from 0 up to (not including) the number of LEDs:
|
||||||
|
|
||||||
|
.. literalinclude:: examples/led_board_4.py
|
||||||
|
|
||||||
|
This also means you can use slicing to access a subset of the LEDs:
|
||||||
|
|
||||||
|
.. literalinclude:: examples/led_board_5.py
|
||||||
|
|
||||||
|
:class:`LEDBoard` objects can have their `LED` objects named upon construction.
|
||||||
|
This means the individual LEDs can be accessed by their name:
|
||||||
|
|
||||||
|
.. literalinclude:: examples/led_board_6.py
|
||||||
|
|
||||||
|
:class:`LEDBoard` objects can also be nested to contain other :class:`LEDBoard`
|
||||||
|
objects.
|
||||||
|
|
||||||
|
.. literalinclude:: examples/led_board_7.py
|
||||||
|
|
||||||
LEDBarGraph
|
LEDBarGraph
|
||||||
===========
|
===========
|
||||||
|
|||||||
Reference in New Issue
Block a user