@@ -94,11 +94,12 @@ def ShowNeoPixels(*pixels):
9494
9595import time
9696
97+ # crate a tab (LayerLcd) to control whether auto advance the pixel's color from the previous pixel to the next pixel
98+ auto_advance_tab = LayerLcd (dd , 12 , 1 )
99+ auto_advance_tab .writeCenteredLine ("Auto Advance" )
100+ auto_advance_tab .enableFeedback ("fl" )
97101
98- auto_advance_button = LayerLcd (dd , 12 , 1 )
99- auto_advance_button .writeCenteredLine ("Auto Advance" )
100- auto_advance_button .enableFeedback ("fl" )
101-
102+ # crate a button (LayerLcd) to manually advance the pixel's color from the previous pixel to the next pixel
102103advance_button = LayerLcd (dd , 3 , 1 )
103104advance_button .border (1 , "blue" , "round" )
104105advance_button .writeCenteredLine (">>>" )
@@ -124,16 +125,15 @@ def ShowNeoPixels(*pixels):
124125b_slider_layer .border (3 , "darkblue" , "round" , 1 )
125126b_slider_layer .colors ("blue" , RGB_COLOR (0x44 , 0x44 , 0xff ), "black" , "darkgray" )
126127
127- # auto "pin" the above layers vertically
128+ # auto "pin" the above layers
128129AutoPin ('V' ,
129- AutoPin ('H' , auto_advance_button , advance_button ),
130- color_layer ,
131- r_slider_layer ,
132- g_slider_layer ,
133- b_slider_layer ).pin (dd )
130+ AutoPin ('H' , auto_advance_tab , advance_button ),
131+ color_layer ,
132+ r_slider_layer ,
133+ g_slider_layer ,
134+ b_slider_layer ).pin (dd )
134135
135136auto_advance = None
136-
137137r = 0
138138g = 0
139139b = 0
@@ -142,29 +142,35 @@ def ShowNeoPixels(*pixels):
142142
143143while True :
144144
145- if auto_advance is None or auto_advance_button .getFeedback ():
145+ if auto_advance is None or auto_advance_tab .getFeedback ():
146+ # if it is not initialized, or if auto advance tab is clicked (has "feedback"), set auto advance accordingly
146147 if auto_advance is None :
147- auto_advance = True
148+ auto_advance = False # initially, manual advance
148149 else :
149150 auto_advance = not auto_advance
151+ # set auto advance tab's border, pixel color and background pixel color according to whether auto advance is on or off
150152 if auto_advance :
151- auto_advance_button .border (1 , "blue" , "round" )
152- auto_advance_button .pixelColor ("red" )
153- auto_advance_button .bgPixelColor ("green" )
153+ auto_advance_tab .border (1 , "blue" , "round" )
154+ auto_advance_tab .pixelColor ("red" )
155+ auto_advance_tab .bgPixelColor ("green" )
154156 advance_button .disabled (True )
155157 else :
156- auto_advance_button .border (1 , "blue" , "hair" )
157- auto_advance_button .pixelColor ("darkgray" )
158- auto_advance_button .bgPixelColor ("gray" )
158+ auto_advance_tab .border (1 , "blue" , "hair" )
159+ auto_advance_tab .pixelColor ("darkgray" )
160+ auto_advance_tab .bgPixelColor ("gray" )
159161 advance_button .disabled (False )
162+
160163 advance = False
161164 if auto_advance :
165+ # check if need to auto advance the colors of the pixels
162166 diff_ms = time .ticks_ms () - last_ms
163167 if diff_ms >= 200 :
168+ # if it has been 200ms, auto advance the colors of the pixels
164169 advance = True
165170 last_ms = time .ticks_ms ()
166171 else :
167172 if advance_button .getFeedback ():
173+ # if advance button is clicked (has "feedback"), advance the colors of the pixels
168174 advance = True
169175
170176 if Pixels :
@@ -190,16 +196,23 @@ def ShowNeoPixels(*pixels):
190196 if fb :
191197 # if there is "feedback" from the B slider, its x position will be the new value for b
192198 b = fb .x
199+
200+ sync_sliders = False
193201 fb : Feedback = color_layer .getFeedback ()
194202 if fb :
203+ # if there is "feedback" from the color layer, its x position will be the new value for r, and its y position will be the new value for g
195204 r = fb .x
196205 g = fb .y
206+ sync_sliders = True
207+
197208 if r != old_r or g != old_g or b != old_b :
198209 # set the background color of the color layer to the new (r, g, b) color
199210 color_layer .backgroundColor (RGB_COLOR (r , g , b ))
200- if r != old_r :
201- r_slider_layer .moveToPos (r , 0 )
202- if g != old_g :
203- g_slider_layer .moveToPos (g , 0 )
204- if b != old_b :
205- b_slider_layer .moveToPos (b , 0 )
211+ if sync_sliders :
212+ # check to see if RGB needs to be synced with the sliders
213+ if r != old_r :
214+ r_slider_layer .moveToPos (r , 0 )
215+ if g != old_g :
216+ g_slider_layer .moveToPos (g , 0 )
217+ if b != old_b :
218+ b_slider_layer .moveToPos (b , 0 )
0 commit comments