Esempio n. 1
0
# Set up where we'll be fetching data from
DATA_SOURCE = ("https://api.twitter.com/1.1/statuses/user_timeline.json?"
               "screen_name=%s&count=1&tweet_mode=extended" % TWITTER_USERNAME)
TWEET_TEXT = [0, "full_text"]
TWEET_FULL_NAME = [0, "user", "name"]
TWEET_HANDLE = [0, "user", "screen_name"]

magtag = MagTag(url=DATA_SOURCE,
                json_path=(TWEET_FULL_NAME, TWEET_HANDLE, TWEET_TEXT))
# Set Twitter OAuth2.0 Bearer Token
bearer_token = secrets["twitter_bearer_token"]
magtag.set_headers({"Authorization": "Bearer " + bearer_token})

# Display setup
magtag.set_background("/images/background.bmp")

# Twitter name
magtag.add_text(
    text_position=(70, 10),
    text_font="/fonts/Arial-Bold-12.pcf",
)

# Twitter handle (@username)
magtag.add_text(
    text_position=(70, 30),
    text_font="/fonts/Arial-12.bdf",
    text_transform=lambda x: "@%s" % x,
)

# Tweet text
Esempio n. 2
0
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise


def get_config():
    print(json.dumps(config))
    #magtag.set_text("config['openweather_token']",0,False) #index


get_config()

PLAINFONT = config['plainfont']  # Use built in font if True

magtag.peripherals.neopixel_disable = config[
    'neopixels_disable']  # turn on lights
magtag.set_background(0xFFFFFF)  # set to white background
if config['backgroundfile'] is not "":
    magtag.set_background(config['backgroundfile'])
magtag.peripherals.neopixels.fill(0x000000)  # red!
#magtag.refresh()

if config['mode'] is 'local':
    verses = json.loads(open("verses.json").read())
    print("using local verses.")
else:
    verses = webverse.json()
    print("using web verses")
    print('.......................................................')
    print(json.dumps(verses))
    print('.......................................................')
# main text large font, used to display script index 0 during dev.
Esempio n. 3
0
SHOW_INTRO = False   # Whether to show the digikey logo + intro text
PLAY_SONG = False    # shhhh!
DEFAULT_SIGN = None  # Set to None to pick, or "Scorpio" (etc) to skip
SHOW_SIGN_IMAGE = True # skip showing the name of the sign/graphic
PLAINFONT = False     # Use built in font if True
# if we have wifi, we'll get a horoscope online!
DATA_SOURCE = "https://aztro.sameerkumar.website/?day=today&sign="

magtag = MagTag()

# lights up fast
magtag.peripherals.neopixels.brightness = 0.1
magtag.peripherals.neopixel_disable = False # turn on lights
if SHOW_INTRO:
    magtag.set_background("digikey.bmp")
    magtag.peripherals.neopixels.fill(0x800000) # red!
    magtag.refresh()
    print("Thank you Digi-Key!")

signs = (("Aquarius", (0, 0, 255)), # blue
         ("Pisces", (144, 240, 144)), # light green
         ("Aries", (255, 0, 0)), # red
         ("Taurus", (0, 255, 0)), # green
         ("Gemini", (128, 128, 0)), # yellow
         ("Cancer", (128, 128, 128)), # white
         ("Leo", (255, 215, 0)), # gold
         ("Virgo", (82, 111, 53)), # dark green
         ("Libra", (255,192,203)), # pink
         ("Scorpio", 0), # black!
         ("Sagittarius", (128,0,128)), # purple
                      stripCometSpeed,
                      cometColorC,
                      tail_length=stripCometTailLen),
            ))),
    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)
            font_event,
            x=88,
            y=40 + (event_idx * 35),
            color=0x000000,
            text=event_name,
            line_spacing=0.65,
        )
        magtag.splash.append(label_event_desc)


# Create a new MagTag object
magtag = MagTag()
r = rtc.RTC()

# DisplayIO Setup
magtag.set_background(0xFFFFFF)

# Add the header
line_header = Line(0, 30, 320, 30, color=0x000000)
magtag.splash.append(line_header)

font_h1 = bitmap_font.load_font("fonts/Arial-18.pcf")
label_header = label.Label(font_h1, x=5, y=15, color=0x000000, max_glyphs=30)
magtag.splash.append(label_header)

# Set up calendar event fonts
font_event = bitmap_font.load_font("fonts/Arial-12.pcf")

if not google_auth.refresh_access_token():
    raise RuntimeError(
        "Unable to refresh access token - has the token been revoked?")
Esempio n. 6
0
# SPDX-License-Identifier: Unlicense
import time
import random
import alarm
import terminalio
from adafruit_magtag.magtag import MagTag

