added button top 3d model and buzzer to code

This commit is contained in:
Angoosh Leviocki 2024-02-28 19:37:58 +01:00
parent 91739586d0
commit 7c871a3b5c
Signed by: angoosh
GPG Key ID: 2DAE446D291BD8D3
4 changed files with 19 additions and 4 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
{"hostname":"spock","username":"angoosh"} {"hostname":"Oneill","username":"angoosh"}

View File

@ -11,7 +11,8 @@ BRIGHTNESS = 0.2 # Adjust the brightness (0.0 - 1.0)
led_strip = neopixel.NeoPixel(Pin(ws_pin), led_num) led_strip = neopixel.NeoPixel(Pin(ws_pin), led_num)
push_button = Pin(24,Pin.IN,Pin.PULL_UP) push_button = Pin(24, Pin.IN, Pin.PULL_UP)
buzzer = Pin(3, Pin.OUT)
pushbutton_pressed = 0 pushbutton_pressed = 0
blink_interrupted = 0 blink_interrupted = 0
@ -80,19 +81,24 @@ def blink_and_beep(times):
blink_delay = 0.2 blink_delay = 0.2
#insert beep #insert beep
buzzer.value(1)
for i in range(0, times): for i in range(0, times):
set_neopixel_color(255, 0, 0) set_neopixel_color(255, 0, 0)
buzzer.value(0)
time.sleep(blink_delay) time.sleep(blink_delay)
set_neopixel_color(0, 0, 0) set_neopixel_color(0, 0, 0)
buzzer.value(1)
time.sleep(blink_delay) time.sleep(blink_delay)
if pushbutton_pressed == 1: if pushbutton_pressed == 1:
pushbutton_pressed = 0 pushbutton_pressed = 0
blink_interrupted = 1 blink_interrupted = 1
i = times i = times
buzzer.value(0)
return return
buzzer.value(0)
ten_min_timer = 0 ten_min_timer = 0
ten_min_timer_led_index = 0 ten_min_timer_led_index = 11
def count_10_min(): def count_10_min():
global ten_min_timer, ten_min_timer_led_index, pushbutton_pressed, blink_interrupted global ten_min_timer, ten_min_timer_led_index, pushbutton_pressed, blink_interrupted
@ -135,6 +141,15 @@ def button_callback(push_button):
set_neopixel_color(0,0,0) set_neopixel_color(0,0,0)
push_button.irq(trigger=Pin.IRQ_FALLING, handler=button_callback) push_button.irq(trigger=Pin.IRQ_FALLING, handler=button_callback)
green = (0, 255, 0)
green = set_neopixel_brightness(green)
led_strip[0] = green
led_strip[2] = green
led_strip[4] = green
led_strip[6] = green
led_strip[8] = green
led_strip.write()
while True: while True:
count_10_min() count_10_min()
time.sleep(1) time.sleep(0.01)