Esempio n. 1
0
    text_position=(MAGTAG.graphics.display.width // 2,
                   MAGTAG.graphics.display.height - 1),
    text_color=0xFFFFFF,
    text_anchor_point=(0.5, 1),  # Center bottom
    is_data=False,  # Text will be set manually
)

# MAIN LOOP ----------------------------------------------------------------

PRIOR_LIST = ''  # Initialize these to nonsense values
PRIOR_DAY = -1  # so the list or day change always triggers on first pass

while True:
    try:
        print('Updating time')
        MAGTAG.get_local_time()
        NOW = rtc.RTC().datetime

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

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

        # 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:
Esempio n. 2
0
magtag = MagTag(debug=True)
magtag.network.connect()

# Corresponds to time.localtime().tm_wday, with corresponding Monday.bmp, etc.
days_of_week = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")

print('we are connected yay')

timestamp = 0
day_of_week = 0

def update_display():
    daystr = days_of_week[ day_of_week ]
    print("update_display:",day_of_week, daystr)
    magtag.set_background("bmps/"+daystr+".bmp")
    magtag.refresh() 
    
    
while True:
    if time.monotonic() - timestamp > 60*60:  # resync time once an hour
        magtag.get_local_time()     # uses adafruit.io 
        timestamp = time.monotonic()
        print("updating!")

        now = time.localtime()
        day_of_week = now.tm_wday
        update_display()
        
    time.sleep(60*30)  # update infrequently
Esempio n. 3
0
#  creating the circles & pulling in positions from spots
for spot in spots:
    circle = Circle(x0=spot[0], y0=spot[1], r=11,
                    fill=ball_color[ball_index])  # Each ball has a color
    ball_index += 1
    ball_index %= len(ball_color)

    #  adding circles to their display group
    circle_group.append(circle)

#  adding circles group to main display group
group.append(circle_group)

#  grabs time from network
magtag.get_local_time()
#  parses time into month, date, etc
now = time.localtime()
month = now[1]
day = now[2]
(hour, minutes, seconds) = now[3:6]
seconds_since_midnight = 60 * (hour * 60 + minutes) + seconds
print(f"day is {day}, ({seconds_since_midnight} seconds since midnight)")

#  sets colors of circles to transparent to reveal dates that have passed & current date
for i in range(day):
    circle_group[i].fill = None
    time.sleep(0.1)

#  updates display with bitmap and current circle colors
magtag.display.show(group)
Esempio n. 4
0
# Color
magtag.add_text(
    text_font="Helvetica-Bold-100.bdf",
    text_position=(
        (magtag.graphics.display.width // 2) - 1,
        (magtag.graphics.display.height // 2) - 1,
    ),
    text_anchor_point=(0.5, 0.5),
)

timestamp = None
last_timestr = None
while True:
    if not timestamp or (time.monotonic() - timestamp > 3600):
        magtag.get_local_time()  # resync time once an hour
        timestamp = time.monotonic()
    now = time.localtime()
    hour = now[3]
    minute = now[4]
    if HOUR_MODE_24:
        timestr = "%d:%02d" % (hour, minute)
    else:
        is_pm = (hour >= 12)
        hour %= 12
        if hour == 0:
            hour = 12
        timestr = "%d:%02d" % (hour, minute)
    if timestr != last_timestr:
        magtag.set_text(timestr)
        last_timestr = timestr