from utime import sleep
from picozero import Servo  

import time
from machine import Pin, freq, PWM
import print_error
from nec import NEC_8

pin_ir = Pin(12, Pin.IN)
led1 = Pin(3,Pin.OUT)
led2 = Pin(5,Pin.OUT)
servo = Servo(19)

Power = 162
Menu = 226
Test = 34
Plus = 2
Back = 194
Previous = 224
Play = 168
Next = 144
Minus = 152
C = 176
button0 = 104
button1 = 48
button2 = 24
button3 = 122
button4 = 16
button5 = 56
button6 = 90
button7 = 66
button8 = 74
button9 = 82

def decodeKeyValue(data):
    return data
    

def callback(data, addr, ctrl):
    if data < 0:  
        pass
    else:
        print(data)
        if data == Plus:
            print("PLUS")
        elif data == Minus:
            print("MINUS")
        elif data == Previous:
            led2.value(1)
            led2.on()
            sleep(2)
            led2.off()
            print("PREVIOUS")
        elif data == Next:
            led1.value(1)
            led1.on()
            sleep(2)
            led1.off()
            print("NEXT")
        elif data == Power:
            servo.min()
            sleep(1)
            servo.mid()
            sleep(1)
            print("POWER")
        elif data == Menu:
            print("MENU")
        elif data == Test:
            print("TEST")
        elif data == Back:
            print("BACK")
        elif data == Play:
            print("PLAY")
        elif data == C:
            print("CCCC")
        elif data == button0:
            print("Button 0 Pressed")
        elif data == button1:
            print("Button 1 Pressed")
        elif data == button2:
            print("Button 2 Pressed")
        elif data == button3:
            print("Button 3 Pressed")
        elif data == button4:
            print("Button 4 Pressed")
        elif data == button5:
            print("Button 5 Pressed")
        elif data == button6:
            print("Button 6 Pressed")
        elif data == button7:
            print("Button 7 Pressed")
        elif data == button8:
            print("Button 8 Pressed")
        elif data == button9:
            print("Button 9 Pressed")


        else:
            print("Unknown")

ir = NEC_8(pin_ir, callback) 
ir.error_function(print_error) 
try:
    while True:
        pass
except KeyboardInterrupt:
    ir.close()
Wokwi - Online ESP32, STM32, Arduino Simulator