Exemple #1
0
    def __init__(self, magtag: MagTag) -> None:
        self._magtag = magtag

        magtag.add_text(
            text_position=(
                50,
                10,
            ),
            text_scale=3,
        )

        magtag.set_text("Spotlight")
Exemple #2
0
line_spacing = 14
if len(contest_str) > 23 or len(deadline_str) > 23:
    text_font = '/fonts/Arial-12.bdf'
    line_spacing = 12

# Text at index 0, contest name
magtag.add_text(
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        (magtag.graphics.display.height // 2) - 1 - line_spacing,
    ),
    text_font=text_font,
    text_anchor_point=(0.5, 0.5),
)

# Text at index 1, days till deadline
magtag.add_text(
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        (magtag.graphics.display.height // 2) - 1 + line_spacing,
    ),
    text_font=text_font,
    text_anchor_point=(0.5, 0.5),
)

contests.next_contest()
magtag.set_text(contest_str, auto_refresh=False)
magtag.set_text(deadline_str, 1)

magtag.exit_and_deep_sleep(10)
Exemple #3
0
        # tm_wday uses 0-6 for Mon-Sun, we want 1-7 for Sun-Sat
        COLUMN = (NOW.tm_wday + 1) % 7 + 1

        TASK_LIST = ''  # Clear task list string
        for entry in ENTRIES:
            cell = entry['gs$cell']
            if int(cell['row']) > 1 and int(cell['col']) is COLUMN:
                TASK_LIST += cell['$t'] + '\n'  # Task + newline character

        # Refreshing the display is jarring, so only do it if the task list
        # or day has changed. This requires preserving state between passes,
        # and is why this code doesn't deep sleep (which is like a reset).
        if TASK_LIST != PRIOR_LIST or PRIOR_DAY != NOW.tm_wday:

            # Set the day-of-week label at top
            MAGTAG.set_text(DAYS[COLUMN - 1], auto_refresh=False)

            # Set the "Updated" date and time label
            if DD_MM:
                DATE = '%d/%d' % (NOW.tm_mday, NOW.tm_mon)
            else:
                DATE = '%d/%d' % (NOW.tm_mon, NOW.tm_mday)
            MAGTAG.set_text('Updated %s %s' % (DATE, hh_mm(NOW, TWELVE_HOUR)),
                            2,
                            auto_refresh=False)

            MAGTAG.set_text(TASK_LIST, 1)  # Update list, refresh display
            PRIOR_LIST = TASK_LIST  # Save list state for next pass
            PRIOR_DAY = NOW.tm_wday  # Save day-of-week for next pass

    except RuntimeError as error:
#
# SPDX-License-Identifier: Unlicense
import time
from adafruit_magtag.magtag import MagTag

magtag = MagTag()

magtag.add_text(
    text_position=(
        50,
        (magtag.graphics.display.height // 2) - 1,
    ),
    text_scale=3,
)

magtag.set_text("Hello World")

button_colors = ((255, 0, 0), (255, 150, 0), (0, 255, 255), (180, 0, 255))
button_tones = (1047, 1318, 1568, 2093)

while True:
    for i, b in enumerate(magtag.peripherals.buttons):
        if not b.value:
            print("Button %c pressed" % chr((ord("A") + i)))
            magtag.peripherals.neopixel_disable = False
            magtag.peripherals.neopixels.fill(button_colors[i])
            magtag.peripherals.play_tone(button_tones[i], 0.25)
            break
    else:
        magtag.peripherals.neopixel_disable = True
    time.sleep(0.01)
Exemple #5
0
    text_maxlen=60,
    text_anchor_point=(0, 0),
)
# small horoscope text, index 6
magtag.add_text(
    text_font= terminalio.FONT if PLAINFONT else "Arial-12.bdf",
    text_position=(10, 10),
    line_spacing=1.0,
    text_wrap=35,
    text_maxlen=130,
    text_anchor_point=(0, 0),
)

if SHOW_INTRO:
    magtag.set_background(0xFFFFFF)    # set to white background
    magtag.set_text("Welcome to\nADABOX 017") # let me introduce myself
    if PLAY_SONG:
        song = ((330, 1), (370, 1), (392, 2), (370, 2), (330, 2), (330, 1),
                (370, 1), (392, 1), (494, 1), (370, 1), (392, 1), (330, 2))
        for notepair in song:
            magtag.peripherals.play_tone(notepair[0], notepair[1] * 0.2)

