Created
July 24, 2023 18:21
-
-
Save ypelletier/b57b0f7ee82e1f896df2809bf636e067 to your computer and use it in GitHub Desktop.
Communication entre une télécommande à infrarouge Samsung et un Raspberry Pi Pico. Un TSOP4838 est branché à la broche GP16 du RP Pico.
This file contains hidden or 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
''' | |
Communication entre une télécommande à infrarouge | |
Samsung et un Raspberry Pi Pico. Un TSOP4838 est branché | |
à la broche GP16 du RP Pico. | |
Bibliothèque micropython_ir par Peter Hinch: | |
https://github.com/peterhinch/micropython_ir | |
Pour plus d'informations, voici l'article détaillé: | |
https://electroniqueamateur.blogspot.com/2023/07/controler-un-raspberry-pi-pico-avec-une.html | |
''' | |
from machine import Pin | |
import time | |
from ir_rx.nec import SAMSUNG | |
# routine qui s'exécutera lorsqu'un bouton de la télécommande | |
# sera enfoncé | |
def callback(data, addr, ctrl): | |
# on affiche la valeur hexadécimale de Data et de Addr. | |
# ces valeurs sont différentes selon le bouton enfoncé. | |
print('Data {:02x} Addr {:04x}'.format(data, addr)) | |
if data == 0x04 and addr == 0x0707: | |
# il s'agit du bouton "1" | |
print('Bouton 1') | |
if data == 0x05 and addr == 0x0707: | |
# il s'agit du bouton "2" | |
print('Bouton 2') | |
if data == 0x06 and addr == 0x0707: | |
# il s'agit du bouton "3" | |
print('Bouton 3') | |
# création d'un objet SAMSUNG. Le capteur est branché à la broche GP16 | |
ir = SAMSUNG(Pin(16, Pin.IN), callback) | |
print ("Veuillez appuyer sur un bouton de la telecommande.") | |
while True: | |
time.sleep_ms(500) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment