Created
July 24, 2023 18:21
-
-
Save ypelletier/4cb9657b1383f3f832635c635062baac to your computer and use it in GitHub Desktop.
ommunication entre une télécommande à infrarouge Sony (20 bits) 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 | |
Sony (20 bits) 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.sony import SONY_20 | |
# 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 == 0x00 and addr == 0x001a: | |
# il s'agit du bouton "1" | |
print('Bouton 1') | |
if data == 0x01 and addr == 0x001a: | |
# il s'agit du bouton "2" | |
print('Bouton 2') | |
if data == 0x02 and addr == 0x001a: | |
# il s'agit du bouton "3" | |
print('Bouton 3') | |
# création d'un objet SONY_20. Le capteur est branché à la broche GP16 | |
ir = SONY_20(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