try:
    magtag.network.connect()
except (ConnectionError) as e:
    print(e)
    print("Continuing without WiFi")

# initial instructions
selection = None
Exemple #6
0
    NOW = rtc.RTC().datetime
    print(NOW)

    print('Updating names')
    RESPONSE = MAGTAG.network.fetch(JSON_URL)
    if RESPONSE.status_code == 200:
        JSON_DATA = RESPONSE.json()
        print('OK')

    # Set the "Updated" date and time label
    if DD_MM:
        DATE = '%d/%d' % (NOW.tm_mday, NOW.tm_mon)
    else:
        DATE = '%d/%d' % (NOW.tm_mon, NOW.tm_mday)
    MAGTAG.set_text('Updated %s %s' % (DATE, hh_mm(NOW, TWELVE_HOUR)),
                    1,
                    auto_refresh=False)

    ENTRIES = JSON_DATA['feed']['entry']  # List of cell data

    # Scan cells in row #1 to find the column number for naughty vs nice.
    # This allows the order of columns in the spreadsheet to be changed,
    # though they still must have a "Naughty" or "Nice" heading at top.
    for entry in ENTRIES:
        cell = entry['gs$cell']
        if int(cell['row']) is 1:  # Only look at top row
            head = cell['$t'].lower()  # Case-insensitive compare
            if ((NICE and head == 'nice') or (not NICE and head == 'naughty')):
                NAME_COLUMN = int(cell['col'])

    # Now that we know which column number contains the names we want,
Exemple #7
0
)

top_lbl_txt = "CircuitPython"
magtag.add_text(
    text_font="fonts/leaguespartan18.bdf",
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        16,
    ),
    text_scale=1,
    text_transform=text_transform,
    text_anchor_point=(0.5, 0.5),
    is_data=False,
)

magtag.set_text(bottom_lbl_txt, index=1)
magtag.set_text(top_lbl_txt, index=2)
# set progress bar width and height relative to board's display
BAR_WIDTH = magtag.graphics.display.width - 80
BAR_HEIGHT = 30

