-
-
Save rtsuk/4dabd9c2902c1634f4202c2490c32790 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries | |
# | |
# SPDX-License-Identifier: Unlicense | |
from adafruit_magtag.magtag import MagTag | |
from adafruit_fakerequests import Fake_Requests | |
from adafruit_datetime import datetime, date, time, timezone, timedelta, tzinfo | |
import board | |
import analogio | |
import alarm | |
import struct | |
# Set up where we'll be fetching data from | |
DATA_SOURCE = "https://magtag-gateway.herokuapp.com/next" | |
#DATA_SOURCE = "http://endling.local:8080/next" | |
DATA_LOCATION = [["top"], ["middle"], ["bottom"], ["bottom"], ["time"]] | |
def battery_value(val): | |
return round(magtag.peripherals.battery,1) | |
magtag = MagTag( | |
url=DATA_SOURCE, | |
json_path=DATA_LOCATION, | |
) | |
magtag.add_text( | |
text_position=( | |
(magtag.graphics.display.width // 2) - 1, | |
15, | |
), | |
text_scale=3, | |
text_anchor_point=(0.5, 0.5), | |
) | |
magtag.add_text( | |
text_position=( | |
(magtag.graphics.display.width // 2) - 1, | |
(magtag.graphics.display.height // 2) - 1, | |
), | |
text_scale=2, | |
text_anchor_point=(0.5, 0.5), | |
) | |
magtag.add_text( | |
text_position=( | |
(magtag.graphics.display.width // 2) - 1, | |
magtag.graphics.display.height - 20, | |
), | |
text_scale=3, | |
text_anchor_point=(0.5, 0.5), | |
) | |
magtag.add_text( | |
text_position=( | |
0, | |
0, | |
), | |
text_scale=1, | |
text_anchor_point=(0.0, 0.0), | |
text_transform=battery_value | |
) | |
magtag.add_text( | |
text_position=( | |
magtag.graphics.display.width, | |
0, | |
), | |
text_scale=1, | |
text_anchor_point=(1.0, 0.0), | |
) | |
try: | |
magtag.network.connect() | |
value = magtag.fetch() | |
print("Response is", value) | |
except (ValueError, RuntimeError, ConnectionError) as e: | |
print("Some error occured, retrying! -", e) | |
except: | |
print("Unexpected error") | |
magtag._text = [] | |
magtag.exit_and_deep_sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment