Water Drinking Reminder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Code for the Water-Drinking Reminder | |
import time | |
import board | |
import digitalio | |
import pwmio | |
# Button and buzzer pin assignments | |
start_button_pin = board.GP20 | |
stop_button_pin = board.GP22 | |
buzzer_pin = board.GP18 | |
# Configure the button and buzzer pins | |
start_button = digitalio.DigitalInOut(start_button_pin) | |
start_button.switch_to_input(pull=digitalio.Pull.UP) | |
stop_button = digitalio.DigitalInOut(stop_button_pin) | |
stop_button.switch_to_input(pull=digitalio.Pull.UP) | |
buzzer_pwm = pwmio.PWMOut(buzzer_pin, frequency=1500, duty_cycle=0) | |
while True: | |
if not start_button.value: | |
duration = 10 # Set the timer duration (in seconds) // Change time Value (1 hour = 60 minutes = 3600 seconds) | |
end_time = time.monotonic() + duration | |
print("Timer started!") | |
while time.monotonic() < end_time and stop_button.value: | |
remaining_time = end_time - time.monotonic() | |
minutes = int(remaining_time / 60) | |
seconds = int(remaining_time % 60) | |
print(f"Time left: {minutes:02d}:{seconds:02d}", end='\r') | |
time.sleep(1) | |
print("\nTimer ended!") | |
buzzer_pwm.duty_cycle = 0 # Turn off the buzzer | |
buzzer_pwm.duty_cycle = int(65535 / 2) # 50% duty cycle | |
if not stop_button.value: | |
buzzer_pwm.duty_cycle = 0 # Turn off the buzzer | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment