"""
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Raspberry Pi Pico I2C LCD Display (MicroPython) ┃
┃ ┃
┃ An example of using an I2C LCD display with the ┃
┃ Raspberry Pi Pico. ┃
┃ ┃
┃ Copyright (c) 2023 Anderson Costa ┃
┃ GitHub: github.com/arcostasi ┃
┃ License: MIT ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
"""
from machine import I2C, Pin
from time import sleep
from pico_i2c_lcd import I2cLcd
btn_green = Pin(8, Pin.IN, Pin.PULL_UP)
btn_blue = Pin(9, Pin.IN, Pin.PULL_UP)
btn_yellow = Pin(10, Pin.IN, Pin.PULL_UP)
btn_red = Pin(15, Pin.IN, Pin.PULL_UP)
i2c_bus = I2C(0, sda=Pin(0), scl=Pin(1), freq=40000)
i2c_address = i2c_bus.scan()[0]
lcd_display = I2cLcd(i2c_bus, i2c_address, 2, 16)
def lcd_display_list(strings):
if strings:
for line in strings:
lcd_display.clear()
lcd_display.move_to(0, 0)
lcd_display.putstr(line)
sleep(1)
def display_line(line):
words = line.split()
line1 = words[0]
line2 = ""
for word in words[1:]:
line2 = line2 + word + " "
print(line2)
lcd_display.clear()
lcd_display.move_to(0,0)
lcd_display.putstr(line1)
lcd_display.move_to(0,1)
lcd_display.putstr(line2)
sentence = "Programming Is The Best"
while True:
if btn_green.value() == 0:
# make sentence all capitals
display_line(sentence)
elif btn_blue.value() == 0:
# make sentence all lowercase
display_line(sentence)
elif btn_yellow.value() == 0:
# Replace the word "Programming" with "MicroPython" in sentence
display_line(sentence)
elif btn_red.value() == 0:
# Replace the word "Micropython" with "Programming" in sentence
display_line(sentence)
sleep(0.3)