BAR_X = magtag.graphics.display.width // 2 - BAR_WIDTH // 2
BAR_Y = 66

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(BAR_X,
                           BAR_Y,
                           BAR_WIDTH,
                           BAR_HEIGHT,
                           1.0,
                           bar_color=0x999999,
Exemple #8
0
import time
import terminalio
from adafruit_magtag.magtag import MagTag

magtag = MagTag()
magtag.peripherals.neopixel_disable = False

magtag.add_text(
    text_font=terminalio.FONT,
    text_position=(140, 55),
    text_scale=7,
    text_anchor_point=(0.5, 0.5),
)

magtag.set_text("00:00")


# Function that makes the neopixels display the seconds left
def update_neopixels(seconds):
    n = seconds // 15
    for j in range(n):
        magtag.peripherals.neopixels[3 - j] = (128, 0, 0)
    magtag.peripherals.neopixels[3 - n] = (int(
        ((seconds / 15) % 1) * 128), 0, 0)


alarm_set = False
while True:
    if not alarm_set:
        # Set the timer to 1 minute
Exemple #9
0
from adafruit_magtag.magtag import MagTag
import re
DATA_SOURCE = "http://192.168.1.34:5000/select?first=1&subscription=%5B%22reading%20list%20%24%20is%20%24title%20%24%20%24%22%5D"
magtag = MagTag(url=DATA_SOURCE)
magtag.network.connect()
magtag.add_text(
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        (magtag.graphics.display.height // 2) - 1,
    ),
    text_scale=3,
    text_anchor_point=(0.5, 0.5),
    is_data=False,
)
try:
    value = magtag.fetch()
    print("Response is", value)
    title = re.search(r"title\":\"(.+)\"", value).group(1)
    magtag.set_text("Read\n" + title, 0)
except (ValueError, RuntimeError) as e:
    print("Some error occured, retrying! -", e)
magtag.exit_and_deep_sleep(60)
Exemple #10
0
CYAN = 0x0088BB
MAGENTA = 0x9900BB
WHITE = 0x888888

blink(WHITE, 0.3)

# pylint: disable=no-member
magtag.add_text(
    text_font=terminalio.FONT,
    text_position=(
        5,
        (magtag.graphics.display.height // 2) - 1,
    ),
    text_scale=3,
)
magtag.set_text("MagTag Slideshow")
time.sleep(5)
magtag.add_text(
    text_font=terminalio.FONT,
    text_position=(3, 120),
    text_scale=1,
)
magtag.set_text("  back        mute      pause/play     fwd", 1)
time.sleep(8)

timestamp = time.monotonic()
sound_toggle = True  # state of sound feedback
autoplay_toggle = True  # state of autoplay
auto_pause = 60  # time between slides in auto mode

# Create the slideshow object that plays through alphabetically.
    text_scale=1,
    line_spacing=0.7,
    text_anchor_point=(0, 0),
)

magtag.add_text(
    text_font="fonts/ArialMT-9.bdf",
    text_position=(5, 38),
    text_scale=1,
    line_spacing=0.6,
    text_anchor_point=(0, 0),
)

# Create the QR code
url = f"https://certification.oshwa.org/{selected['oshwaUid'].lower()}.html"
magtag.graphics.qrcode(url, qr_size=4, x=173, y=3)

# Prepare to wrap the text correctly by getting the width of each character for every font
arial_12 = font_width_to_dict("fonts/Arial-Bold-12.bdf")
arial_9 = font_width_to_dict("fonts/ArialMT-9.bdf")

# Set the text. On some characters, this fails. If so, run the whole file again in 5 seconds
try:
    magtag.set_text(wrap(selected["projectName"], 545, 2, arial_12), 0, False)
    magtag.set_text(wrap(selected["projectDescription"], 530, 19, arial_9), 1)
    magtag.exit_and_deep_sleep(3600)
except Exception:  # pylint: disable=broad-except
    print("Could not set title or description: unsupported glyphs.")
    print("Trying again in 10 seconds.")
    magtag.exit_and_deep_sleep(10)
    line_spacing=0.85,
    text_anchor_point=(0.5, 0.5),
)

# Set up buttons
cur_btn = False
prev_btn = False

while True:
    # Shuffle the deck
    cards = sorted(cards, key=lambda _: random.random())
    for card in cards:

        # Show the first side and wait for the D button
        text = ''.join(magtag.wrap_nicely(card[0], 20))
        magtag.set_text(text)
        while True:
            cur_btn = magtag.peripherals.button_d_pressed
            if cur_btn and not prev_btn:
                print("Show Result")
                time.sleep(0.1)
                break
            prev_btn = cur_btn

        # Show the second side and wait for the D button
        text = '\n'.join(magtag.wrap_nicely(card[1], 11))
        text += '\n'
        text += '\n'.join(magtag.wrap_nicely(card[2], 20))
        print(text)
        magtag.set_text(text)
        while True:
Exemple #13
0
    )

    # Bottom Menu Upper
    magtag.add_text(
        text_position=(1, magtag.graphics.display.height - 18),
        text_scale=1,
    )

    num_text_boxes = 6
    #################

    #################
    # Main menu selection
    activities = Activity()
    magtag.set_text(activities.button_text("ABCs", "Songs", "Colors",
                                           "Shapes"),
                    index=1,
                    auto_refresh=False)
    magtag.set_text("Select an Activity", index=4, auto_refresh=True)
    current_activity = None

    while current_activity is None:
        for i, b in enumerate(magtag.peripherals.buttons):
            if not b.value:
                if i == 0:
                    current_activity = abc.ABC()
                elif i == 1:
                    current_activity = songs.Songs()
                elif i == 2:
                    current_activity = colors.Colors()
                elif i == 3:
                    current_activity = shapes.Shapes()
Exemple #14
0
    data = json.load(fp)
chap_list = list(data.keys())
num_chap = len(chap_list)
list_len = min(num_chap, MAX_LLEN)

