from machine import Pin
import utime
bar_leds = [Pin(i, Pin.OUT) for i in range(2, 12)]
button = Pin(16, Pin.IN, Pin.PULL_DOWN)
start_time = utime.ticks_ms()
while True:
t = (utime.ticks_diff(utime.ticks_ms(), start_time) / 1000) % 21
velocity = 0.5 * (t**2) - 0.3 * t + 7
acceleration = t - 0.3
if button.value() == 0:
print(f"Time: {t:.1f}s | acceleration: {acceleration:.2f}")
level = int((acceleration / 20) * 10)
if level < 0:
level = 0
if level > 10:
level = 10
for i in range(10):
bar_leds[i].value(1 if i < level else 0)
else:
print(f"Time: {t:.1f}s | velocity: {velocity:.2f}")
level = int((velocity / 200) * 10)
if level < 0:
level = 0
if level > 10:
level = 10
for i in range(10):
bar_leds[i].value(1 if i < level else 0)
utime.sleep(1)