1
- ### cpx-ir-shutter-remote v1.1
1
+ ### cpx-ir-shutter-remote v1.2
2
2
### Circuit Playground Express (CPX) shutter remote using infrared for Sony Cameras
3
3
4
4
### copy this file to CPX as code.py
53
53
duty_cycle = round (20 / 100 * 65535 ))
54
54
ir_pulseout = pulseio .PulseOut (ir_carrier_pwm )
55
55
56
+ ### Used to observe 6.0.0-6.2.0 bug
57
+ ### https://github.com/adafruit/circuitpython/issues/4602
58
+ ##ir_carrier_pwm_a2debug = pulseio.PWMOut(board.A2,
59
+ ## frequency=CARRIER_IRFREQ_SONY,
60
+ ## duty_cycle=round(20 / 100 * 65535))
61
+ ##ir_pulseout_a2debug = pulseio.PulseOut(ir_carrier_pwm_a2debug)
62
+
56
63
### Sony timing values (in us) based on the ones in
57
64
### https://github.com/z3t0/Arduino-IRremote/blob/master/src/ir_Sony.cpp
58
65
### Disabling the addition of trail value is required to make this work
@@ -67,6 +74,20 @@ def fire_shutter():
67
74
This is a code used by Sony cameras."""
68
75
ir_encoder .transmit (ir_pulseout , [0xB4 , 0xB8 , 0xF0 ],
69
76
repeat = 2 , delay = 0.005 , nbits = 20 )
77
+ ### Send to A2 to help debug issue with 5.3.1 ok, 6.x broken
78
+ ###
79
+ ##ir_encoder.transmit(ir_pulseout_a2debug, [0xB4, 0xB8, 0xF0],
80
+ ## repeat=2, delay=0.005, nbits=20)
81
+
82
+
83
+ def say_interval (number_as_words ):
84
+ words = number_as_words .split () + ["seconds" ]
85
+ for word in words :
86
+ if word == "," :
87
+ time .sleep (0.15 )
88
+ else :
89
+ cp .play_file (WAV_DIR + "/" + word + ".wav" )
90
+ time .sleep (0.050 )
70
91
71
92
72
93
SHUTTER_CMD_COLOUR = (8 , 0 , 0 )
@@ -76,6 +97,25 @@ def fire_shutter():
76
97
S_TO_NS = 1000 * 1000 * 1000
77
98
ADJ_NS = 20 * 1000 * 1000
78
99
IMPENDING_NS = 2 * S_TO_NS
100
+ ### intervalometer mode announces the duration
101
+ manual_trig_wav = "button.wav"
102
+ sound_trig_wav = "noise.wav"
103
+ impending_wav = "ready.wav"
104
+ WAV_DIR = "num"
105
+ interval_words = ["five" ,
106
+ "ten" ,
107
+ "fifteen" ,
108
+ "twenty" ,
109
+ "twenty five" ,
110
+ "thirty" ,
111
+ "sixty" ,
112
+ "one hundred and twenty" ,
113
+ "one hundred and eighty" ,
114
+ "two hundred and forty" ,
115
+ "three hundred" ,
116
+ "six hundred" ,
117
+ "one thousand , eight hundred" ,
118
+ "three thousand , six hundred" ]
79
119
intervals = [5 , 10 , 15 , 20 , 25 , 30 , 60 ,
80
120
120 , 180 , 240 , 300 , 600 , 1800 , 3600 ]
81
121
interval_idx = intervals .index (30 ) ### default is 30 seconds
@@ -84,11 +124,15 @@ def fire_shutter():
84
124
first_cmd_ns = None
85
125
pixel_indication = True
86
126
impending = False
127
+ say_and_reset = False
87
128
88
129
while True :
89
130
### CPX switch to left
90
131
if cp .switch :
91
- intervalometer = False
132
+ if intervalometer :
133
+ cp .play_file (manual_trig_wav )
134
+ intervalometer = False
135
+
92
136
if cp .button_a : ### left button_a
93
137
if pixel_indication :
94
138
cp .pixels .fill (SHUTTER_CMD_COLOUR )
@@ -110,18 +154,27 @@ def fire_shutter():
110
154
### CPX switch to right
111
155
else :
112
156
if not intervalometer :
113
- last_cmd_ns = time . monotonic_ns ()
157
+ say_and_reset = True
114
158
intervalometer = True
115
159
160
+ ### Left button decreases time
116
161
if cp .button_a and interval_idx > 0 :
117
162
interval_idx -= 1
118
163
while cp .button_a :
119
164
pass ### wait for button release
165
+ say_and_reset = True
120
166
167
+ ### Right button increases time
121
168
elif cp .button_b and interval_idx < len (intervals ) - 1 :
122
169
interval_idx += 1
123
170
while cp .button_b :
124
171
pass ### wait for button release
172
+ say_and_reset = True
173
+
174
+ if say_and_reset :
175
+ say_interval (interval_words [interval_idx ])
176
+ last_cmd_ns = time .monotonic_ns ()
177
+ say_and_reset = False
125
178
126
179
### If enough time has elapsed fire the shutter
127
180
### or show the impending colour on NeoPixels
@@ -143,6 +196,6 @@ def fire_shutter():
143
196
and not impending
144
197
and now_ns - last_cmd_ns >= interval_ns - IMPENDING_NS ):
145
198
cp .pixels .fill (IMPENDING_COLOUR )
146
- time . sleep ( 0.1 )
199
+ cp . play_file ( impending_wav )
147
200
cp .pixels .fill (BLACK )
148
201
impending = True
0 commit comments