from machine import Pin
import time
import random
import neopixel
#Cheat detect:
fail = False
#Neopixel:
NumLeds = 24
leds = neopixel.NeoPixel(Pin(16, Pin.OUT), NumLeds)
#All leds green:
for i in range(NumLeds):
leds[i] = [0, 255, 0]
leds.write()
#Button setup:
butt = Pin(5, Pin.IN, Pin.PULL_UP)
#Time setup:
delay = random.randint(2, 4)
passedTime = 0
#Delay in turning the LEDs red:
while passedTime <= delay:
time.sleep(0.2)
passedTime += 0.2
#User tries to cheat:
if butt.value() == 0:
print("You are a faliure")
fail = True
#Set all LEDs red:
for i in range(NumLeds):
leds[i] = [255, 0, 0]
leds.write()
#Time shenanigans:
StartTime = time.time_ns()
while True:
#Button is pressed:
if butt.value() == 0:
InputTime = time.time_ns()
break
#Results of experiment:
print(f"You did it in {(InputTime-StartTime)/1000000} milliseconds!")
if fail:
print("You cheated, cheater!")
print("Cheater,")
print("Cheater,")
print("Wifey")
print("Beater")