2
2
from time import ticks_ms
3
3
from micropython import const
4
4
5
+ class ModulinoButtonsLED ():
6
+ def __init__ (self , buttons ):
7
+ self ._value = 0
8
+ self ._buttons = buttons
9
+
10
+ def on (self ):
11
+ self .value = 1
12
+
13
+ def off (self ):
14
+ self .value = 0
15
+
16
+ @property
17
+ def value (self ):
18
+ return self ._value
19
+
20
+ @value .setter
21
+ def value (self , value ):
22
+ self ._value = value
23
+ self ._buttons ._update_leds ()
24
+
5
25
class ModulinoButtons (Modulino ):
6
26
"""
7
27
Class to interact with the buttons of the Modulino Buttons.
@@ -35,7 +55,37 @@ def __init__(self, i2c_bus = None, address = None):
35
55
self ._on_button_a_long_press = None
36
56
self ._on_button_b_long_press = None
37
57
self ._on_button_c_long_press = None
58
+
59
+ # LEDs
60
+ self ._led_a = ModulinoButtonsLED (self )
61
+ self ._led_b = ModulinoButtonsLED (self )
62
+ self ._led_c = ModulinoButtonsLED (self )
63
+
64
+ @property
65
+ def led_a (self ) -> ModulinoButtonsLED :
66
+ """ Returns the LED A object of the module. """
67
+ return self ._led_a
68
+
69
+ @property
70
+ def led_b (self ) -> ModulinoButtonsLED :
71
+ """ Returns the LED B object of the module. """
72
+ return self ._led_b
38
73
74
+ @property
75
+ def led_c (self ) -> ModulinoButtonsLED :
76
+ """ Returns the LED C object of the module. """
77
+ return self ._led_c
78
+
79
+ def _update_leds (self ):
80
+ """
81
+ Update the physical status of the button LEDs by writing the current values to the module.
82
+ """
83
+ data = bytearray (3 )
84
+ data [0 ] = self ._led_a .value
85
+ data [1 ] = self ._led_b .value
86
+ data [2 ] = self ._led_c .value
87
+ self .write (data )
88
+
39
89
def set_led_status (self , a : bool , b : bool , c : bool ) -> None :
40
90
"""
41
91
Turn on or off the button LEDs according to the given status.
@@ -45,11 +95,10 @@ def set_led_status(self, a: bool, b: bool, c: bool) -> None:
45
95
b (bool): The status of the LED B.
46
96
c (bool): The status of the LED C.
47
97
"""
48
- data = bytearray (3 )
49
- data [0 ] = 1 if a else 0
50
- data [1 ] = 1 if b else 0
51
- data [2 ] = 1 if c else 0
52
- self .write (data )
98
+ self ._led_a ._value = 1 if a else 0
99
+ self ._led_b ._value = 1 if b else 0
100
+ self ._led_c ._value = 1 if c else 0
101
+ self ._update_leds ()
53
102
54
103
@property
55
104
def long_press_duration (self ) -> int :
0 commit comments