# CÂU 1 - MicroPython ESP32
from machine import Pin
import time
led_green = Pin(32, Pin.OUT)
led_yellow = Pin(33, Pin.OUT)
led_red = Pin(25, Pin.OUT)
temp = 20
increasing = True
def turn_off_all():
led_green.off()
led_yellow.off()
led_red.off()
while True:
# giả lập nhiệt độ
if increasing:
temp += 0.5
else:
temp -= 0.5
if temp >= 40:
increasing = False
if temp <= 20:
increasing = True
turn_off_all()
if temp < 25:
led_green.on()
elif temp <= 35:
led_yellow.on()
else:
led_red.on()
time.sleep(0.2)