Skip to content

Set pixels brightness; recall display brightness setting in auto dim mode #11

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 3 commits into from
Dec 6, 2019
Merged
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
10 changes: 6 additions & 4 deletions adafruit_pybadger.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PyBadger:
BUTTON_A = const(2)
BUTTON_B = const(1)

def __init__(self, i2c=None):
def __init__(self, i2c=None, *, pixels_brightness=1.0):
# Accelerometer
if i2c is None:
try:
Expand All @@ -103,6 +103,7 @@ def __init__(self, i2c=None):

# Display
self.display = board.DISPLAY
self._display_brightness = 1.0

# Light sensor
self._light_sensor = analogio.AnalogIn(board.A7)
Expand All @@ -116,7 +117,7 @@ def __init__(self, i2c=None):
# Count is hardcoded - should be based on board ID, currently no board info for PyBadge LC
neopixel_count = 5
self._neopixels = neopixel.NeoPixel(board.NEOPIXEL, neopixel_count,
pixel_order=neopixel.GRB)
brightness=pixels_brightness, pixel_order=neopixel.GRB)

# Auto dim display based on movement
self._last_accelerometer = None
Expand Down Expand Up @@ -154,7 +155,7 @@ def auto_dim_display(self, delay=5.0, movement_threshold=10):
self.display.brightness = 0.1
self._start_time = current_time
else:
self.display.brightness = 1
self.display.brightness = self._display_brightness

@property
def pixels(self):
Expand Down Expand Up @@ -206,7 +207,7 @@ def light(self):

@property
def acceleration(self):
"""Accelerometer data."""
"""Accelerometer data, +/- 2G sensitivity."""
return self._accelerometer.acceleration if self._accelerometer is not None else None

@property
Expand All @@ -216,6 +217,7 @@ def brightness(self):

@brightness.setter
def brightness(self, value):
self._display_brightness = value
self.display.brightness = value

# pylint: disable=too-many-locals
Expand Down