12_neopixel_led_strip

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
12_neopixel_led_strip [2026/08/02 13:40] – [Knight Rider Lights] walkeradmin12_neopixel_led_strip [2026/08/02 13:48] (current) – [Knight Rider Lights] walkeradmin
Line 514: Line 514:
     chase_bounce((255, 0, 0), 0.08)     chase_bounce((255, 0, 0), 0.08)
 </code> </code>
 +
 +So, what does this extra code do? and how?
 +\\ 
 +\\
 +Here is an explanation of the reverse code block in general.
 +
 +<code:python | download>
 +# Backward direction (move the lit LED from right to left)
 +# range(NUM_LEDS - 2, 0, -1) generates:
 +# For 12 LEDs → 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
 +# - Start at LED 10 (second-to-last)
 +# - Stop at LED 1 (LED 0 is skipped to avoid repeating the end LED)
 +# - Step backwards by -1 each time
 +for i in range(NUM_LEDS - 2, 0, -1):
 +
 +    clear()              # Turn all LEDs off before lighting the next one
 +
 +    np[i] = color        # Light the current LED at position i
 +
 +    np.write()           # Send the updated LED data to the strip
 +
 +    time.sleep(delay)    # Pause so the movement is visible
 +</code>
 +
 +And this is what the line that makes the count to backwards actually does.
 +
 +<code:python | download>
 +range(NUM_LEDS - 2, 0, -1)
 +#Breakdown for NUM_LEDS = 12:
 +
 +Start: NUM_LEDS - 2 → 10
 +#(LED 11 was already lit in the forward chase)
 +
 +Stop: 0 
 +#(but Python stops before 0, so last value is 1)
 +
 +Step: -1
 +#(count backwards)
 +</code>
 +
 +For the reverse sequence, we don't need to worry about the first (0) or last (11) LEDs as these are already set by the forward sequence.
 +\\ 
 +\\ 
 +That's it! Oh, and don't worry, I won't be fitting these to my car :)
 +\\ 
 +\\ 
 +----
12_neopixel_led_strip.1785678039.txt.gz · Last modified: by walkeradmin