# IR excercise #2, toggle red, yellow, green and blue leds with remote 1, 2, 3 and 4
# Copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-08-26  initial release

from	machine	import	Pin
from	drivers	import	IrRec

# ============================= testKey =================================

# print remote code from pressed IR button
def testKey():
    print('press a IR remote button')
    ir = IrRec()
    while True:
        if code := ir.getKey():
            print(hex(code))
            
# =============================== Local =================================

class Led:
    
    def __init__(self, pin_nr):
        self.led = Pin(pin_nr, Pin.OUT, value=0)
        
        
    def toggle(self):
        self.led(not self.led())
        
# =============================== Main ==================================

class Main:
    key_1 = 0xFF6897
    key_2 = 0xFF9867
    key_3 = 0xFFB04F
    key_4 = 0xFF30CF

    def __init__(self):
       self.led_red    = Led(32)
       self.led_yellow = Led(33)
       self.led_green  = Led(25)
       self.led_blue   = Led(26)
       ir = IrRec()
       while True:
           if key := ir.getKey():
               if   key == self.key_1: self.led_red.toggle()
               elif key == self.key_2: self.led_yellow.toggle()
               elif key == self.key_3: self.led_green.toggle()
               elif key == self.key_4: self.led_blue.toggle()
               else: print(f'unknown key {key:X} pressed')
       
#testKey()
Main()
    
# ================================ end ===================================
