Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP2215 - Colour sequence game
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mzxs1g21
COMP2215 - Colour sequence game
Commits
556a5cb1
"clmctest/git@git.soton.ac.uk:flame/flame-clmc.git" did not exist on "0605d6d3df64caa9fafa3dc2311551ce15292abd"
Commit
556a5cb1
authored
2 years ago
by
mzxs1g21
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
bc223512
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Colour_sequence_skeleton.py
+67
-0
67 additions, 0 deletions
Colour_sequence_skeleton.py
with
67 additions
and
0 deletions
Colour_sequence_skeleton.py
0 → 100644
+
67
−
0
View file @
556a5cb1
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)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment