@@ -27,7 +27,6 @@ def __init__(self, vin_pin:int, button_pin:int):
27
27
self .on_switch = ADC (Pin (vin_pin ))
28
28
29
29
self .button = Pin (button_pin , Pin .IN , Pin .PULL_UP )
30
- self .button_callback = None
31
30
32
31
self .led = Pin ("LED" , Pin .OUT )
33
32
# A timer ID of -1 is a virtual timer.
@@ -43,20 +42,6 @@ def are_motors_powered(self) -> bool:
43
42
"""
44
43
return self .on_switch .read_u16 () > 20000
45
44
46
- def set_button_callback (self , trigger , callback ):
47
- """
48
- Sets an interrupt callback to be triggered on a change in button state, specified by trigger.
49
- Follow the link for more information on how to write an Interrupt Service Routine (ISR).
50
- https://docs.micropython.org/en/latest/reference/isr_rules.html
51
-
52
- :param trigger: The type of trigger to be used for the interrupt
53
- :type trigger: Pin.IRQ_RISING | Pin.IRQ_FALLING
54
- :param callback: The function to be called when the interrupt is triggered
55
- :type callback: function | None
56
- """
57
- self .button_callback = callback
58
- self .button .irq (trigger = trigger , handler = self .button_callback )
59
-
60
45
def is_button_pressed (self ) -> bool :
61
46
"""
62
47
Returns the state of the button
@@ -98,9 +83,9 @@ def led_off(self):
98
83
self .led .off ()
99
84
self ._virt_timer .deinit ()
100
85
101
- def led_blink (self , frequency : int ):
86
+ def led_blink (self , frequency : int = 0 ):
102
87
"""
103
- Blinks the LED at a given frequency
88
+ Blinks the LED at a given frequency. If the frequency is 0, the LED will stop blinking.
104
89
105
90
:param frequency: The frequency to blink the LED at (in Hz)
106
91
:type frequency: int
@@ -110,6 +95,10 @@ def led_blink(self, frequency: int):
110
95
self ._virt_timer .deinit ()
111
96
# We set it to twice in input frequency so that
112
97
# the led flashes on and off frequency times per second
113
- self ._virt_timer .init (freq = frequency * 2 , mode = Timer .PERIODIC ,
114
- callback = lambda t :self .led .toggle ())
115
- self .is_led_blinking = True
98
+ if frequency != 0 :
99
+ self ._virt_timer .init (freq = frequency * 2 , mode = Timer .PERIODIC ,
100
+ callback = lambda t :self .led .toggle ())
101
+ self .is_led_blinking = True
102
+ else :
103
+ self ._virt_timer .deinit ()
104
+ self .is_led_blinking = False
0 commit comments