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
Show file tree
Hide file tree
Changes from all 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
19 changes: 12 additions & 7 deletions adafruit_pybadger.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ 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)
try:
i2c = board.I2C()
except RuntimeError:
self._accelerometer = None

if i2c is not None:
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)

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

@property
def brightness(self):
Expand Down
2 changes: 1 addition & 1 deletion examples/pybadger_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)

while True:
pybadger.auto_dim_display(delay=10)
pybadger.auto_dim_display(delay=10) # Remove or comment out this line if you have the PyBadge LC
if pybadger.button.a:
pybadger.show_business_card(image_name="Blinka.bmp", name_string="Blinka", name_scale=2,
email_string_one="blinka@", email_string_two="adafruit.com")
Expand Down