from machine import Pin
from time import sleep
gpio=[0,1,2,3,4,5,6,7] #list of the number of gpio pins used for leds
led= len(gpio) # the number of the used leds pins
leds=[0]* led # list to save the declaration of leds pins
p_b= Pin(17, Pin.IN , Pin.PULL_DOWN) # decleration of push button
for i in range(led):
leds[i]= Pin(gpio[i], Pin.OUT) # a loop used to declare the leds pins
free= False # a flag to check if the button was bushed
while True:
if p_b.value() == 0:
for n in range (led): # a loop used for running lights when the push button is not pressed
leds[n].value(1)
sleep(0.2)
leds[n].value(0)
if p_b.value() == 1: # to reverse the order if button was pushed after this loop
free= True
if free == True:
for n in range (led-1,-1,-1): # a loop used for running lights when the push button is pressed
leds[n].value(1)
sleep(0.2)
leds[n].value(0)
free= False