Skip to content

Commit b441fec

Browse files
committed
going for v0.3.0
1 parent 7435ff7 commit b441fec

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

samples/melody/main.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,26 @@ def wave_prog():
3030
label("low")
3131
jmp(y_dec, "low")
3232
jmp(x_dec, "loop")
33-
set(x, 1)
34-
mov(isr, x)
35-
push()
33+
# set(x, 1)
34+
# mov(isr, x)
35+
# push()
3636
sm = rp2.StateMachine(0, wave_prog, freq=100000, set_base=Pin(SPEAKER_PIN))
37-
def HWPlayToneBlocked(freq: int, duration: int):
37+
sm.active(1)
38+
def HWPlayTone(freq: int, duration: int):
3839
halfWaveNumCycles = round((100000.0 / 2) / freq) # 2 is the number of cycles per half wave
3940
waveCount = round(duration * freq / 1000.0)
4041
#print(". freq", freq)
4142
#print(". duration", duration)
4243
#print(". halfWaveNumCycles", halfWaveNumCycles)
4344
#print(". waveCount", waveCount)
44-
sm.active(1)
45+
#sm.active(1)
4546
#start_ms = time.ticks_ms()
4647
sm.put(waveCount)
4748
sm.put(halfWaveNumCycles) # 2 * (x / 10) == blink time
48-
res = sm.get()
49-
#taken_ms = time.ticks_ms() - start_ms
50-
#print(f"= got result {res} in {taken_ms:.2} ms")
51-
sm.active(0)
49+
# res = sm.get()
50+
# #taken_ms = time.ticks_ms() - start_ms
51+
# #print(f"= got result {res} in {taken_ms:.2} ms")
52+
# sm.active(0)
5253
except:
5354
print("*****")
5455
print("* No HWPlayToneBlocked")
@@ -152,11 +153,11 @@ def GetNoteFreq(octave, noteIdx):
152153

153154
def PlayTone(freq: int, duration: int, playToSpeaker: bool):
154155
if playToSpeaker:
155-
if HWPlayToneBlocked:
156-
HWPlayToneBlocked(freq, duration)
156+
if HWPlayTone:
157+
HWPlayTone(freq, duration)
157158
else:
158159
dd.tone(freq, duration)
159-
dd.sleep_ms(duration)
160+
dd.sleep_ms(duration)
160161

161162

162163
def FeedbackHandler(layer, type, x, y):
@@ -192,7 +193,7 @@ def __init__(self):
192193
self.lyricLayer.backgroundColor("lightgray")
193194
self.lyricLayer.setTextFont("DL::Roboto")
194195

195-
if not HWPlayToneBlocked:
196+
if not HWPlayTone:
196197
self.targetLayer.disabled()
197198

198199
dd.pinAutoPinLayers(

0 commit comments

Comments
 (0)