Skip to content

Commit 68ed5ba

Browse files
committed
going for v0.3.0
1 parent 6a0fd21 commit 68ed5ba

2 files changed

Lines changed: 55 additions & 11 deletions

File tree

dumbdisplay/_ddlayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def flashArea(self, x, y):
106106
self.dd._sendCommand(self.layer_id, "flasharea", str(x), str(y))
107107
# def writeComment(self, comment):
108108
# self.dd.writeComment(comment)
109-
def enableFeedback(self, auto_feedback_method = "fa", feedback_handler = None):
109+
def enableFeedback(self, auto_feedback_method, feedback_handler = None):
110110
'''
111111
rely on getFeedback() being called */
112112
:param auto_feedback_method:

samples/neopixels/main.py

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import time
2+
3+
14
NUM_PIXELS = 4
25
NEO_PIXELS_IN_PIN = 22
36

47
try:
58

6-
import time
79
import rp2
810
from machine import Pin
911

@@ -71,6 +73,7 @@ def ShowNeoPixels(*pixels):
7173

7274

7375
from dumbdisplay.core import *
76+
from dumbdisplay.layer_lcd import *
7477
from dumbdisplay.layer_graphical import *
7578
from dumbdisplay.layer_joystick import *
7679

@@ -92,6 +95,15 @@ def ShowNeoPixels(*pixels):
9295
import time
9396

9497

98+
auto_advance_button = LayerLcd(dd, 12, 1)
99+
auto_advance_button.writeCenteredLine("Auto Advance")
100+
auto_advance_button.enableFeedback("fl")
101+
102+
advance_button = LayerLcd(dd, 3, 1)
103+
advance_button.border(1, "blue", "round")
104+
advance_button.writeCenteredLine(">>>")
105+
advance_button.enableFeedback("fl")
106+
95107
# create a graphical layer (LayerGraphical) to show the color set using the following sliders
96108
color_layer = LayerGraphical(dd, 150, 101)
97109
color_layer.border(5, "black", "round", 2)
@@ -112,7 +124,14 @@ def ShowNeoPixels(*pixels):
112124
b_slider_layer.colors("blue", RGB_COLOR(0x44, 0x44, 0xff), "black", "darkgray")
113125

114126
# auto "pin" the above layers vertically
115-
AutoPin('V').pin(dd)
127+
AutoPin('V',
128+
AutoPin('H', auto_advance_button, advance_button),
129+
color_layer,
130+
r_slider_layer,
131+
g_slider_layer,
132+
b_slider_layer).pin(dd)
133+
134+
auto_advance = None
116135

117136
r = 0
118137
g = 0
@@ -121,14 +140,39 @@ def ShowNeoPixels(*pixels):
121140
last_ms = time.ticks_ms()
122141

123142
while True:
124-
diff_ms = time.ticks_diff(time.ticks_ms(), last_ms)
125-
if diff_ms >= 200:
126-
# shift pixels colors ... the 1st one will then be set to the color of (r, g, b)
127-
for i in range(NUM_PIXELS - 1, 0, -1):
128-
Pixels[i] = Pixels[i - 1]
129-
Pixels[0] = (r, g, b)
130-
ShowNeoPixels(*Pixels)
131-
last_ms = time.ticks_ms()
143+
144+
if auto_advance is None or auto_advance_button.getFeedback():
145+
if auto_advance is None:
146+
auto_advance = True
147+
else:
148+
auto_advance = not auto_advance
149+
if auto_advance:
150+
auto_advance_button.border(1, "blue", "round")
151+
auto_advance_button.pixelColor("red")
152+
auto_advance_button.bgPixelColor("green")
153+
advance_button.disabled(True)
154+
else:
155+
auto_advance_button.border(1, "blue", "hair")
156+
auto_advance_button.pixelColor("darkgray")
157+
auto_advance_button.bgPixelColor("gray")
158+
advance_button.disabled(False)
159+
advance = False
160+
if auto_advance:
161+
diff_ms = time.ticks_ms() - last_ms
162+
if diff_ms >= 200:
163+
advance = True
164+
last_ms = time.ticks_ms()
165+
else:
166+
if advance_button.getFeedback():
167+
advance = True
168+
169+
if Pixels:
170+
if advance:
171+
# shift pixels colors ... the 1st one will then be set to the color of (r, g, b)
172+
for i in range(NUM_PIXELS - 1, 0, -1):
173+
Pixels[i] = Pixels[i - 1]
174+
Pixels[0] = (r, g, b)
175+
ShowNeoPixels(*Pixels)
132176

133177
old_r = r
134178
old_g = g

0 commit comments

Comments
 (0)