Skip to content

Commit 043c8e4

Browse files
committed
going for v0.3.0
1 parent cba254f commit 043c8e4

3 files changed

Lines changed: 74 additions & 18 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ dumbdisplay_experimental
1111
/_dd.py
1212
/_test.ipynb
1313
/.micropico
14+
/experiments/pyclock
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
import machine
3+
from machine import Pin
4+
@rp2.asm_pio(
5+
set_init=rp2.PIO.OUT_LOW,
6+
in_shiftdir=rp2.PIO.SHIFT_LEFT,
7+
out_shiftdir=rp2.PIO.SHIFT_LEFT,
8+
)
9+
def wave_prog():
10+
pull(block)
11+
mov(x, osr) # waveCount
12+
pull(block)
13+
label("loop")
14+
mov(y, osr) # halfWaveNumCycles
15+
set(pins, 1) # high
16+
label("high")
17+
jmp(y_dec, "high")
18+
mov(y, osr) # halfWaveNumCycles
19+
set(pins, 0) # low
20+
label("low")
21+
jmp(y_dec, "low")
22+
jmp(x_dec, "loop")
23+
sm = rp2.StateMachine(0, wave_prog, freq=1953125, set_base=Pin(5)) # the clock frequency of Raspberry Pi Pico is 125MHz; 1953125 is 125MHz / 64
24+
sm.active(1)
25+
def HWPlayTone(freq: int, duration: int):
26+
halfWaveNumCycles = round(1953125.0 / freq / 2) # count 1 cycle for jmp() ==> 1 cycle per half wave ==> 2 cycles per wave
27+
waveCount = round(duration * freq / 1000.0)
28+
sm.put(waveCount)
29+
sm.put(halfWaveNumCycles)
30+
31+
import time
32+
HWPlayTone(262, 1000) # Do
33+
time.sleep(1)
34+
HWPlayTone(294, 1000) # Re
35+
time.sleep(1)
36+
HWPlayTone(330, 1000) # Mi
37+
time.sleep(1)

experiments/picopio/pio_neo_blink.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ def neo_prog():
2929
label("loop_pixel_bit")
3030
out(y, 1) # y <= left-most 1 bit of sor
3131
jmp(not_y, "bit_0")
32-
set(pins, 1).delay(15)
33-
set(pins, 0).delay(8)
32+
set(pins, 1).delay(15) # 1: high (16 cycles)
33+
set(pins, 0).delay(8) # 1: low (9 cycles)
3434
jmp("bit_end")
3535
label("bit_0")
36-
set(pins, 1).delay(7)
37-
set(pins, 0).delay(16)
36+
set(pins, 1).delay(7) # 0: high (8 cycles)
37+
set(pins, 0).delay(16) # 0: low (17 cycles)
3838
label("bit_end")
3939
jmp(x_dec, "loop_pixel_bit") # x is bit counter
4040
mov(y, isr) # y <= isr (pixel counter)
4141
jmp(y_dec, "loop_pixel") # y is pixel counter
42-
label("debug")
43-
set(y, 8)
44-
label("debug_2")
45-
mov(isr, y)
46-
push()
42+
# label("debug")
43+
# set(y, 8)
44+
# label("debug_2")
45+
# mov(isr, y)
46+
# push()
4747

4848
sm = rp2.StateMachine(0, neo_prog, freq=20_000_000, set_base=Pin(22))
4949
sm.active(1)
@@ -64,17 +64,35 @@ def ShowNeoPixels(*pixels):
6464
#print(f". [{i}] = {pixel} ({grb})")
6565
sm.put(grb, 8)
6666
time.sleep_us(300)
67-
res = sm.get()
68-
print(f"got result {res}")
69-
67+
# res = sm.get()
68+
# print(f"got result {res}")
69+
70+
7071
NUM_PIXELS = 4
7172
Pixels = []
7273
for i in range(NUM_PIXELS):
7374
Pixels.append(None)
7475

75-
Pixels[0] = (128, 0, 0)
76-
Pixels[1] = (0, 128, 0)
77-
Pixels[2] = (0, 0, 128)
78-
Pixels[3] = (32, 32, 32)
79-
ShowNeoPixels(*Pixels)
80-
76+
# Pixels[0] = (128, 0, 0)
77+
# Pixels[1] = (0, 128, 0)
78+
# Pixels[2] = (0, 0, 128)
79+
# Pixels[3] = (32, 32, 32)
80+
# ShowNeoPixels(*Pixels)
81+
82+
83+
rgb = 0
84+
i = 0
85+
while True:
86+
if rgb == 0:
87+
c = (255, 0, 0)
88+
elif rgb == 1:
89+
c = (0, 255, 0)
90+
else:
91+
c = (0, 0, 255)
92+
Pixels[i] = c
93+
ShowNeoPixels(*Pixels)
94+
time.sleep(0.1)
95+
Pixels[i] = (0, 0, 0)
96+
ShowNeoPixels(*Pixels)
97+
rgb = (rgb + 1) % 3
98+
i = (i + 1) % NUM_PIXELS

0 commit comments

Comments
 (0)