Skip to content

Commit d293080

Browse files
authored
Merge pull request #41 from makermelissa/main
Add light sensor to peripherals
2 parents c62f549 + 0bf242c commit d293080

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

adafruit_magtag/peripherals.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def __init__(self):
5656
self._speaker_enable.direction = Direction.OUTPUT
5757
self._speaker_enable.value = False
5858

59+
# Battery Voltage
60+
self._light = AnalogIn(board.LIGHT)
61+
5962
# Buttons
6063
self.buttons = []
6164
for pin in (board.BUTTON_A, board.BUTTON_B, board.BUTTON_C, board.BUTTON_D):
@@ -143,3 +146,21 @@ def any_button_pressed(self):
143146
Return whether any button is pressed
144147
"""
145148
return False in [self.buttons[i].value for i in range(0, 4)]
149+
150+
@property
151+
def light(self):
152+
"""
153+
Return the value of the light sensor. The neopixel_disable property
154+
must be false to get a value.
155+
.. code-block:: python
156+
157+
import time
158+
from adafruit_magtag.magtag import MagTag
159+
160+
magtag = MagTag()
161+
162+
while True:
163+
print(magtag.peripherals.light)
164+
time.sleep(0.01)
165+
"""
166+
return self._light.value

0 commit comments

Comments
 (0)