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 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
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._brightness_value = 1.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a value for display brightness. Can we name it something like _display_brightness so it doesn't get confused with neopixel brightness? It makes reading the code a bit easier. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea. I'll make the change.


# 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._brightness_value

@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._brightness_value = value
self.display.brightness = value

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