Update magic_nine_ball.py

added code to except IOError
This commit is contained in:
John Edgar Park 2018-09-20 16:37:57 -07:00 committed by GitHub
parent 1283ea4322
commit cf1c955a54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,7 +24,7 @@ i = random.randint(0, 19) # initial image is randomly selected
# Set up accelerometer on I2C bus, 4G range:
I2C = busio.I2C(board.SCL, board.SDA)
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) # Production board
ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18)
ACCEL.range = adafruit_lis3dh.RANGE_4_G
@ -51,8 +51,10 @@ while True:
# Wait forever
while not shaken:
ACCEL_X, ACCEL_Y, ACCEL_Z = ACCEL.acceleration # Read the accel-z
time.sleep(0.001)
try:
ACCEL_X, ACCEL_Y, ACCEL_Z = ACCEL.acceleration # Read the accelerometer
except IOError:
pass
# print(ACCEL_Z) # uncomment to see the accelerometer z reading
if ACCEL_Z > 5:
shaken = True