# Set up where we'll be fetching data from
DATA_SOURCE = (
    "https://raw.githubusercontent.com/codyogden/killedbygoogle/main/graveyard.json"
)

# Get the MagTag ready
MAGTAG = MagTag()
MAGTAG.peripherals.neopixel_disable = True
MAGTAG.set_background("/bmps/background.bmp")
MAGTAG.network.connect()

# Prepare the three text fields
MAGTAG.add_text(
    text_font="/fonts/Deutsch-Gothic-14.bdf",
    text_position=(
        55,
        60,
    ),
    text_wrap=14,
    text_anchor_point=(0.5, 0.5),
    text_scale=1,
    line_spacing=0.9,
    is_data=False,
)
Esempio n. 7
0
import json
import terminalio
from adafruit_magtag.magtag import MagTag


magtag = MagTag()
magtag.peripherals.neopixel_disable = True # turn off lights

magtag.set_background("bmps\magtag_bible.bmp")
verses = json.loads(open("verses.json").read())

# main text, index 0
magtag.add_text(
    text_font = terminalio.FONT if PLAINFONT else "Arial-Bold-24.bdf",
    text_position=(
        magtag.graphics.display.width // 2,
        10,
    ),
    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),
Esempio n. 8
0
    mins = minutes_till_eventstart % 60
    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)
import wifi
import socketpool
import adafruit_requests as requests
from adafruit_magtag.magtag import MagTag

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

# Initialize magtag object
magtag = MagTag()

magtag.set_background("bmps/oshwa_full.bmp")

# Set up WiFi
wifi.radio.connect(secrets["ssid"], secrets["password"])
print(f"Connected to {secrets['ssid']}!")
print("My IP address is", wifi.radio.ipv4_address)

socket = socketpool.SocketPool(wifi.radio)
https = requests.Session(socket, ssl.create_default_context())

# Paste your API token below
TOKEN = "YOUR_API_TOKEN"


def font_width_to_dict(font):
    # Reads the font file to determine how wide each character is
                Comet(strip,
                      strip_comet_speed,
                      comet_two_color,
                      tail_length=strip_comet_tail),
            ),
        ), ),
    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()
Esempio n. 11
0
        magtag.set_text(quizQuestions[WHICH_QUESTION]['parts'], 5, False)
    if SHOW_EXTRA == False:
        magtag.set_text("", 5, False)
    if CORRECT_ANSWER == 1:
        magtag.set_text('A: ' + quizQuestions[WHICH_QUESTION]['answer'], 6,
                        False)
        magtag.set_text('B: ' + wrongAnswer, 7, False)
    if CORRECT_ANSWER == 2:
        magtag.set_text('A: ' + wrongAnswer, 6, False)
        magtag.set_text('B: ' + quizQuestions[WHICH_QUESTION]['answer'], 7,
                        False)
    magtag.refresh()


magtag.peripherals.neopixels.brightness = 0.1
magtag.set_background("background.bmp")
magtag.set_text("STUDIUM\n LENTUM")
magtag.refresh()
if SHOW_LIGHTS == True:
    magtag.peripherals.neopixels.fill(0xFF4500)
if PLAY_SOUNDS == True:
    song = ((262, 2), (262, 2), (349, 6))
    for notepair in song:
        magtag.peripherals.play_tone(notepair[0], notepair[1] * 0.2)
if SHOW_LIGHTS == True:
    time.sleep(0.5)
    magtag.peripherals.neopixels.fill(0xffffff)
else:
    magtag.peripherals.neopixels.fill(0x000000)

Esempio n. 12
0
#	key_invert = False
#
#	pixels = neopixel.NeoPixel(board.NEOPIXEL, 4, brightness=neo_brightness, auto_write=False)
#
#
#	touch1 = touchio.TouchIn(board.TOUCH1)
#	touch2 = touchio.TouchIn(board.TOUCH2)
#el
if os.uname().machine == 'Adafruit MagTag with ESP32S2':
    from adafruit_magtag.magtag import MagTag

    device_type = 1
    key_invert = True  #Magtag keypress .value(s) are inverted; False means pressed, True means released.

    magtag = MagTag()
    magtag.set_background(e_white)

    #pixels = neopixel.NeoPixel(board.NEOPIXEL, 4, brightness=neo_brightness, auto_write=False)
    pixels = magtag.peripherals.neopixels
    magtag.peripherals.neopixel_disable = False

    touch1 = magtag.peripherals.buttons[0]
    touch2 = magtag.peripherals.buttons[1]
    touch3 = magtag.peripherals.buttons[2]
    touch4 = magtag.peripherals.buttons[3]
else:
    print("I don't know how to run on this platform: " + os.uname().machine)
    print("Here are its hardware features: " + str(dir(board)))
    sys.exit(1)

selected_keynum = 0