diff --git a/README.rst b/README.rst index 77f372c..bc0f1bb 100644 --- a/README.rst +++ b/README.rst @@ -42,19 +42,31 @@ Usage Example import pulseio import board import adafruit_irremote + pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True) + decoder = adafruit_irremote.GenericDecode() + + # size must match what you are decoding! for NEC use 4 + received_code = bytearray(4) + + while True: + pulses = decoder.read_pulses(pulsein) + print("Heard", len(pulses), "Pulses:", pulses) + try: + code = decoder.decode_bits(pulses, debug=False) + print("Decoded:", code) + except adafruit_irremote.IRNECRepeatException: # unusual short code! + print("NEC repeat!") + except adafruit_irremote.IRDecodeException as e: # failed to decode + print("Failed to decode: ", e.args) + + print("----------------------------") - with pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True) as p: - d = adafruit_irremote.GenericDecode() - code = bytearray(4) - while True: - d.decode(p, code) - print(code) Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. Building locally diff --git a/adafruit_irremote.py b/adafruit_irremote.py index bfdd30a..0a2937b 100644 --- a/adafruit_irremote.py +++ b/adafruit_irremote.py @@ -25,18 +25,31 @@ Demo code for Circuit Playground Express: -.. code-block: python +.. code-block:: python + # Circuit Playground Express Demo Code + # Adjust the pulseio 'board.PIN' if using something else import pulseio import board import adafruit_irremote - - with pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True) as p: - d = adafruit_irremote.GenericDecode() - code = bytearray(4) - while True: - d.decode(p, code) - print(code) + pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True) + decoder = adafruit_irremote.GenericDecode() + + # size must match what you are decoding! for NEC use 4 + received_code = bytearray(4) + + while True: + pulses = decoder.read_pulses(pulsein) + print("Heard", len(pulses), "Pulses:", pulses) + try: + code = decoder.decode_bits(pulses, debug=False) + print("Decoded:", code) + except adafruit_irremote.IRNECRepeatException: # unusual short code! + print("NEC repeat!") + except adafruit_irremote.IRDecodeException as e: # failed to decode + print("Failed to decode: ", e.args) + + print("----------------------------") * Author(s): Scott Shawcroft