# Print list of chapters
for i in range(list_len):
    magtag.add_text(
        text_font=terminalio.FONT,
        text_position=(10, 3 + (i * 10)),
        line_spacing=1.0,
        text_anchor_point=(0, 0),  # Top left
        is_data=False,  # Text will be set manually
    )
    if i == 0:
        magtag.set_text("> " + chap_list[i], i, auto_refresh=False)
    else:
        magtag.set_text("  " + chap_list[i], i, auto_refresh=False)

# Add button labels at the bottom of the screen
BUTTON_TEXT_IDX = list_len
magtag.graphics.splash.append(
    Rect(0,
         magtag.graphics.display.height - 14,
         magtag.graphics.display.width,
         magtag.graphics.display.height,
         fill=0x0))
magtag.add_text(
    text_font=terminalio.FONT,
    text_position=(3, magtag.graphics.display.height - 14),
    text_color=0xFFFFFF,
            ),
        ), ),
    AnimationGroup(
        # Turn the LEDs off.
        Solid(pixels, 0),
        Solid(strip, 0),
    ),
    auto_clear=True,
)

# Set the background image.
magtag.set_background("/adaflake.bmp")

# Add lines of text including button labels.
magtag.add_text(text_color=0xFFFFFF, text_position=(0, 10), text_scale=2)
magtag.set_text("Button functions:")
magtag.add_text(text_color=0xFFFFFF, text_position=(0, 65))
magtag.set_text(
    " Button A: Color Cycle\n"
    " Button B: Sparkle\n"
    " Button C: Comet\n"
    " Button D: LEDs off",
    index=1)
magtag.add_text(text_color=0xFFFFFF, text_position=(0, 120))
magtag.set_text("    A           B           C           D", index=2)
magtag.refresh()

# Main loop.
while True:
    if magtag.peripherals.button_a_pressed:
        animations.activate(0)
Exemple #16
0
    text_scale = 3 if PLAINFONT else 1,
    line_spacing=1,
    text_anchor_point=(0.5, 0),
)

# verse text, index 1
magtag.add_text(
    text_font= terminalio.FONT if PLAINFONT else "Arial-12.bdf",
    text_position=(10, 10),
    line_spacing=1.0,
    text_wrap=35,
    text_maxlen=130,
    text_anchor_point=(0, 0),
)

#reference text, index 2
# button labels, add all 4 in one loop
magtag.add_text(
        text_font = terminalio.FONT if PLAINFONT else "Arial-12.bdf",
        text_position=(150, 110),
        line_spacing=1.0,
        text_anchor_point=(0, 1),
)

#set verse txt
magtag.set_test("Hello World",0,False)
magtag.set_text((verses)["Text"], 1)

Ref = (verses)["Book"] + " " + (verses)["Chapter"] + ":" + (versus)["Verse"]

magtag.set_text((Ref, 2, False)
            ))),
    AnimationGroup(Solid(boardPixels, WHITE), Solid(stripPixels, AMBER)),
    AnimationGroup(
        Solid(boardPixels, AMBER),
        Solid(stripPixels, 0),
    ),
    auto_clear=True,
)

###   Background & Text   ###
# Draws the background image and static text

magtag.set_background("/led.bmp")

magtag.add_text(text_color=0x000000, text_position=(5, 10), text_scale=2)
magtag.set_text("Light Selector:", auto_refresh=False)

magtag.add_text(text_color=0x000000, text_position=(25, 65))
magtag.set_text("A: Rainbow Cycle\n"
                "B: Comet\n"
                "C: Amber\n"
                "D: Dim",
                index=1,
                auto_refresh=False)

magtag.add_text(text_color=0x000000, text_position=(0, 120))
magtag.set_text("    A           B           C           D", index=2)

magtag.add_text(text_color=0x000000, text_position=(250, 10))
magtag.set_text("{} V".format("-4.20"), index=3)
Exemple #18
0

try:
    table = magtag.fetch().split("\n")
    columns = l_split(table[0])
    latest = l_split(table[-2])
    print(columns)
    print(latest)
    value = dict(zip(columns, latest))
    print("Response is", value)
    print(value)

    vaccinated = int(value["people_vaccinated"]) / 331984513
    fully_vaccinated = int(value["people_fully_vaccinated"]) / 331984513

    magtag.set_text(f"{value['location']} Vaccination Rates", 0, False)
    magtag.set_text(value["date"], 1, False)
    magtag.set_text("Vaccinated: {:.2f}%".format(vaccinated * 100), 2, False)
    magtag.set_text("Fully Vaccinated: {:.2f}%".format(fully_vaccinated * 100),
                    3, False)

    progress_bar.progress = vaccinated
    progress_bar_1.progress = fully_vaccinated

    magtag.refresh()

    SECONDS_TO_SLEEP = 24 * 60 * 60  # Sleep for one day

