from machine import Pin, I2C
from time import sleep
import sys
from i2c_lcd import I2cLcd
# I2C LCD Setup
I2C_ADDR = 0x27
I2C_SCL = 22
I2C_SDA = 21
LCD_ROWS = 2
LCD_COLS = 16
i2c = I2C(0, scl=Pin(I2C_SCL), sda=Pin(I2C_SDA), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, LCD_ROWS, LCD_COLS)
lcd.clear()
lcd.putstr("Waiting input...")
def is_palindrome(s):
return s == s[::-1]
while True:
lcd.clear()
lcd.putstr("Enter number:")
print("Enter a number: ")
while not sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
sleep(0.1)
input_str = sys.stdin.readline().strip()
lcd.clear()
lcd.putstr(input_str[:16]) # display max 16 chars
lcd.move_to(0, 1)
if is_palindrome(input_str):
lcd.putstr("Palindrome :)")
print(f"{input_str} is a Palindrome!")
else:
lcd.putstr("Not Palindrome")
print(f"{input_str} is NOT a Palindrome!")
sleep(3)