1+ import time
2+
3+
14NUM_PIXELS = 4
25NEO_PIXELS_IN_PIN = 22
36
47try :
58
6- import time
79 import rp2
810 from machine import Pin
911
@@ -71,6 +73,7 @@ def ShowNeoPixels(*pixels):
7173
7274
7375from dumbdisplay .core import *
76+ from dumbdisplay .layer_lcd import *
7477from dumbdisplay .layer_graphical import *
7578from dumbdisplay .layer_joystick import *
7679
@@ -92,6 +95,15 @@ def ShowNeoPixels(*pixels):
9295import 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
96108color_layer = LayerGraphical (dd , 150 , 101 )
97109color_layer .border (5 , "black" , "round" , 2 )
@@ -112,7 +124,14 @@ def ShowNeoPixels(*pixels):
112124b_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
117136r = 0
118137g = 0
@@ -121,14 +140,39 @@ def ShowNeoPixels(*pixels):
121140last_ms = time .ticks_ms ()
122141
123142while 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