except (ValueError, RuntimeError) as e:
    print("Some error occured, retrying in one hour! -", e)
    seconds_to_sleep = 60 * 60  # Sleep for one hour
weekdays = ("mon", "tue", "wed", "thur", "fri", "sat", "sun")
last_sync = None
last_minute = None

magtag = MagTag()

magtag.graphics.set_background("/background.bmp")

mid_x = magtag.graphics.display.width // 2 - 1
magtag.add_text(
    text_font="Lato-Regular-74.bdf",
    text_position=(mid_x, 10),
    text_anchor_point=(0.5, 0),
    is_data=False,
)
magtag.set_text("00:00a", auto_refresh=False)

magtag.add_text(
    text_font="/BebasNeueRegular-41.bdf",
    text_position=(126, 86),  #was 141
    text_anchor_point=(0, 0),
    is_data=False,
)
magtag.set_text("DAY 00:00a", index=1, auto_refresh=False)


def hh_mm(time_struct, twelve_hour=True):
    """ Given a time.struct_time, return a string as H:MM or HH:MM, either
        12- or 24-hour style depending on twelve_hour flag.
    """
    postfix = ""
Exemple #20
0
    print(event["name"], "starts in", days, "days", hrs, "hours and", mins,
          "minutes\n")

    remaining_starttimes.append(minutes_till_eventstart)
    remaining_endtimes.append(minutes_till_eventend)

mins_till_next_eventstart = min(remaining_starttimes)
mins_till_next_eventend = min(remaining_endtimes)
next_up = events[remaining_starttimes.index(mins_till_next_eventstart)]

# OK find the one with the smallest minutes remaining
sleep_time = None
if current_event:
    print("Currently: ", current_event)
    magtag.set_background("bmps/" + current_event["graphic"])
    magtag.set_text("Currently streaming until " +
                    time_format(current_event["end_time"]))
    remaining_starttimes.index(mins_till_next_eventstart)
    if BEEP_ON_EVENTSTART:
        for _ in range(3):
            magtag.peripherals.play_tone(1760, 0.1)
            time.sleep(0.2)
    sleep_time = mins_till_next_eventend + 1
else:
    print("Next up! ", next_up)
    magtag.set_background("bmps/" + next_up["graphic"])

    string = ("Coming up on " + next_up["day_of_week"] + " at " +
              time_format(next_up["start_time"]))
    magtag.set_text(string)
    sleep_time = mins_till_next_eventstart
Exemple #21
0
magtag.add_text(
    text_font="fonts/leaguespartan11.bdf",
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        (magtag.graphics.display.height) - 8,
    ),
    text_anchor_point=(0.5, 1.0),
)

magtag.graphics.splash.append(dose1_ny_progress_bar)
magtag.graphics.splash.append(dose1_us_progress_bar)
magtag.graphics.splash.append(dose2_ny_progress_bar)
magtag.graphics.splash.append(dose2_us_progress_bar)
response = requests.get(endpoint)

magtag.set_text(f"Population Vaccinated", index=0, auto_refresh=False)

Date = ""

for location in response.json()["vaccination_data"]:
    if location["Location"] == "US" or location["Location"] == "NY":
        Location = location["Location"]

        if Date == "":
            Date = location["Date"]
        elif Date != location["Date"]:
            Date = Date + " & " + location["Date"]

        Administered_Dose1_Pop_Pct = location["Administered_Dose1_Pop_Pct"]
        Administered_Dose2_Pop_Pct = location["Administered_Dose2_Pop_Pct"]
Exemple #22
0

def format_percent(a, b):
    return round(a / b * 100, 1)

def add_text(x, y):
    magtag.add_text(
        text_font="Arial-12.bdf",
        text_position=(x, y),
        is_data=False
    )


