Skip to content

Commit 26c5b13

Browse files
committed
going for v0.3.0
1 parent 03c671f commit 26c5b13

3 files changed

Lines changed: 83 additions & 28 deletions

File tree

dumbdisplay/_ddlayer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,18 @@ def padding(self, left, top = None, right = None, bottom = None):
7676
self.dd._sendCommand(self.layer_id, "padding", str(left), str(top), str(right), str(bottom))
7777
def noPadding(self):
7878
self.dd._sendCommand(self.layer_id, "padding")
79-
def margin(self, left, top, right, bottom):
79+
def margin(self, left, top = None, right = None, bottom = None):
8080
'''see border() for size unit'''
81-
self.dd._sendCommand(self.layer_id, "margin", str(left), str(top), str(right), str(bottom))
81+
if top == None and right == None and bottom == None:
82+
self.dd._sendCommand(self.layer_id, "margin", str(left))
83+
else:
84+
if top == None:
85+
top = left
86+
if right == None:
87+
right = left
88+
if bottom == None:
89+
bottom = top
90+
self.dd._sendCommand(self.layer_id, "margin", str(left), str(top), str(right), str(bottom))
8291
def noMargin(self):
8392
self.dd._sendCommand(self.layer_id, "margin")
8493
def backgroundColor(self, color):

samples/melody/main.py

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
)
1919
def wave_prog():
2020
pull(block)
21-
mov(x, osr) # number of waves
21+
mov(x, osr) # waveCount
2222
pull(block)
2323
label("loop")
24-
mov(y, osr) # wave half len number of cycles
24+
mov(y, osr) # halfWaveNumCycles
2525
set(pins, 1) # high
2626
label("high")
2727
jmp(y_dec, "high")
28-
mov(y, osr) # wave half len number of cycles
28+
mov(y, osr) # halfWaveNumCycles
2929
set(pins, 0) # low
3030
label("low")
3131
jmp(y_dec, "low")
@@ -35,7 +35,7 @@ def wave_prog():
3535
push()
3636
sm = rp2.StateMachine(0, wave_prog, freq=100000, set_base=Pin(SPEAKER_PIN))
3737
def HWPlayToneBlocked(freq: int, duration: int):
38-
halfWaveNumCycles = round(50000.0 / freq)
38+
halfWaveNumCycles = round((100000.0 / 2) / freq) # 2 is the number of cycles per half wave
3939
waveCount = round(duration * freq / 1000.0)
4040
#print(". freq", freq)
4141
#print(". duration", duration)
@@ -59,13 +59,48 @@ def HWPlayToneBlocked(freq: int, duration: int):
5959
Song = "G C E C E D C A G G C E C E D G E G E G E C G A C C A G G C E C E D C Z"
6060
Octave = "0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 Z"
6161
Beat = "2 4 1 1 4 2 4 2 4 2 4 1 1 4 2 8 2 1 1 1 1 4 2 4 1 1 1 4 2 4 1 1 4 2 8 Z"
62+
Lyrics = [
63+
[
64+
"4:Amazing",
65+
"1:Grace",
66+
"1:How",
67+
"1:sweet",
68+
"1:the",
69+
"1:sound", ],
70+
[
71+
"1:That",
72+
"1:saved",
73+
"2:a",
74+
"1:wretch",
75+
"1:like",
76+
"1:me", ],
77+
[
78+
"1:I",
79+
"2:once",
80+
"2:was",
81+
"1:lost", ],
82+
[
83+
"1:but",
84+
"1:now",
85+
"1:am",
86+
"1:found", ],
87+
[
88+
"1:Was",
89+
"1:blind",
90+
"2:but",
91+
"1:now",
92+
"1:I",
93+
"1:see",
94+
],
95+
]
6296

6397
BeatSpeed = 300
6498

65-
TOP_HEIGHT = 30
66-
WIDTH = 14
67-
HEIGHT = 80
68-
BORDER = 1
99+
#TOP_HEIGHT = 30
100+
TOP_HEIGHT = 50
101+
KEY_WIDTH = 14
102+
KEY_HEIGHT = 80
103+
KEY_BORDER = 1
69104

70105

71106
# create DumbDisplay
@@ -133,13 +168,13 @@ class MelodyApp:
133168

134169
def __init__(self):
135170
self.play = False
136-
self.playToSpeaker = HWPlayToneBlocked != None
171+
self.playToSpeaker = False
137172
self.restart = False
138173
self.adhocFreq = -1
139174

140175
dd.recordLayerSetupCommands()
141176

142-
dd.configPinFrame(9 * WIDTH, TOP_HEIGHT + HEIGHT)
177+
dd.configPinFrame(9 * KEY_WIDTH, TOP_HEIGHT + KEY_HEIGHT)
143178

