File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66try :
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 )
4750except :
4851 print ("*****" )
You can’t perform that action at this time.
0 commit comments