from machine import Pin
import time
# Define the IR receiver and LED pins
ir_sensor = Pin(15, Pin.IN)
led = Pin(16, Pin.OUT)
blinking = False
# Replace with the actual IR code for the "Power On" button on your remote
POWER_ON_CODE = 0x10EF # Example IR code for "Power On"
# Simulate IR signal decoding
def decode_ir_signal():
# Simulate detecting a specific IR signal when IR sensor gets input
if ir_sensor.value() == 0: # Simulating IR signal detection
time.sleep(0.05) # Delay to simulate decoding process
print("IR signal detected!")
return POWER_ON_CODE # Simulate receiving "Power On" button IR code
return None
while True:
# Detect and decode IR signal
command = decode_ir_signal() # In a real scenario, this should decode the IR code
if command is not None:
print("Command received:", hex(command))
# Check if the received command matches the "Power On" IR code
if command == POWER_ON_CODE:
# Toggle the blinking state on each press of "Power On"
blinking = not blinking
if blinking:
print("Blinking enabled (Power On)")
else:
led.off() # Turn off the LED immediately when blinking stops
print("LED turned off (Power Off)")
else:
print("Ignored IR command") # Ignore any other IR command
# Control LED blinking based on the blinking flag
if blinking:
led.on()
time.sleep(0.2) # Adjust blink rate
led.off()
time.sleep(0.2)
print("LED Blinking")
else:
led.off() # Ensure LED stays off when not blinking
time.sleep(0.05) # Small delay for smoother operation