DATA_SOURCE = "https://api.github.com/repos/adafruit/circuitpython" STARS_COUNT = ["stargazers_count"] REPO_NAME = ["full_name"] # the current working directory (where this file is) cwd = ("/" + __file__).rsplit("/", 1)[0] pyportal = PyPortal( url=DATA_SOURCE, json_path=(REPO_NAME, STARS_COUNT), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/bgs/terminal.bmp", text_font=cwd + "/fonts/Helvetica-Bold-24.bdf", text_position=((20, 160), (20, 280)), # quote location # author location text_color=(0xFFFFFF, 0xF291C7), # quote text color # author text color text_wrap=(30, 0), # characters to wrap for quote # no wrap for author text_maxlen=(180, 30), # max text size for quote & author debug=True, ) # speed up projects with lots of text by preloading the font! pyportal.preload_font() while True: try: value = pyportal.fetch() print("Response is", value) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) time.sleep(60)
if CURRENCY == 'USD': return "$%d" % val if CURRENCY == 'EUR': return "€%d" % val if CURRENCY == 'GBP': return "£%d" % val return "%d" % val # the current working directory (where this file is) cwd = ("/" + __file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/bitcoin_background.bmp", text_font=cwd + "/fonts/Arial-Bold-24-Complete.bdf", text_position=(195, 130), text_color=0x0, text_transform=text_transform) pyportal.preload_font(b'$012345789') # preload numbers pyportal.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol while True: try: value = pyportal.fetch() print("Response is", value) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) time.sleep(3 * 60) # wait 3 minutes
reveal_text_area.text = "Player 2!" break time.sleep(0.05) # debounce delay else: # Timer runs out q_text_area.text = '' reveal_text_area.text = "Times up!" # PyPortal constructor pyportal = PyPortal(url=DATA_SOURCE, json_path=(Q_LOCATION, CA_LOCATION, WA_LOCATION1, WA_LOCATION2, WA_LOCATION3), status_neopixel=board.NEOPIXEL, default_bg=cwd + "/trivia_title.bmp") pyportal.preload_font() # speed things up by preloading font pyportal.splash.append(loading_text_area) #loading... pyportal.splash.append(q_text_area) pyportal.splash.append(reveal_text_area) pyportal.splash.append(timer_text_area) for textarea in ans_text_areas: pyportal.splash.append(textarea) while True: # Load new question when screen is touched while not pyportal.touchscreen.touch_point: pass reveal_text_area.text = '' q_text_area.text = ''
def text_transform(val): format_str = "{:,.2f} Bitcoins\n = {:,d}" if CURRENCY == 'USD': format_str = "{:,.2f} Bitcoins\n = %{:,d}" if CURRENCY == 'EUR': format_str = "{:,.2f} Bitcoins\n = €{:,d}" if CURRENCY == 'GBP': format_str = "{:,.2f} Bitcoins\n = £{:,d}" return format_str.format(NUM_BITCOINS, int(val*NUM_BITCOINS)) # the current working directory (where this file is) cwd = ("/"+__file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd+"/bitcoin_background.bmp", text_font=cwd+"/fonts/Arial-BoldItalic-12-Complete.bdf", text_position=(195, 95), text_color=0x0, text_transform=text_transform) pyportal.preload_font() # preload alphanums pyportal.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol while True: try: value = pyportal.fetch() print("Response is", value) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) time.sleep(3*60) # wait 3 minutes
# # E.g. "New York, US" or "London, GB" # set to your local the tide predition STATION from the NOAA tide prediction site STATION = "8441241" # Set up a placeholder for DATA_SOURCE that we will update later on DATA_SOURCE = " " DATA_LOCATION = [] # Initialize the pyportal object and set the tides background pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd + "/tides.bmp") pyportal.preload_font() big_font = bitmap_font.load_font(cwd + "/fonts/Arial-Bold-24-Complete.bdf") little_font = bitmap_font.load_font(cwd + "/fonts/Arial-Bold-12.bdf") pyportal.preload_font( b'0123456789fallingrising') # pre-load glyphs for fast printing directionp = (100, 195) high1p = (25, 25) low1p = (25, 85) high2p = (210, 25) low2p = (210, 85) high1t = (25, 50) low1t = (25, 110) high2t = (210, 50) low2t = (210, 110) currentp = (120, 165)
import board from adafruit_pyportal import PyPortal # Set up where we'll be fetching data from DATA_SOURCE = "http://tspann-MBP15-HW14277:8080/nifi-api/flow/status" DATA_LOCATION = ["controllerStatus", "flowFilesQueued"] def text_transform(val): format_str = "FlowFilesQueued in NiFi = {:d}" return format_str.format(val) # the current working directory (where this file is) cwd = ("/"+__file__).rsplit('/', 1)[0] pyportal = PyPortal(url=DATA_SOURCE, json_path=DATA_LOCATION, status_neopixel=board.NEOPIXEL, default_bg=cwd+"/quote_background.bmp", text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf", text_position=(20, 20), text_color=0xFFFFFF, text_transform=text_transform) pyportal.preload_font(b'$012345789') # preload numbers while True: try: value = pyportal.fetch() except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) time.sleep(60) #
json_path=(BG_VALUE, BG_DIRECTION), status_neopixel=board.NEOPIXEL, default_bg=0xFFFFFF, text_font=cwd + "/fonts/Arial-Bold-24-Complete.bdf", text_position=( (90, 120), # VALUE location (140, 160)), # DIRECTION location text_color=( 0x000000, # sugar text color 0x000000), # direction text color text_wrap=( 35, # characters to wrap for sugar 0), # no wrap for direction text_maxlen=(180, 30), # max text size for sugar & direction text_transform=(text_transform_bg, text_transform_direction), ) # speed up projects with lots of text by preloading the font! pyportal.preload_font(b'mg/dl012345789') pyportal.preload_font((0x2191, 0x2192, 0x2193)) #pyportal.preload_font() while True: try: value = pyportal.fetch() pyportal.set_background(get_bg_color(value[0])) print("Response is", value) except RuntimeError as e: print("Some error occured, retrying! -", e) time.sleep(180)
default_bg=CWD+"/latest_tweet_bkg.bmp", text_font=CWD+"/fonts/PressStart2P-10.bdf", #text_* variables need to be lists if we're passing > 1 json paths text_position=[(30, 120),(30, 220),(280, 220)], text_color=[0xFFFFFF,0xF32E6D, 0x3ABD20], text_wrap = [28,0,0], text_maxlen = [240,10,10], caption_text="Latest tweet from @"+ TWITTER_NAME, caption_font=CWD+"/fonts/Collegiate-24.bdf", caption_position=(25, 20), caption_color=0xFFFFFF, esp = esp32, #Pre defined the esp32 object before pyportal so we could do twitter handshake passed_spi = spi, ) pyportal.preload_font() #preload font to speed up processing # track the last value so we can play a sound when it updates pyportal_tweet = '' followers_count = 0 num_likes = 0 num_rt = 0 while True: #Reset Flags before we check to see if the values changed updated_tweet = False retweet_update = False favorite_update = False #Call Twitter's get function with our get headers that now include the Bearer token required