Created
July 19, 2024 11:05
-
-
Save qbalsdon/37fdb108bd987a61b56fe536967416a5 to your computer and use it in GitHub Desktop.
PicoBricks: Read value from IR sensor and output to serial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PicoBricks read value from IR sensor and output to serial | |
# Thonny IDE | |
# Reference: https://picobricks.com/blogs/robotic-stem-projects/remote-test-project | |
from time import sleep | |
from machine import Pin | |
import machine | |
import time | |
from picobricks import NEC_16 | |
from picobricks import IR_RX | |
def ir_callback(data, addr, ctrl): | |
global ir_data | |
global ir_addr, data_rcvd | |
if data > 0: | |
ir_data = data | |
ir_addr = addr | |
data_rcvd = True | |
ir = NEC_16(Pin(0, Pin.IN), ir_callback) | |
ir_data = 0 | |
data_rcvd = False | |
# reference: https://github.com/Robotistan/PicoBricks/blob/403ba1953ee4a990fcdf3876c7ecf3d3c473c2c8/Software/Pre-Installed%20Code/picobricks.py#L1038 | |
def data_to_key_name(data): | |
if data == 69: return "1" | |
if data == 70: return "2" | |
if data == 71: return "3" | |
if data == 68: return "4" | |
if data == 64: return "5" | |
if data == 67: return "6" | |
if data == 7: return "7" | |
if data == 21: return "8" | |
if data == 9: return "9" | |
if data == 22: return "*" | |
if data == 25: return "0" | |
if data == 13: return "#" | |
if data == 24: return "^" | |
if data == 8: return "<" | |
if data == 28: return "§" | |
if data == 90: return ">" | |
if data == 82: return "V" | |
return "Unknown [{}]".format(data) | |
while True: | |
if data_rcvd == True: | |
data_rcvd = False | |
print("Key [{}]".format(data_to_key_name(ir_data))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment