Simple test

Ensure your device works with this simple test.

examples/magtag_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4import time
 5from adafruit_magtag.magtag import MagTag
 6
 7magtag = MagTag()
 8
 9magtag.add_text(
10    text_position=(
11        50,
12        (magtag.graphics.display.height // 2) - 1,
13    ),
14    text_scale=3,
15)
16
17magtag.set_text("Hello World")
18
19button_colors = ((255, 0, 0), (255, 150, 0), (0, 255, 255), (180, 0, 255))
20button_tones = (1047, 1318, 1568, 2093)
21
22while True:
23    for i, b in enumerate(magtag.peripherals.buttons):
24        if not b.value:
25            print("Button %c pressed" % chr((ord("A") + i)))
26            magtag.peripherals.neopixel_disable = False
27            magtag.peripherals.neopixels.fill(button_colors[i])
28            magtag.peripherals.play_tone(button_tones[i], 0.25)
29            break
30    else:
31        magtag.peripherals.neopixel_disable = True
32    time.sleep(0.01)

Other Demos

examples/magtag_bitcoin_demo.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4from adafruit_magtag.magtag import MagTag
 5
 6# Set up where we'll be fetching data from
 7DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
 8DATA_LOCATION = ["bpi", "USD", "rate_float"]
 9
10
11def text_transform(val):
12    return "Bitcoin: $%d" % val
13
14
15magtag = MagTag(
16    url=DATA_SOURCE,
17    json_path=DATA_LOCATION,
18)
19
20magtag.network.connect()
21
22magtag.add_text(
23    text_position=(
24        (magtag.graphics.display.width // 2) - 1,
25        (magtag.graphics.display.height // 2) - 1,
26    ),
27    text_scale=3,
28    text_transform=text_transform,
29    text_anchor_point=(0.5, 0.5),
30)
31
32try:
33    value = magtag.fetch()
34    print("Response is", value)
35except (ValueError, RuntimeError) as e:
36    print("Some error occured, retrying! -", e)
37magtag.exit_and_deep_sleep(60)