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

Upload New File

parents
No related branches found
No related tags found
No related merge requests found
from machine import Pin
import random
import time
import neopixel
np = neopixel.NeoPixel(machine.Pin(28), 1)
np[0] = (0,0,0) # Initially set the led to nothing
np.write()
button1 = Pin(20, Pin.IN, Pin.PULL_DOWN)
button2 = Pin(21, Pin.IN, Pin.PULL_DOWN)
button3 = Pin(22, Pin.IN, Pin.PULL_DOWN)
def get_guess():
guess = 1
while True:
if button1.value() == 0:
# Logic to increment guess by 1 and print it (also implement error handling for guess being > 10)
if button2.value() == 0:
guess -= 1
# Logic to decrement guess by 1 and print it (also implement error handling for guess being < 1)
if button3.value() == 0:
print("Submitting guess...")
return guess
def get_result(guess, answer):
# If statements to assign colour of LED depending on how far guess is from answer (distacnce up to individual, 4 colours)
def play_game():
answer = random.randint(1, 10)
print("Guess a number between 1 and 10!")
while True:
guess = get_guess()
result = get_result(guess, answer)
if result == "green":
# Actions taken if guess is the same as answer
elif result == "yellow":
# Actions taken if guess is quite close to answer
elif result == "orange":
# Actions taken if guess is somewhat close to answer
elif result == "red":
# Actions taken if guess is far from answer
play_game()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment