import utime
from machine import I2C, Pin
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
I2C_ADDR = 39 # The address for LCD
I2C_NUM_ROWS = 2 # We use the 16*2 LCD
I2C_NUM_COLS = 16 # We use the 16*2 LCD
# I2C and LCD setup
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
def count_to_10():
"""Display 'Count:' fixed on the LCD and update numbers 1 to 10."""
print("Starting") # Debug: function is called
lcd.clear()
lcd.move_to(0, 0)
lcd.putstr("Count:") # Display fixed text "Count:"
print("LCD title 'Count:' displayed") # Debug checkpoint
for i in range(1, 11):
print("Current i=", i) # Debug: check loop + value
lcd.move_to(7, 0) # Move cursor to the number position
lcd.putstr(" ") # Clear previous number
lcd.move_to(7, 0) # Move cursor back again
lcd.putstr(str(i)) # Display current number
utime.sleep(1)
print("Finished")
# Forever loop calling the function
while True:
count_to_10()
utime.sleep(2) # Optional pause before restarting