144179
self.setupKey(-1, 11)
145180
for i in range(0, 12):
@@ -149,21 +184,32 @@ def __init__(self):
149184
self.playLayer = self.setupButton("⏯")
150185
self.restartLayer = self.setupButton("⏮")
151186
self.targetLayer = self.setupButton("📢")
187+
self.lyricLayer = LayerLcd(dd, 20, 2)
188+
self.lyricLayer.margin(2)
189+
self.lyricLayer.border(1, "blue", "round")
190+
self.lyricLayer.writeCenteredLine("hello")
152191

153192
if not HWPlayToneBlocked:
154193
self.targetLayer.disabled()
155194

156-
dd.pinAutoPinLayers(AutoPin("H", self.playLayer, self.restartLayer, self.targetLayer).build(), 0, 0, 9 * WIDTH, TOP_HEIGHT)
195+
dd.pinAutoPinLayers(
196+
AutoPin("V",
197+
AutoPin("H", self.playLayer, self.restartLayer, self.targetLayer),
198+
self.lyricLayer).build(),
199+
0, 0, 9 * KEY_WIDTH, TOP_HEIGHT)
157200

158201
dd.playbackLayerSetupCommands("uddmelody")
159202

160203
def run(self):
161204
while True:
162205
i = 0
206+
self.lyricLayer.clear()
163207
while True:
164208
dd.timeslice()
165209
if self.adhocFreq != -1:
166210
# key on DumbDisplay pressed ... play the note/tone of the key press
211+
if not self.play:
212+
self.lyricLayer.writeCenteredLine(f"🎵 {self.adhocFreq}")
167213
PlayTone(self.adhocFreq, 200, self.playToSpeaker)
168214
self.adhocFreq = -1
169215
if self.restart:
@@ -194,37 +240,37 @@ def run(self):
194240

195241

196242
def setupKey(self, octaveOffset: int, noteIdx: int) -> LayerGraphical:
197-
width = WIDTH - 2 * BORDER
198-
xOffset = noteIdx * WIDTH / 2
243+
width = KEY_WIDTH - 2 * KEY_BORDER
244+
xOffset = noteIdx * KEY_WIDTH / 2
199245
#height
200246
#bgColor
201247
isSemi = False
202248
if noteIdx == 1 or noteIdx == 3 or noteIdx == 6 or noteIdx == 8 or noteIdx == 10:
203-
height = HEIGHT / 2 + 10
249+
height = KEY_HEIGHT / 2 + 10
204250
bgColor = "black"
205251
isSemi = True
206252
else:
207-
height = HEIGHT
253+
height = KEY_HEIGHT
208254
bgColor = "white"
209255
if noteIdx > 4:
210-
xOffset += WIDTH / 2
256+
xOffset += KEY_WIDTH / 2
211257
keyLayer = LayerGraphical(dd, width, height)
212258
keyLayer.octaveOffset = octaveOffset
213259
keyLayer.noteIdx = noteIdx
214260
keyLayer.backgroundColor(bgColor)
215-
keyLayer.border(BORDER, "gray")
261+
keyLayer.border(KEY_BORDER, "gray")
216262
keyLayer.padding(0)
217263
keyLayer.enableFeedback("fa", FeedbackHandler)
218264
if isSemi:
219265
keyLayer.reorderLayer("T")
220266
pass
221267
else:
222268
if noteIdx == 0:
223-
keyLayer.drawStr(2, HEIGHT - 15, "C", "blue")
224-
l = WIDTH + octaveOffset * 7 * WIDTH + xOffset
269+
keyLayer.drawStr(2, KEY_HEIGHT - 15, "C", "blue")
270+
l = KEY_WIDTH + octaveOffset * 7 * KEY_WIDTH + xOffset
225271
t = TOP_HEIGHT
226-
w = width + 2 * BORDER
227-
h = height + 2 * BORDER
272+
w = width + 2 * KEY_BORDER
273+
h = height + 2 * KEY_BORDER
228274
keyLayer.pinLayer(l, t, w, h)
229275
return keyLayer
230276

@@ -241,15 +287,15 @@ def feedbackHandler(self, layer, type, x, y):
241287
if layer == self.playLayer:
242288
self.play = not self.play
243289
if self.play:
244-
self.playLayer.backgroundColor("lightgray")
290+
self.playLayer.backgroundColor("lightgreen")
245291
else:
246292
self.playLayer.noBackgroundColor()
247293
elif layer == self.targetLayer:
248294
self.playToSpeaker = not self.playToSpeaker
249295
if self.playToSpeaker:
250-
self.targetLayer.noBackgroundColor()
296+
self.targetLayer.backgroundColor("lightgreen")
251297
else:
252-
self.targetLayer.backgroundColor("lightgray")
298+
self.targetLayer.noBackgroundColor()
253299
elif layer == self.restartLayer:
254300
self.restart = True
255301
else:

samples/run_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

33
if __name__ == "__main__":
4-
#import melody.main
5-
import graphical.main
4+
import melody.main
5+
#import graphical.main
66
#import doodle.main

0 commit comments

Comments
 (0)