Skip to content

Commit 2c93111

Browse files
author
Kevin J Walters
committed
Adding audio for changing modes and more importantly reading out the duration changes.
Moving IR sending into fire_shutter(). Adding an impending shutter fire 2 seconds before it happens in intervalometer mode with yellow flash and ready audio sample. Commented out code to send same pulses to A2 to demonstrate bug for adafruit/circuitpython#4602
1 parent e502cb8 commit 2c93111

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

cpx/cpx-ir-shutter-remote.py

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### cpx-ir-shutter-remote v1.1
1+
### cpx-ir-shutter-remote v1.2
22
### Circuit Playground Express (CPX) shutter remote using infrared for Sony Cameras
33

44
### copy this file to CPX as code.py
@@ -53,6 +53,13 @@
5353
duty_cycle=round(20 / 100 * 65535))
5454
ir_pulseout = pulseio.PulseOut(ir_carrier_pwm)
5555

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+
5663
### Sony timing values (in us) based on the ones in
5764
### https://github.com/z3t0/Arduino-IRremote/blob/master/src/ir_Sony.cpp
5865
### Disabling the addition of trail value is required to make this work
@@ -67,6 +74,20 @@ def fire_shutter():
6774
This is a code used by Sony cameras."""
6875
ir_encoder.transmit(ir_pulseout, [0xB4, 0xB8, 0xF0],
6976
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)
7091

7192

7293
SHUTTER_CMD_COLOUR = (8, 0, 0)
@@ -76,6 +97,25 @@ def fire_shutter():
7697
S_TO_NS = 1000 * 1000 * 1000
7798
ADJ_NS = 20 * 1000 * 1000
7899
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"]
79119
intervals = [5, 10, 15, 20, 25, 30, 60,
80120
120, 180, 240, 300, 600, 1800, 3600]
81121
interval_idx = intervals.index(30) ### default is 30 seconds
@@ -84,11 +124,15 @@ def fire_shutter():
84124
first_cmd_ns = None
85125
pixel_indication = True
86126
impending = False
127+
say_and_reset = False
87128

88129
while True:
89130
### CPX switch to left
90131
if cp.switch:
91-
intervalometer = False
132+
if intervalometer:
133+
cp.play_file(manual_trig_wav)
134+
intervalometer = False
135+
92136
if cp.button_a: ### left button_a
93137
if pixel_indication:
94138
cp.pixels.fill(SHUTTER_CMD_COLOUR)
@@ -110,18 +154,27 @@ def fire_shutter():
110154
### CPX switch to right
111155
else:
112156
if not intervalometer:
113-
last_cmd_ns = time.monotonic_ns()
157+
say_and_reset = True
114158
intervalometer = True
115159

160+
### Left button decreases time
116161
if cp.button_a and interval_idx > 0:
117162
interval_idx -= 1
118163
while cp.button_a:
119164
pass ### wait for button release
165+
say_and_reset = True
120166

167+
### Right button increases time
121168
elif cp.button_b and interval_idx < len(intervals) - 1:
122169
interval_idx += 1
123170
while cp.button_b:
124171
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
125178

126179
### If enough time has elapsed fire the shutter
127180
### or show the impending colour on NeoPixels
@@ -143,6 +196,6 @@ def fire_shutter():
143196
and not impending
144197
and now_ns - last_cmd_ns >= interval_ns - IMPENDING_NS):
145198
cp.pixels.fill(IMPENDING_COLOUR)
146-
time.sleep(0.1)
199+
cp.play_file(impending_wav)
147200
cp.pixels.fill(BLACK)
148201
impending = True

0 commit comments

Comments
 (0)