Skip to content

Commit ff0f9a6

Browse files
committed
going for v0.3.0
1 parent 6f061b4 commit ff0f9a6

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

samples/melody/main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
try:
77
# https://docs.micropython.org/en/latest/library/rp2.html
8+
SPEAKER_PIN = 5
89
import time
910
import rp2
1011
from machine import Pin
@@ -30,19 +31,21 @@ def wave_prog():
3031
set(x, 1)
3132
mov(isr, x)
3233
push()
33-
sm = rp2.StateMachine(0, wave_prog, freq=10000, set_base=Pin(15))
34+
sm = rp2.StateMachine(0, wave_prog, freq=100000, set_base=Pin(SPEAKER_PIN))
3435
def HWPlayToneBlocked(freq: int, duration: int):
35-
halfWaveNumCycles = int(10000 / freq / 2)
36-
waveCount = int(duration / freq / 2)
37-
#print("halfWaveNumCycles", halfWaveNumCycles)
38-
#print("waveCount", waveCount)
36+
halfWaveNumCycles = round(50000.0 / freq)
37+
waveCount = round(duration * freq / 1000.0)
38+
print(". freq", freq)
39+
print(". duration", duration)
40+
print(". halfWaveNumCycles", halfWaveNumCycles)
41+
print(". waveCount", waveCount)
3942
sm.active(1)
4043
start_ms = time.ticks_ms()
4144
sm.put(waveCount)
4245
sm.put(halfWaveNumCycles) # 2 * (x / 10) == blink time
4346
res = sm.get()
4447
taken_ms = time.ticks_ms() - start_ms
45-
#print(f"got result {res} in {taken_ms:.2} ms")
48+
print(f"= got result {res} in {taken_ms:.2} ms")
4649
sm.active(0)
4750
except:
4851
print("*****")

0 commit comments

Comments
 (0)