import utime
from machine import I2C, Pin
from liquid_crystal import LiquidCrystal
from liquid_crystal_i2c import LiquidCrystal_I2C
def main() -> None:
i2c: I2C = I2C(0, scl=Pin(1), sda=Pin(0), freq=100000)
gpio_list: tuple = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) # 8bit mode
# gpio_list: tuple = (2, 3, 4, 9, 10, 11, 12) # 4bit mode
print(f"GPIO display running: {len(gpio_list[3:])}bit mode")
print(f"I2C display running: 4bit mode")
# Initialize LCD with default parameters (2 rows, 16 columns, 5x8 font)
lcd1 = LiquidCrystal_I2C(i2c)
lcd2 = LiquidCrystal(gpio_list)
lcd1.backlight(True) # Backlight on
lcd1.clear_display() # Clear the display
lcd1.set_cursor(0, 0) # Set the cursor to print
lcd1.print("Hello, World!")
lcd2.backlight(Pin(13, Pin.OUT), True)
lcd2.clear_display()
lcd2.set_cursor(0, 0) # Set the cursor to print
lcd2.print("Hello, World!")
while True:
for i in range(100):
lcd1.set_cursor(1, 0) # allocate space for print variable
lcd1.print(" ") # Fill some space for avoid display clear
lcd1.set_cursor(1, 0)
lcd1.print(i) # Print the variable
lcd2.set_cursor(1, 0)
lcd2.print(" ")
lcd2.set_cursor(1, 0)
lcd2.print(i) # Print the variable
utime.sleep_ms(60)
if __name__ == "__main__":
main()