Skip to content

Remove Accelerometer Init for PyBadge LC #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 23, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions adafruit_pybadger.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@ class PyBadger:

def __init__(self, i2c=None):
# Accelerometer
if i2c is None:
i2c = board.I2C()
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
try:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
if i2c is None:
i2c = board.I2C()
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
except RuntimeError:
self._accelerometer = None

if i2c is not None:
try:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)
except ValueError:
self._accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

# Buttons
self._buttons = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK),
Expand Down Expand Up @@ -202,7 +207,10 @@ def light(self):
@property
def acceleration(self):
"""Accelerometer data."""
return self._accelerometer.acceleration
acceleration = None
if self._accelerometer is not None:
acceleration = self._accelerometer.acceleration
return acceleration

@property
def brightness(self):
Expand Down