from machine import Pin
from time import sleep
import lcd
# Initialize LCD pins
lcd_rs = Pin(12, Pin.OUT)
lcd_e = Pin(11, Pin.OUT)
lcd_d4 = Pin(10, Pin.OUT)
lcd_d5 = Pin(9, Pin.OUT)
lcd_d6 = Pin(8, Pin.OUT)
lcd_d7 = Pin(7, Pin.OUT)
lcd.init(lcd_rs, lcd_e, lcd_d4, lcd_d5, lcd_d6, lcd_d7)
# Message to scroll
msg = "Welcome!"
while True:
pos = 16 # Start from just off-screen right
while pos >= -8: # Scroll until message disappears completely
lcd.clear()
# Set cursor to 0 (beginning of row)
lcd.setCursor(0, 0)
# Only print characters that are within screen range
for i in range(8):
char_pos = pos + i
if char_pos >= 0 and char_pos < 16:
lcd.setCursor(char_pos, 0)
lcd.print(msg[i])
sleep(0.3)
pos = pos - 1