Newbie Led sequential blink
Posted: Sun Oct 14, 2018 12:01 pm
Hi at all, my name's Marcello from italy, i'm looking for example hot to blink sequential led with my pyboard.
This is my code but i don' t understand how. I would like whhen i press the button sled's start blink in sequential an then when i press again led's blink off.
Thanks for your support!
# main.py -- put your code here!
import time
from pyb import Pin
# OUTPUT PINS - LEDs
led1 = Pin('Y1', Pin.OUT_PP)
led2 = Pin('Y3', Pin.OUT_PP)
led3 = Pin('Y4', Pin.OUT_PP)
led4 = Pin('Y5', Pin.OUT_PP)
button = Pin('Y2', Pin.IN)
def leds():
led1.high()
time.sleep(0.1)
#led1.low()
led2.high()
time.sleep(0.1)
led3.high()
time.sleep(0.1)
led4.high()
time.sleep(0.1)
led1.low()
time.sleep(0.1)
led2.low()
time.sleep(0.1)
led3.low()
time.sleep(0.1)
led4.low()
time.sleep(0.1)
print (button.value())
def ledsOff():
led1.low()
led2.low()
led3.low()
led4.low()
while True:
if button.value() == 1 :
leds()
elif button.value() == 0:
ledsOff()
This is my code but i don' t understand how. I would like whhen i press the button sled's start blink in sequential an then when i press again led's blink off.
Thanks for your support!
# main.py -- put your code here!
import time
from pyb import Pin
# OUTPUT PINS - LEDs
led1 = Pin('Y1', Pin.OUT_PP)
led2 = Pin('Y3', Pin.OUT_PP)
led3 = Pin('Y4', Pin.OUT_PP)
led4 = Pin('Y5', Pin.OUT_PP)
button = Pin('Y2', Pin.IN)
def leds():
led1.high()
time.sleep(0.1)
#led1.low()
led2.high()
time.sleep(0.1)
led3.high()
time.sleep(0.1)
led4.high()
time.sleep(0.1)
led1.low()
time.sleep(0.1)
led2.low()
time.sleep(0.1)
led3.low()
time.sleep(0.1)
led4.low()
time.sleep(0.1)
print (button.value())
def ledsOff():
led1.low()
led2.low()
led3.low()
led4.low()
while True:
if button.value() == 1 :
leds()
elif button.value() == 0:
ledsOff()