-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel_button_leds.py
39 lines (29 loc) · 1011 Bytes
/
panel_button_leds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Control the LEDs on the panel buttons."""
import gpiozero
import pi_header_pinout
BUTTON_PINS = pi_header_pinout.BUTTON_GPIO_PINS
LED_PINS = pi_header_pinout.BUTTON_LED_GPIO_PINS
class PanelButtonLEDsController:
"""Controls the panel button LEDs."""
def __init__(self):
# Maps button pins to corresponding LED pins.
self.leds = [
gpiozero.LED(LED_PINS[0], active_high=False), # RGB LED.
gpiozero.LED(LED_PINS[1]),
gpiozero.LED(LED_PINS[2]),
gpiozero.LED(LED_PINS[3])
]
def turn_on_led(self, led_index: int):
"""Turn on a LED."""
self.leds[led_index].on()
def turn_off_led(self, led_index: int):
"""Turn off a LED."""
self.leds[led_index].off()
def turn_off_all_leds(self):
"""Turn off all LEDS."""
for led in self.leds:
led.off()
def turn_on_all_leds(self):
"""Turn on all LEDS."""
for led in self.leds:
led.on()