Skip to content
Snippets Groups Projects
Commit 556a5cb1 authored by mzxs1g21's avatar mzxs1g21
Browse files

Upload New File

parent bc223512
No related branches found
No related tags found
No related merge requests found
import machine
import neopixel
import random
import time
# Assign buttons and LED
button_pins = [20, 21, 22] # Pins for buttons 1, 2, and 3 respectively
# Set up buttons as inputs with pull-down resistors
for pin in button_pins:
machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_DOWN)
np = neopixel.NeoPixel(machine.Pin(28), 1)
np[0] = (0,0,0) # Initially set the led to nothing
np.write()
# Blinks the LED green once
def blink_green():
np[0] = (0,0,0)
np.write()
time.sleep_ms(500)
np[0] = (0,255,0)
np.write()
time.sleep_ms(500)
# Blinks the LED red once
def blink_red():
np[0] = (0,0,0)
np.write()
time.sleep_ms(500)
np[0] = (255,0,0)
np.write()
time.sleep_ms(500)
# Blinks the LED blue once
def blink_blue():
np[0] = (0,0,0)
np.write()
time.sleep_ms(500)
np[0] = (0,0,255)
np.write()
time.sleep_ms(500)
# Logic to generate random a sequence of random length of nummbers from 0,1,2 (Create list of numbers called sequence)
for button in sequence:
if button == 0:
blink_red()
elif button == 1:
blink_green()
elif button == 2:
blink_blue()
np[0] = (0,0,0)
np.write()
button_presses = [] # List to record button inputs
while len(button_presses) < rep:
# Logic to check each button to see if it's been pressed and append number to list
if sequence == button_presses:
# Code to signify correct inputs (LED lighting)
else:
# Code to signify incorreect inputs (LED lighting)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment