@@ -27,7 +27,6 @@ def __init__(self, vin_pin:int, button_pin:int):
2727 self .on_switch = ADC (Pin (vin_pin ))
2828
2929 self .button = Pin (button_pin , Pin .IN , Pin .PULL_UP )
30- self .button_callback = None
3130
3231 self .led = Pin ("LED" , Pin .OUT )
3332 # A timer ID of -1 is a virtual timer.
@@ -43,20 +42,6 @@ def are_motors_powered(self) -> bool:
4342 """
4443 return self .on_switch .read_u16 () > 20000
4544
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-
6045 def is_button_pressed (self ) -> bool :
6146 """
6247 Returns the state of the button
@@ -98,9 +83,9 @@ def led_off(self):
9883 self .led .off ()
9984 self ._virt_timer .deinit ()
10085
101- def led_blink (self , frequency : int ):
86+ def led_blink (self , frequency : int = 0 ):
10287 """
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.
10489
10590 :param frequency: The frequency to blink the LED at (in Hz)
10691 :type frequency: int
@@ -110,6 +95,10 @@ def led_blink(self, frequency: int):
11095 self ._virt_timer .deinit ()
11196 # We set it to twice in input frequency so that
11297 # 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