import machine
import utime

# Define GPIO pins
BUTTON_1_PIN = 18
BUTTON_2_PIN = 19

# Initialize GPIO pins for buttons
button1 = machine.Pin(BUTTON_1_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)
button2 = machine.Pin(BUTTON_2_PIN, machine.Pin.IN, machine.Pin.PULL_DOWN)

# Initialize SPI for LCD
spi = machine.SPI(0, baudrate=20000000, polarity=0, phase=0, sck=machine.Pin(10), mosi=machine.Pin(11))

# Initialize ILI9341 LCD
cs = machine.Pin(17, machine.Pin.OUT)
dc = machine.Pin(20, machine.Pin.OUT)
rst = machine.Pin(16, machine.Pin.OUT)
cs.value(1)
rst.value(0)
utime.sleep_ms(50)
rst.value(1)

# ILI9341 initialization commands
spi.write(b'\x01')  # Software reset
utime.sleep_ms(100)
spi.write(b'\x11')  # Sleep out
utime.sleep_ms(100)
spi.write(b'\xB1\x01\x2C\x2D')  # Frame control
spi.write(b'\xB2\x01\x2C\x2D')  # Frame control
spi.write(b'\xB3\x01\x2C\x2D\x01\x2C\x2D')  # Frame control
spi.write(b'\xB4\x07')  # Display inversion control
spi.write(b'\xC0\xA2\x02\x84')  # Power control
spi.write(b'\xC1\xC5')  # Power control
spi.write(b'\xC2\x0A\x00')  # Power control
spi.write(b'\xC3\x8A\x2A')  # Power control
spi.write(b'\xC4\x8A\xEE')  # Power control
spi.write(b'\xC5\x0E')  # VCOM control
spi.write(b'\x36\x08')  # Memory access control
spi.write(b'\x3A\x55')  # Pixel format set
spi.write(b'\x2A\x00\x00\x00\x7F')  # Column address set
spi.write(b'\x2B\x00\x00\x00\x9F')  # Row address set
spi.write(b'\x29')  # Display on
utime.sleep_ms(500)

# Function to read buttons
def read_buttons():
    return button1.value(), button2.value()

# Main loop
while True:
    button1_state, button2_state = read_buttons()
    print("Button 1 state:", button1_state)
    print("Button 2 state:", button2_state)
    utime.sleep(0.1)  # Adjust delay as needed
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT