From e72ef10f76fd8236f2f8559e88b7b952094be550 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 15 Dec 2020 13:12:06 -0800 Subject: [PATCH 1/2] Add light sensor to peripherals --- adafruit_magtag/peripherals.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/adafruit_magtag/peripherals.py b/adafruit_magtag/peripherals.py index 75d00a6..46b63b3 100755 --- a/adafruit_magtag/peripherals.py +++ b/adafruit_magtag/peripherals.py @@ -56,6 +56,9 @@ def __init__(self): self._speaker_enable.direction = Direction.OUTPUT self._speaker_enable.value = False + # Battery Voltage + self._light = AnalogIn(board.LIGHT) + # Buttons self.buttons = [] for pin in (board.BUTTON_A, board.BUTTON_B, board.BUTTON_C, board.BUTTON_D): @@ -143,3 +146,11 @@ def any_button_pressed(self): Return whether any button is pressed """ return False in [self.buttons[i].value for i in range(0, 4)] + + @property + def light(self): + """ + Return the value of the light sensor. The neopixel_disable property + must be false to get a value. + """ + return self._light.value From 0bf242cb565bc4a116463434715242638dfe72af Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 15 Dec 2020 15:11:06 -0700 Subject: [PATCH 2/2] Update adafruit_magtag/peripherals.py with example Co-authored-by: Kattni --- adafruit_magtag/peripherals.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/adafruit_magtag/peripherals.py b/adafruit_magtag/peripherals.py index 46b63b3..bedca2c 100755 --- a/adafruit_magtag/peripherals.py +++ b/adafruit_magtag/peripherals.py @@ -152,5 +152,15 @@ def light(self): """ Return the value of the light sensor. The neopixel_disable property must be false to get a value. + .. code-block:: python + + import time + from adafruit_magtag.magtag import MagTag + + magtag = MagTag() + + while True: + print(magtag.peripherals.light) + time.sleep(0.01) """ return self._light.value