# Iowa Info
add_text(5, 10)
magtag.set_text('Iowa', 0, False)
add_text(5, 40)
add_text(5, 60)
add_text(5, 80)

# Des Moines Info
add_text(140, 10)
magtag.set_text('Des Moines County', 4, False)
add_text(145, 40)
add_text(145, 55)
add_text(145, 70)
add_text(145, 85)
add_text(145, 100)

magtag.peripherals.neopixels.brightness = 0.1
magtag.peripherals.neopixels.disable = False
Exemple #23
0
tsl = TSL2591(board.I2C())

# We'll connect this MagTag to the internet if we need to use Adafruit IO connectivity.
# device.network.connect()

device.add_text(
    text_font=terminalio.FONT,
    text_position=(
        10,
        (device.graphics.display.height // 2) - 1,
    ),
    text_scale=1,
)

device.set_text(
    "Select a mode:\na. CO2 and Temperature\nb. Humidity\nc.Infrared Light\nd.Visible Light\nWant to start over? Press Reset to go back."
)

buttons = device.peripherals.buttons

while True:

    # When button A is pressed, then show CO2 and temperature
    if device.peripherals.button_a_pressed:
        co2 = scd.CO2
        temperature = scd.temperature
        print("Current CO2: {:.2f}".format(co2))
        print("Current Temperature: {:.2f}".format(temperature))
        device.set_text(
            'Current CO2: {:.2f} ppm\nCurrent Temperature: {:.2f} C'.format(
                co2, temperature))
Exemple #24
0
        # Get the response and turn it into json
        RESPONSE = MAGTAG.network.requests.get(DATA_SOURCE)
        VALUE = RESPONSE.json()

        # Choose a random project to display
        PROJECT = VALUE[random.randint(0, len(VALUE) - 1)]

        # Prepare the text to be displayed
        CLOSED = PROJECT["dateClose"].split("-")
        CLOSED.reverse()
        CLOSED = "/".join(CLOSED)

        print(PROJECT["name"])

        # Display the text
        MAGTAG.set_text(PROJECT["name"], 0, False)
        MAGTAG.set_text(CLOSED, 1, False)
        MAGTAG.set_text(PROJECT["description"], 2)

        # Play a song
        for notepair in SONG:
            MAGTAG.peripherals.play_tone(notepair[0], notepair[1] * 0.2)

        # Put the board to sleep for an hour
        time.sleep(2)
        print("Sleeping")
        PAUSE = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 60 * 60)
        alarm.exit_and_deep_sleep_until_alarms(PAUSE)

    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
Exemple #25
0
def details_transform(val3):
    if val3 == None or not len(val3):
        return "Details: To Be Determined"
    return "Details: " + val3[0:166] + "..."


# Set up the MagTag with the JSON data parameters
magtag = MagTag(url=DATA_SOURCE,
                json_path=(NAME_LOCATION, DATE_LOCATION, DETAIL_LOCATION))

magtag.add_text(text_font="/fonts/Lato-Bold-ltd-25.bdf",
                text_position=(10, 15),
                is_data=False)
# Display heading text below with formatting above
magtag.set_text("Next SpaceX Launch")

# Formatting for the mission text
magtag.add_text(text_font="/fonts/Arial-Bold-12.pcf",
                text_position=(10, 38),
                text_transform=mission_transform)

# Formatting for the launch time text
magtag.add_text(text_font="/fonts/Arial-12.bdf",
                text_position=(10, 60),
                text_transform=time_transform)

# Formatting for the details text
magtag.add_text(
    text_font=terminalio.FONT,
    text_position=(10, 94),
    return 365


magtag = MagTag()
magtag.network.connect()

magtag.add_text(
    text_font="/fonts/epilogue18.bdf",
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        24,
    ),
    text_anchor_point=(0.5, 0.5),
    is_data=False,
)
magtag.set_text("Year Progress:", auto_refresh=False)

magtag.add_text(
    text_font="/fonts/epilogue18.bdf",
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        55,
    ),
    text_anchor_point=(0.5, 0.5),
    is_data=False,
)

