797
In this example we use LEDs connected to the following pins – 16,17,18,19,20,21,22,26,27,28 to create the knight rider effect
I tested this with cytron maker pi pico as it has LEDs connected to all the outputs
Schematic
If you want to build its fairly simple, you just need the pico, 10 LEDs and 10 resistors.
We forgot the resistor and led for pin 28
Parts
RP2040 | Aliexpress |
Electronics Components Basic Starter Kit | Aliexpress |
Code
# Knight Rider LED from machine import Pin import utime #LED Pins to be used LEDs = [16,17,18,19,20,21,22,26,27,28] #create an empty list to assing pins in pico led_pins = [] for x in range(0,10): led_pins.append(Pin(LEDs[x], Pin.OUT, Pin.PULL_UP)) button_fast = Pin(11,Pin.IN, Pin.PULL_DOWN) button_slow = Pin(13,Pin.IN, Pin.PULL_DOWN) while True: # Left to Right # for x in range(len(led_pins)-2): led_pins[x+1].value(1) utime.sleep(0.010) led_pins[x].value(1) utime.sleep(0.010) led_pins[x+1].value(1) utime.sleep(0.010) led_pins[x+2].value(1) utime.sleep(0.010) led_pins[x].value(0) utime.sleep(0.010) led_pins[x+1].value(1) utime.sleep(0.010) led_pins[x+2].value(0) # Left to Right # for x in reversed(range(len(led_pins)-2)): led_pins[x+1].value(1) utime.sleep(0.010) led_pins[x].value(1) utime.sleep(0.010) led_pins[x+1].value(1) utime.sleep(0.010) led_pins[x+2].value(1) utime.sleep(0.010) led_pins[x].value(0) utime.sleep(0.010) led_pins[x+1].value(1) utime.sleep(0.010) led_pins[x+2].value(0)