Skip to content

Instantly share code, notes, and snippets.

@jackleonard
Last active March 17, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackleonard/7b333899713bb6e7a0558ecc9c7dc70b to your computer and use it in GitHub Desktop.
Save jackleonard/7b333899713bb6e7a0558ecc9c7dc70b to your computer and use it in GitHub Desktop.
Quick and Dirty implementation of simple question and answer game using circuit playground as feedback. Built to experiment neopixel control and animation with circuitplayground.
"""This is a simple 4 question game example highlighting use of circuitplaygrounds neopixels"""
from adafruit_circuitplayground import cp
import math
import time
green = (0, 200, 0)
red = (200, 0, 0)
purple = (150, 0, 100)
blue = (0, 0, 200)
correct = (255, 255, 255)
answer1 = "donald trump"
answer2 = "covid 19"
answer3 = "angela merkel"
answer4 = "xi jingping"
score = 0
print("works")
while True:
print("works")
def lightReact(whatIsIt, userinput):
print("********")
print(whatIsIt)
print(userinput)
global score
if userinput == answer1 or userinput == answer2 or userinput == answer3 or userinput == answer4:
whatIsIt = True
else:
whatIsIt = False
if whatIsIt is False:
cp.pixels.fill(red)
cp.pixels.brightness = 1.0
time.sleep(0.4)
cp.pixels.brightness = 0.0
time.sleep(0.4)
cp.pixels.brightness = 1.0
time.sleep(0.4)
cp.pixels.brightness = 0.0
time.sleep(0.6)
else:
score += 1
print("****** CORRECT ******")
print("You scored %d/4" % score)
cp.pixels.fill(green)
cp.pixels.brightness = 1.0
time.sleep(0.4)
cp.pixels.brightness = 0.0
time.sleep(0.4)
cp.pixels.brightness = 1.0
time.sleep(0.4)
cp.pixels.brightness = 0.0
time.sleep(0.6)
def countDown():
cp.pixels.brightness = 0.1
cp.pixels.fill(correct)
global score
# score based proportionality light
if score != 0:
print("1")
cp.pixels.brightness = float((score/3 * 1)/10)
time.sleep(0.1)
print("2")
cp.pixels.brightness = float((score/3 * 2)/10)
time.sleep(0.1)
print("3")
cp.pixels.brightness = float((score/3 * 3)/10)
time.sleep(0.1)
print("Go")
cp.pixels.brightness = float((score/3 * 4)/10)
time.sleep(0.1)
else:
print("1")
cp.pixels.brightness = 0.3
time.sleep(0.5)
print("2")
cp.pixels.brightness = 0.6
time.sleep(0.5)
print("3")
cp.pixels.brightness = 0.9
time.sleep(0.5)
print("Go")
cp.pixels.brightness = score/5
time.sleep(0.8)
whatIsIt = True
countDown()
# for question 1
print("Who is the current US President?")
userinput = input()
lightReact(whatIsIt, userinput)
countDown()
# for question 2
print("What is the current outbreak?")
userinput = input()
lightReact(whatIsIt, userinput)
countDown()
# for question 3
print("What is the name of the german chancellor?")
userinput = input()
lightReact(whatIsIt, userinput)
countDown()
# for question 4
print("What is the name of the chinese prime minister?")
userinput = input()
lightReact(whatIsIt, userinput)
countDown()
time.sleep(1.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment