File tree Expand file tree Collapse file tree 2 files changed +40
-15
lines changed Expand file tree Collapse file tree 2 files changed +40
-15
lines changed Original file line number Diff line number Diff line change @@ -42,19 +42,31 @@ Usage Example
42
42
import pulseio
43
43
import board
44
44
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 (" ----------------------------" )
45
63
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)
52
64
53
65
Contributing
54
66
============
55
67
56
68
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> `_
58
70
before contributing to help this project stay welcoming.
59
71
60
72
Building locally
Original file line number Diff line number Diff line change 25
25
26
26
Demo code for Circuit Playground Express:
27
27
28
- .. code-block: python
28
+ .. code-block:: python
29
29
30
+ # Circuit Playground Express Demo Code
31
+ # Adjust the pulseio 'board.PIN' if using something else
30
32
import pulseio
31
33
import board
32
34
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("----------------------------")
40
53
41
54
* Author(s): Scott Shawcroft
42
55
You can’t perform that action at this time.
0 commit comments