From 556a5cb1e202c543b12e0f8e0d5aed332f0aa508 Mon Sep 17 00:00:00 2001 From: mzxs1g21 <mzxs1g21@soton.ac.uk> Date: Sun, 14 May 2023 00:54:09 +0000 Subject: [PATCH] Upload New File --- Colour_sequence_skeleton.py | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Colour_sequence_skeleton.py diff --git a/Colour_sequence_skeleton.py b/Colour_sequence_skeleton.py new file mode 100644 index 0000000..469a303 --- /dev/null +++ b/Colour_sequence_skeleton.py @@ -0,0 +1,67 @@ +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) -- GitLab