Created
September 20, 2019 01:34
-
-
Save aewhite/754d834b17215f45843c6d4bd407429f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from microbit import * | |
import random | |
def buildPattern(length): | |
formatString = '{0:0' + str(length) + 'b}' | |
binaryString = formatString.format(random.getrandbits(length)) | |
letterPattern = ['A' if char == '0' else 'B' for char in binaryString] | |
return letterPattern | |
patternLength = random.randint(3, 5) | |
pattern = buildPattern(patternLength) | |
targetPosition = random.randint(0, patternLength) | |
targetLetter = pattern[targetPosition] | |
fullSequence = pattern + pattern + pattern + pattern[0:targetPosition] | |
displayText = " ".join(fullSequence) + " ?" | |
display.show(displayText, 400) | |
expectedButton = button_a if targetLetter == 'A' else button_b | |
unexpectedButton = button_a if targetLetter == 'B' else button_b | |
while True: | |
if expectedButton.is_pressed(): | |
display.show(Image.HAPPY) | |
break | |
elif unexpectedButton.is_pressed(): | |
display.show(Image.SAD) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment