from machine import Pin
import utime
led1 = Pin(2, Pin.OUT)
led2 = Pin(3, Pin.OUT)
led3 = Pin(4, Pin.OUT)
led4 = Pin(5, Pin.OUT)
led5 = Pin(6, Pin.OUT)
led6 = Pin(7, Pin.OUT)
led7 = Pin(8, Pin.OUT)
led8 = Pin(9, Pin.OUT)
led9 = Pin(10, Pin.OUT)
led10 = Pin(11, Pin.OUT)
bar = [led1, led2, led3, led4, led5, led6, led7, led8, led9, led10]
button = Pin(14, Pin.IN, Pin.PULL_UP)
t = 0
show_velocity = True
last_btn_val = 1
while t <= 20:
if button.value() == 0 and last_btn_val == 1:
show_velocity = not show_velocity
utime.sleep(0.2)
last_btn_val = button.value()
v = (0.5 * t**2) - (0.3 * t) + 7
a = (1.0 * t) - 0.3
if show_velocity == True:
value = v
max_val = 201
print("Time:", t, "Mode: Velocity", "Val:", v)
else:
value = a
max_val = 20
print("Time:", t, "Mode: Acceleration", "Val:", a)
num_on = int((value / max_val) * 10)
for i in range(10):
if i < num_on:
bar[i].on()
else:
bar[i].off()
t = t + 1
utime.sleep(0.5)
print("Exit")