Skip to content

Commit cf1c955

Browse files
authored
Update magic_nine_ball.py
added code to except IOError
1 parent 1283ea4 commit cf1c955

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Magic_Nine_Ball/magic_nine_ball.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Set up accelerometer on I2C bus, 4G range:
2525
I2C = busio.I2C(board.SCL, board.SDA)
2626

27-
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) # Production board
27+
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18)
2828

2929
ACCEL.range = adafruit_lis3dh.RANGE_4_G
3030

@@ -51,8 +51,10 @@
5151

5252
# Wait forever
5353
while not shaken:
54-
ACCEL_X, ACCEL_Y, ACCEL_Z = ACCEL.acceleration # Read the accel-z
55-
time.sleep(0.001)
54+
try:
55+
ACCEL_X, ACCEL_Y, ACCEL_Z = ACCEL.acceleration # Read the accelerometer
56+
except IOError:
57+
pass
5658
# print(ACCEL_Z) # uncomment to see the accelerometer z reading
5759
if ACCEL_Z > 5:
5860
shaken = True

0 commit comments

Comments
 (0)