Skip to content

Commit c0e9f43

Browse files
committed
First attempts at PyBadge LC fix - Part 2
1 parent 1fea0e2 commit c0e9f43

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adafruit_pybadger.py

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

8484
def __init__(self, i2c=None):
8585
# Accelerometer
86-
if i2c is None:
87-
i2c = board.I2C()
88-
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
8986
try:
90-
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
91-
except ValueError:
92-
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
87+
if i2c is None:
88+
i2c = board.I2C()
89+
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
9390
except RuntimeError:
9491
self._accelerometer = None
9592

93+
if i2c is not None:
94+
try:
95+
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
96+
except ValueError:
97+
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
98+
9699
# Buttons
97100
self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
98101
digitalio.DigitalInOut(board.BUTTON_OUT),

0 commit comments

Comments
 (0)