Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://docs.sunfounder.com/projects/pico-2w-kit/en/latest/pyproject/py_irremote.html
- # Modified for CROSS remote 31 July 2025 by Tony Goodhew
- import time
- from machine import Pin
- from ir_rx.nec import NEC_8 # Adjust based on your remote's protocol
- from ir_rx.print_error import print_error
- # Initialize the IR receiver pin
- ir_pin = Pin(17, Pin.IN)
- # Callback function to handle received data
- def ir_callback(data, addr, ctrl):
- if data < 0: # Repeat code or error
- pass
- else:
- # print(data)
- key = decode_key(data)
- print("Received Key:", key)
- # Function to decode the received data into key presses
- def decode_key(data):
- key_codes = {
- 69: "1",
- 70: "2",
- 71: "3",
- 68: "4",
- 64: "5",
- 67: "6",
- 7: "7",
- 21: "8",
- 9: "9",
- 22: "*",
- 25: "0",
- 13: "#",
- 24: "U",
- 8: "L",
- 28: "K",
- 90: "R",
- 82: "D",
- 0x0: "ERROR"
- # Add more key codes based on your remote
- }
- return key_codes.get(data, "UNKNOWN")
- # Instantiate the IR receiver
- ir = NEC_8(ir_pin, ir_callback)
- ir.error_function(print_error) # Optional: to print errors
- try:
- while True:
- time.sleep(1) # Keep the main thread alive
- except KeyboardInterrupt:
- ir.close()
- print("Program terminated")
Advertisement
Add Comment
Please, Sign In to add comment