Skip to content

Commit 0e34313

Browse files
authored
Merge pull request #337 from jedgarpark/magic-nine-ball-fix
Magic nine ball fix
2 parents 29adbbc + 44f19e5 commit 0e34313

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Magic_Nine_Ball/magic_nine_ball.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
board.DISPLAY.show(splash)
1717

1818
max_brightness = 2 ** 15
19+
SENSITIVITY = 5 # reading in Z direction to trigger, adjustable
1920

2021
images = list(filter(lambda x: x.endswith("bmp"), os.listdir("/")))
2122

22-
i = random.randint(0, 19) # initial image is randomly selected
23+
i = random.randint(0, (len(images)-1)) # initial image is randomly selected
2324

2425
# Set up accelerometer on I2C bus, 4G range:
2526
I2C = busio.I2C(board.SCL, board.SDA)
@@ -52,11 +53,11 @@
5253
# Wait forever
5354
while not shaken:
5455
try:
55-
ACCEL_X, ACCEL_Y, ACCEL_Z = ACCEL.acceleration # Read the accelerometer
56+
ACCEL_Z = ACCEL.acceleration[2] # Read Z axis acceleration
5657
except IOError:
5758
pass
5859
# print(ACCEL_Z) # uncomment to see the accelerometer z reading
59-
if ACCEL_Z > 5:
60+
if ACCEL_Z > SENSITIVITY:
6061
shaken = True
6162

6263
# Fade down the backlight
@@ -66,8 +67,7 @@
6667

6768
splash.pop()
6869

69-
if ACCEL_Z > 5:
70-
i = random.randint(0, 19) # initial image is randomly selected
71-
print("shaken")
72-
faceup = False
70+
i = random.randint(0, (len(images)-1)) # pick a new random image
71+
# print("shaken")
72+
faceup = False
7373
i %= len(images) - 1

0 commit comments

Comments
 (0)