File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ from microbit import *
2+ from random import randrange
3+
4+ # Define left, stay still and right
5+ directions = ["L" , "O" , "R" ]
6+ points = 0
7+
8+ # While the micro:bit is on
9+ while True :
10+ # Pick a random direction
11+ direction = directions [randrange (3 )]
12+ display .show (direction )
13+ # Sleep for a second (1000ms)
14+ sleep (1000 )
15+
16+ # Get the X-axis (left-right) tilt
17+ acc_x = accelerometer .get_x ()
18+ # Determine direction
19+ if acc_x < - 200 :
20+ user_in = "L"
21+ elif abs (acc_x ) < 200 :
22+ user_in = "O"
23+ elif acc_x > 200 :
24+ user_in = "R"
25+
26+ # Check win condition
27+ if user_in == direction :
28+ # User input correctly
29+ points += 1
30+ else :
31+ display .scroll (points )
32+ display .show (Image .SAD )
33+ points = 0
34+ sleep (1000 )
You can’t perform that action at this time.
0 commit comments