import time
from temperature_sensor import read_temperature
from display_controller import lcd
from led_controller import set_color, temperature_to_color
from motion_sensor import motion_sensor
from light_sensor import light_sensor
from joystick import get_joystick

def main():
    print("Entering main loop")    
    while True:
        try:
            temperature, hum = read_temperature()
            temperature = int(temperature)
            hum = int(hum)
            print(f"Temperature: {temperature}, Humidity: {hum}")

            lcd_string = f"T:{temperature:.1f}C H:{hum:.1f}%"
            lcd.clear()
            lcd.putstr(lcd_string)
            print(f"Displayed on LCD: {lcd_string}")
            
            sensed_motion = motion_sensor.value()
            if sensed_motion:
                print("Motion detected")
            
            sensed_light = light_sensor.value()
            if sensed_light:
                print(f"Light detected: {sensed_light}")

            get_joystick()
            time.sleep(0.5)
        
        except Exception as e:
            print(f"Error: {e}")

if __name__ == "__main__":
    print("Starting!")
    main()
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
wokwi-rgb-led-1:R
wokwi-rgb-led-1:COM
wokwi-rgb-led-1:G
wokwi-rgb-led-1:B
wokwi-dht22-1:VCC
wokwi-dht22-1:SDA
wokwi-dht22-1:NC
wokwi-dht22-1:GND
wokwi-pir-motion-sensor-1:VCC
wokwi-pir-motion-sensor-1:OUT
wokwi-pir-motion-sensor-1:GND
wokwi-photoresistor-sensor-1:VCC
wokwi-photoresistor-sensor-1:GND
wokwi-photoresistor-sensor-1:DO
wokwi-photoresistor-sensor-1:AO
wokwi-lcd1602-1:GND
wokwi-lcd1602-1:VCC
wokwi-lcd1602-1:SDA
wokwi-lcd1602-1:SCL
wokwi-analog-joystick-1:VCC
wokwi-analog-joystick-1:VERT
wokwi-analog-joystick-1:HORZ
wokwi-analog-joystick-1:SEL
wokwi-analog-joystick-1:GND