import machine
import neopixel
import time
# LED Strip Configuration
num_leds = 15 # Number of LEDs in the strip
pin_led = machine.Pin(18, machine.Pin.OUT)
led_strip = neopixel.NeoPixel(pin_led, num_leds)
# Score Animation Function
def score(points):
# Check if victory animation should be played
if points > 15:
play_victory_animation()
else:
play_score_animation(points)
# Show score for 20 seconds
show_score(points, 20)
# Turn off the station
turn_off_station()
# Function to play the victory animation
def play_victory_animation():
for i in range(num_leds):
led_strip[i] = (0, 255, 0) # Set LED color to green
led_strip.write()
time.sleep(0.2)
# Function to play the score animation
def play_score_animation(points):
for i in range(points):
led_strip[i] = (255, 0, 0) # Set LED color to red
led_strip.write()
time.sleep(0.2)
# Function to show the score
def show_score(points, duration):
for _ in range(duration):
led_strip.fill((0, 0, 0)) # Turn off all LEDs
for i in range(points):
led_strip[i] = (255, 0, 0) # Set LED color to red
led_strip.write()
time.sleep(1)
# Function to turn off the station
def turn_off_station():
led_strip.fill((0, 0, 0)) # Turn off all LEDs
led_strip.write()
# Example usage
score(10) # Call the score function with the number of points