from machine import Pin
from time import ticks_ms, ticks_diff, sleep
import tm1637
# LED setup
green_led = Pin(5, Pin.OUT)
# Button on GPIO 12 and 32, with internal pull-up resistor
# So basically, Pin.PULL_UP means the GPIO pin is set to HIGH (3.3V) by default.
# When the button is pressed, it connects the pin directly to GND (0V),
# so the pin reads a value of 0 — the current is pulled down to ground.
start_button = Pin(12, Pin.IN, Pin.PULL_UP)
end_button = Pin(33, Pin.IN, Pin.PULL_UP)
buzzer = Pin(23, Pin.OUT)
# Display setup
tm = tm1637.TM1637(clk=Pin(26), dio=Pin(27))
# Variables
counting = False
counter = 0
last_update = ticks_ms()
total_price = 150
while True:
if start_button.value() == 0:
counting = True
green_led.on()
if counting and ticks_diff(ticks_ms(), last_update) >= 1000:
minutes = counter // 60
seconds = counter % 60
display_val = minutes * 100 + seconds
tm.show_number(display_val)
counter += 1
last_update = ticks_ms()
if counter % 10 == 0:
total_price += 25
if end_button.value() == 0:
counting = False
green_led.off()
counter = 0
buzzer.on()
print("\n\nEEEEEEENK")
tm.show([0x00, 0x00, 0x00, 0x00])
sleep(5)
buzzer.off()
print("Session is Done!\n")
print(f"Please Pay: {total_price}")