# set progress bar width and height relative to board's display
BAR_WIDTH = magtag.graphics.display.width - 80
BAR_HEIGHT = 30
Exemple #27
0
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.bdf",
    text_wrap=28,
    text_maxlen=120,
    text_position=(
        (magtag.graphics.display.width // 2),
        (magtag.graphics.display.height // 2) - 10,
    ),
    line_spacing=0.75,
    text_anchor_point=(0.5, 0.5),  # center the text on x & y
)

# author in italic text, no wrapping
magtag.add_text(
    text_font="/fonts/Arial-Italic-12.bdf",
    text_position=(magtag.graphics.display.width // 2, 118),
    text_anchor_point=(0.5, 0.5),  # center it in the nice scrolly thing
)

# OK now we're ready to connect to the network, fetch data and update screen!
try:
    magtag.network.connect()
    value = magtag.fetch()
    print("Response is", value)
except (ValueError, RuntimeError) as e:
    magtag.set_text(e)
    print("Some error occured, retrying later -", e)
# wait 2 seconds for display to complete
time.sleep(2)
magtag.exit_and_deep_sleep(TIME_BETWEEN_REFRESHES)
Exemple #28
0
        return "Details: To Be Determined"
    return "Humidity: " + str(val2)

# Set up the MagTag with the JSON data parameters
magtag = MagTag(
    url=DATA_SOURCE,
    json_path=(reading_time, reading_Temperature, reading_Humidity)
)

magtag.add_text(
    text_font="/fonts/Lato-Bold-ltd-25.bdf",
    text_position=(10, 15),
    is_data=False
)
# Display heading text below with formatting above
magtag.set_text("5th Wheel")

# Formatting for the Time text
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.pcf",
    text_position=(10, 38),
    text_transform=time_transform
)

# Formatting for the Temperature text
magtag.add_text(
    text_font="/fonts/Arial-Bold-12.pcf",
    text_position=(10, 60),
    text_transform=Temperature_transform
)
Exemple #29
0
            minutes = int(timesplit[1])
            seconds = int(float(timesplit[2].split("-")[0]))
            rtc.RTC().datetime = time.struct_time((year, month, mday, hours, minutes, seconds, 0, 0, False))
            lasttimefetch_stamp = time.monotonic()
        except (ValueError, RuntimeError) as e:
            print("Some error occured, retrying! -", e)
            continue

    if not timestamp or (time.monotonic() - timestamp) > 60:  # once a minute
        now = time.localtime()
        print("Current time:", now)
        remaining = time.mktime(event_time) - time.mktime(now)
        print("Time remaining (s):", remaining)
        if remaining < 0:
            print("EVENT TIME")
            magtag.set_text("It's Time\nTo Party!")
            magtag.peripherals.neopixel_disable = False
            while True:  # that's all folks
                magtag.peripherals.neopixels.fill(0xFF0000) # red
                time.sleep(0.25)
                magtag.peripherals.neopixels.fill(0xFFFFFF) # white
                time.sleep(0.25)
                magtag.peripherals.neopixels.fill(0x0000FF) # blue
                time.sleep(0.25)
        secs_remaining = remaining % 60
        remaining //= 60
        mins_remaining = remaining % 60
        remaining //= 60
        hours_remaining = remaining % 24
        remaining //= 24
        days_remaining = remaining
from adafruit_magtag.magtag import MagTag
from secrets import secrets

DATA_SOURCE = 'https://api.openweathermap.org/data/2.5/weather?zip=52601,us&units=imperial&appid=' + \
              secrets['open_weather_key']

magtag = MagTag(url=DATA_SOURCE,
                json_path=(["name"], ["main", "temp"], ["main", "temp_max"],
                           ["main", "temp_min"], ["weather", 0,
                                                  "main"], ["wind", "speed"]))

magtag.add_text(text_position=(5, 10), text_scale=2, is_data=False)

magtag.get_local_time()
now = time.localtime()
magtag.set_text("{}/{}/{} {}:{}".format(*now))

magtag.add_text(text_position=(5, 30), text_scale=2)

magtag.add_text(text_position=(10, 50),
                text_transform=lambda x: "Current: {}F".format(x),
                text_scale=2)

magtag.add_text(text_position=(10, 75),
                text_transform=lambda x: "Max: {}F".format(x),
                text_scale=2)

magtag.add_text(text_position=(120, 75),
                text_transform=lambda x: "Min: {}F".format(x),
                text_scale=2)