Skip to content

Commit 78746da

Browse files
committed
Un-nest the try/except blocks and move try/except under if statement
1 parent fa0c95c commit 78746da

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

adafruit_pybadger.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,18 @@ class PyBadger:
8383

8484
def __init__(self, i2c=None):
8585
# Accelerometer
86-
try:
87-
if i2c is None:
86+
if i2c is None:
87+
try:
8888
i2c = board.I2C()
89+
except RuntimeError:
90+
self._accelerometer = None
91+
92+
if i2c is not None:
8993
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
9094
try:
9195
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
9296
except ValueError:
9397
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
94-
except RuntimeError:
95-
self._accelerometer = None
9698

9799
# Buttons
98100
self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),

0 commit comments

Comments
 (0)