from machine import Pin
import time
ir_sensor = Pin(15, Pin.IN)
led = Pin(16, Pin.OUT)
blinking = False
POWER_ON_CODE = 0x10EF
def decode_ir_signal():
if ir_sensor.value() == 0:
time.sleep(0.05)
print("IR signal detected!")
return POWER_ON_CODE
return None
while True:
command = decode_ir_signal()
if command is not None:
print("Command received:", hex(command))
if command == POWER_ON_CODE:
blinking = not blinking
if blinking:
print("Blinking enabled (Power On)")
else:
led.off()
print("LED turned off (Power Off)")
else:
print("Ignored IR command")
if blinking:
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)
print("LED Blinking")
else:
led.off()
time.sleep(0.05)