# Pico Health Band - Super Beginner Version
# Reminds you to drink water
# Bonus: LED bar shows glasses drunk, melody when goal is reached
from machine import Pin, PWM
from time import sleep
# --- Components ---
buzzer = PWM(Pin(10)) # Buzzer on GP10
button_stop = Pin(8, Pin.IN, Pin.PULL_DOWN) # Stop buzzer
button_add = Pin(9, Pin.IN, Pin.PULL_DOWN) # Add glass
# LCD connections (RS, E, D4, D5, D6, D7)
lcd_rs = 11
lcd_e = 12
lcd_d4 = 13
lcd_d5 = 14
lcd_d6 = 15
lcd_d7 = 16
lcd.init(lcd_rs, lcd_e, lcd_d4, lcd_d5, lcd_d6, lcd_d7)
lcd.clear()
# LED Bar (8 LEDs)
leds = [Pin(i, Pin.OUT) for i in range(0,9)]
# --- Variables ---
glass_count = 0
# --- Functions ---
def buzzer_on():
buzzer.freq(1000)
buzzer.duty_u16(30000)
def buzzer_off():
buzzer.duty_u16(0)
def play_melody():
notes = [523, 659, 784, 1047] # simple melody
for n in notes:
buzzer.freq(n)
buzzer.duty_u16(30000)
sleep(0.5) # short notes for beginner-friendly demo
buzzer_off()
sleep(0.2)
def update_leds():
for i in range(10):
if i < glass_count:
leds[i].value(1)
else:
leds[i].value(0)
# --- Start ---
lcd.clear()
lcd.write(0,0,"Pico Health Band")
while True:
# Reminder to drink water
lcd.clear()
lcd.write(0,0,"Drink Water!")
buzzer_on()
sleep(3) # buzzer rings for 3 sec
buzzer_off()
# Wait for stop button
if button_stop.value() == 1:
lcd.clear()
lcd.write(0,0,"Good job!")
sleep(2)
# Check add glass button
if button_add.value() == 1:
glass_count += 1
if glass_count > 10:
glass_count = 10
update_leds()
lcd.clear()
lcd.write(0,0,"Glasses: "+str(glass_count))
sleep(2)
# If goal reached
if glass_count == 10:
lcd.clear()
lcd.write(0,0,"Goal Reached!")
play_melody()
sleep(3)
# Wait before next reminder (shortened for demo)
sleep(10)