Skip to content

Commit 1fd9824

Browse files
authored
Merge pull request #11 from CedarGroveStudios/master
Set pixels brightness; recall display brightness setting in auto dim mode
2 parents be64d07 + 9dd1194 commit 1fd9824

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

adafruit_pybadger.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class PyBadger:
8181
BUTTON_A = const(2)
8282
BUTTON_B = const(1)
8383

84-
def __init__(self, i2c=None):
84+
def __init__(self, i2c=None, *, pixels_brightness=1.0):
8585
# Accelerometer
8686
if i2c is None:
8787
try:
@@ -103,6 +103,7 @@ def __init__(self, i2c=None):
103103

104104
# Display
105105
self.display = board.DISPLAY
106+
self._display_brightness = 1.0
106107

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

121122
# Auto dim display based on movement
122123
self._last_accelerometer = None
@@ -154,7 +155,7 @@ def auto_dim_display(self, delay=5.0, movement_threshold=10):
154155
self.display.brightness = 0.1
155156
self._start_time = current_time
156157
else:
157-
self.display.brightness = 1
158+
self.display.brightness = self._display_brightness
158159

159160
@property
160161
def pixels(self):
@@ -206,7 +207,7 @@ def light(self):
206207

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

212213
@property
@@ -216,6 +217,7 @@ def brightness(self):
216217

217218
@brightness.setter
218219
def brightness(self, value):
220+
self._display_brightness = value
219221
self.display.brightness = value
220222

221223
# pylint: disable=too-many-locals

0 commit comments

Comments
 (0)