Skip to content

Commit 0b04de3

Browse files
authored
Merge pull request #10 from sommersoft/example_update
Example Updates
2 parents 3236a4f + a5c0c6e commit 0b04de3

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

README.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,31 @@ Usage Example
4242
import pulseio
4343
import board
4444
import adafruit_irremote
45+
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
46+
decoder = adafruit_irremote.GenericDecode()
47+
48+
# size must match what you are decoding! for NEC use 4
49+
received_code = bytearray(4)
50+
51+
while True:
52+
pulses = decoder.read_pulses(pulsein)
53+
print("Heard", len(pulses), "Pulses:", pulses)
54+
try:
55+
code = decoder.decode_bits(pulses, debug=False)
56+
print("Decoded:", code)
57+
except adafruit_irremote.IRNECRepeatException: # unusual short code!
58+
print("NEC repeat!")
59+
except adafruit_irremote.IRDecodeException as e: # failed to decode
60+
print("Failed to decode: ", e.args)
61+
62+
print("----------------------------")
4563
46-
with pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True) as p:
47-
d = adafruit_irremote.GenericDecode()
48-
code = bytearray(4)
49-
while True:
50-
d.decode(p, code)
51-
print(code)
5264
5365
Contributing
5466
============
5567

5668
Contributions are welcome! Please read our `Code of Conduct
57-
<https://github.com/adafruit/Adafruit_CircuitPython_irremote/blob/master/CODE_OF_CONDUCT.md>`_
69+
<https://github.com/adafruit/Adafruit_CircuitPython_IRRemote/blob/master/CODE_OF_CONDUCT.md>`_
5870
before contributing to help this project stay welcoming.
5971

6072
Building locally

adafruit_irremote.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,31 @@
2525
2626
Demo code for Circuit Playground Express:
2727
28-
.. code-block: python
28+
.. code-block:: python
2929
30+
# Circuit Playground Express Demo Code
31+
# Adjust the pulseio 'board.PIN' if using something else
3032
import pulseio
3133
import board
3234
import adafruit_irremote
33-
34-
with pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True) as p:
35-
d = adafruit_irremote.GenericDecode()
36-
code = bytearray(4)
37-
while True:
38-
d.decode(p, code)
39-
print(code)
35+
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
36+
decoder = adafruit_irremote.GenericDecode()
37+
38+
# size must match what you are decoding! for NEC use 4
39+
received_code = bytearray(4)
40+
41+
while True:
42+
pulses = decoder.read_pulses(pulsein)
43+
print("Heard", len(pulses), "Pulses:", pulses)
44+
try:
45+
code = decoder.decode_bits(pulses, debug=False)
46+
print("Decoded:", code)
47+
except adafruit_irremote.IRNECRepeatException: # unusual short code!
48+
print("NEC repeat!")
49+
except adafruit_irremote.IRDecodeException as e: # failed to decode
50+
print("Failed to decode: ", e.args)
51+
52+
print("----------------------------")
4053
4154
* Author(s): Scott Shawcroft
4255

0 commit comments

Comments
 (0)