def show_text(self, text, duration=2, blink=True): """ show text for the given time """ # should be called with _exec_with_lock self._settings.log.msg("DisplayController: showing text: %s" % text) if self._brightness == 0: time.sleep(duration) return display.clear() # scroll long text if len(text) > 4: steps = len(text) - 3 sleep_time = float(duration) / steps for i in range(steps): display.print_str(text[:4], False) display.show() time.sleep(sleep_time) text = text[1:] else: display.print_str(text, False) if blink: display.set_blink(display.HT16K33_BLINK_2HZ) display.show() time.sleep(duration) if blink: display.set_blink(display.HT16K33_BLINK_OFF)
def display_state(rpi_id, pidi_status_dir): global last_state try: dir_file_list = os.listdir(pidi_status_dir) except FileNotFoundError: flp.scroll_print('ERROR - REMOTE DIR NOT FOUND!') return except PermissionError: flp.scroll_print('ERROR - REMOTE DIR NOT PERMITTED!') return instructions = get_device_instructions(rpi_id, dir_file_list) if not instructions: if last_state is None: flp.scroll_print('ERROR - FILE FOR THIS RASPBERRY NOT FOUND!') return else: instructions = [last_state] if len(instructions) > 1: flp.scroll_print('ERROR - TOO MANY INSTRUCTIONS') return instr = instructions[0] flp.print_str(instr) flp.show() rename_instruction(rpi_id, instr, pidi_status_dir) last_state = instr
def main(): flp.clear() flp.print_str("NSFW") flp.show() print(infotext) print("\nPress Ctrl-C to exit.\n") wait_for_internet_connection() stocks = get_stocks_from_config("stocks.conf") flp.glow(period=0.5, duration=4) flp.clear() flp.show() print("Watching Stocks:") print("\n".join([ sym + ": " + share.get_name() + " (" + str(own) + " owned)" for sym, own, share in stocks ])) while (len(stocks) > 0): show_latest(stocks) print("No stocks...")
def showtime(): global debug global fourchar_flag global fourchar_payload # old logic actually worked, to a point fourchar_flag = False str_time = time.strftime("%H%M") flp.print_number_str(str_time) if int(time.time()) % 2 == 0: flp.set_decimal(1, 1) else: flp.set_decimal(1, 0) flp.show() time.sleep(0.1) # new logic # flp.print_str(" ") # flp.show # float_temp = float(fourchar_payload) # flp.print_float(float_temp, decimal_digits=1, justify_right=True) # flp.show() # time.sleep(2) # old logic if fourchar_flag == True: flp.print_str(" ") flp.show float_temp = float(fourchar_payload) flp.print_float(float_temp, decimal_digits=1, justify_right=True) flp.show() time.sleep(2)
def display_message(titles, numbers, show_title_at_end=False, number_type='str', float_decimal_digits=1, number_sleep=1, title_sleep=.5): """Display messaages with different timings for titles vs numbers.""" for title in titles: flp.clear() flp.print_str(title) flp.show() time.sleep(title_sleep) for number in numbers: flp.clear() flp.print_number_str(str(number)) flp.show() time.sleep(number_sleep) if (show_title_at_end): for title in titles: flp.clear() flp.print_str(title) flp.show() time.sleep(title_sleep)
def show_clock(): str_time = time.strftime("%H%M") fourletterphat.clear() fourletterphat.print_str(str_time) fourletterphat.set_decimal(1, int(time.time() % 2)) fourletterphat.show()
def scroll_message(message): m = " " + message fourletterphat.clear() while len(m) > 3: fourletterphat.print_str(m[:4]) m = m[1:] fourletterphat.show() time.sleep(float(1) / scrolling_speed) time.sleep(seconds_for_panel_display)
def __display_a(self): if self.display_id != self.__display_a: self.display_id = self.__display_a flp.print_str("LOGC") flp.show() time.sleep(2) flp.print_float(self.temp_a, decimal_digits=1) flp.set_blink(flp.HT16K33_BLINK_2HZ) flp.show()
def dprint(s): if len(s) > 4: s = " " + s + " " for i in range(len(s) - 4): flp.print_str(s[i:i + 4]) flp.show() time.sleep(0.25) else: flp.print_str(s) flp.show() return
def _set_time(self): """ set the current time on the display """ # should be called with _exec_with_lock self._settings.log.msg("DisplayController: setting time to: %s" % self._current_time) lights_off = self._settings.get("_lights_off") display.clear() if self._brightness > 0 and not lights_off: t_string = self._current_time.replace(":", "") display.print_str(t_string) display.show()
def __display_f(self): if self.display_id != self.__display_f: flp.set_blink(flp.HT16K33_BLINK_OFF) self.display_id = self.__display_f #flp.scroll_print("FREEZER") flp.print_str("FRZR") flp.show() time.sleep(2) flp.print_float(self.temp_f, decimal_digits=1) flp.show() flp.glow()
def monitor(url): response = requests.get(url) status_code = response.status_code fourletterphat.clear() fourletterphat.print_str(str(status_code)) fourletterphat.show() time.sleep(5) fourletterphat.scroll_print(str(status_code) + ' ' + url + ' ' + str(status_code), 0.1 if (200 == status_code) else 1 ) fourletterphat.print_number_str(str(status_code)) fourletterphat.show() time.sleep(5) fourletterphat.clear()
def alarm_text(self, stop_me, duration=1, text=None, delay=0): """ show running text """ if not text: return duration = int(duration) self._settings.log.msg( "DisplayController: show alarm text '%s' for %s minutes" % (text, duration)) # honor delay delay = int(delay) if delay > 0: self._settings.log.msg( "DisplayController: delaying alarm for %d minutes" % delay) if stop_me.wait(60 * delay): return if simulate: stop_me.wait(60 * duration) self._settings.log.msg( "DisplayController: show alarm text finished") return start_time = time.time() end_time = start_time + 60 * duration now = start_time with self._lock: display.clear() display.set_brightness(15) while now <= end_time: display.print_str(text[:4]) display.show() if stop_me.wait(0.35): break text = text[1:] + text[0] now = time.time() # reset display to standard self._settings.log.msg("DisplayController: show alarm text finished") self.set_time() self.set_brightness()
def dispTemp(): #establish location, if city is two words use and underscore between them #state use two letter abbreviation city = "New_York" state = "NY" #build the url url = "http://api.wunderground.com/api/API_KEY_HERE/conditions/q/" + state + "/" + city + ".json" #request our url f = urllib.request.urlopen(url) #open and read the url json_string = f.read() #encode the url into strings instead of bytes encoding = f.info().get_content_charset('utf-8') #parse the encoded data into something we can use JSON with parsed_json = json.loads(json_string.decode(encoding)) #grabbing specific datum with parsed JSON temp_f = parsed_json['current_observation']['temp_f'] strTemp_f = (str)(temp_f) #FourLetterPhat wasn't printing decimal so we are removing it strippedTemp = strTemp_f.replace(".", "") fourletterphat.clear() #printing what we grabbed fourletterphat.print_str(strippedTemp + "F") #setting the decimal at 1 works for double digit temps/looking into how to get to to lineup for single or triple digit temps fourletterphat.set_decimal(1, True) fourletterphat.show() #closing the url f.close()
def show_latest(stocks): folio = defaultdict(float) # {'USD':'123.45'}, e.g. for symbol, owned, share in stocks: flp.clear() flp.print_str(symbol) flp.show() pstr = symbol try: share.refresh() except Exception as e: time.sleep(0.5) pstr += " $" + share.get_price() + " " + share.get_currency() if (owned > 0): # Append folio info if any stocks owned total = float(share.get_price()) * float(owned) pstr += ", " + str(round(owned, 3)) + " OWNED, VAL $" + str( round(total, 2)) + " " + share.get_currency() folio[share.get_currency()] += total scroll_print_float_str(pstr, interval=0.2) flp.clear() flp.show() time.sleep(1) # If any stocks were owned if (len(folio) > 0): # Print a value for every currency folio_str = " FOLIO VAL" for currency, val in folio.items(): folio_str += " $" + str(round(val, 2)) + " " + currency scroll_print_float_str(folio_str, interval=0.25) flp.clear() flp.show() time.sleep(1)
def date_bin(currdate, currfulldate): firstLetter = ' ' secondLetter = ' ' match = False try: data = openJSON() except: binletters = "{}{}".format(firstLetter, secondLetter) fourletterphat.print_str("{}{}".format(currdate, binletters)) fourletterphat.show() return for i in data: if i['bin'] == 'Grey Bin (General waste)': if i['date'] == currfulldate: firstLetter = 'G' match = True for i in data: if i['bin'] == '240Ltr Green Bin (Recycling)': if i['date'] == currfulldate: secondLetter = 'G' match = True for i in data: if i['bin'] == '240Ltr Brown Bin (Garden waste)': if i['date'] == currfulldate: secondLetter = 'B' match = True binletters = "{}{}".format(firstLetter, secondLetter) fourletterphat.print_str("{}{}".format(currdate, binletters)) if match: binday = True else: binday = False fourletterphat.show()
def cupToPi(data): if data is None: print(data) flp.print_str("BREW") flp.show() flp.glow(period=1, duration=10) else: if data is 0: flp.clear() flp.print_str("0CUP") flp.show() else: num = int(data) if num > 9: flp.print_str(data + "CP") flp.show() else: flp.print_str(data + "CUP") flp.show()
loop = True while loop: site = urllib.request.urlopen('https://xn--vder24-bua.se/malm%C3%B6/') soup = bs.BeautifulSoup(site, 'lxml') first_day = soup.find_all(class_="row main-display") # create empty list temp = [] # find all top temps and append to list for i in first_day: temp_list = i.find(class_='top_temp') temp.append(temp_list.text) # try to set degrees, otherwise continue and restart loop try: degrees = temp[0] + ' C' except: print('Something went wrong') continue # fourletterphat-code flp.clear() flp.print_str(degrees) # degree sign not available in flp flp.show() print(degrees) # print to console, because why not time.sleep(60)
#!/usr/bin/env python import time import fourletterphat as flp spinner = ["|", "/", "-", "/"] while True: for i in range(4): for s in spinner: s = s * 4 flp.clear() flp.print_str(s) flp.show() time.sleep(0.1)
#!/usr/bin/env python3 import scrollphat import fourletterphat from time import sleep weekdays = {0: "Mo", 1: "Tue", 2: "We", 3: "Thu", 4: "Fri", 5: "Sat", 6: "Sun"} for i in range(6): scrollphat.write_string("{}".format(weekdays[i]), 0) sleep(0.5) scrollphat.clear() scrollphat.write_string("***") for i in range(1, 32): fourletterphat.print_str("{} ".format(i)) fourletterphat.show() sleep(0.25) fourletterphat.print_str("{}{}".format(i, 'GG')) fourletterphat.show() sleep(0.25) fourletterphat.print_str("{}{}".format(i, 'GB')) fourletterphat.show() sleep(0.25) fourletterphat.print_str("{}{}".format(i, 'GT')) fourletterphat.show() sleep(0.25)
#!/usr/bin/env python import time import fourletterphat from subprocess import Popen, PIPE print(""" Four Letter pHAT: cpu-temp.py This example will display your Pi's CPU temperature in degrees celsius. Press Ctrl+C to exit. """) while True: # Get temp forom vcgencmd in the format: "temp=XY.Z'C" # and reduce to the format "XYZC" for display temp = Popen(["vcgencmd", "measure_temp"], stdout=PIPE) temp = temp.stdout.read().decode('utf-8') temp = temp[5:].replace(".", "").replace("'", "").strip() fourletterphat.clear() fourletterphat.print_str(temp) fourletterphat.set_decimal(1, 1) fourletterphat.show() time.sleep(1)
#!/usr/bin/env python import time import fourletterphat print(""" Four Letter pHAT: blink.py Demonstrate the display blinking at the three available speeds. Press Ctrl+C to exit. """) fourletterphat.clear() fourletterphat.print_str("BLNK") fourletterphat.show() for blink_speed in [fourletterphat.HT16K33_BLINK_HALFHZ, fourletterphat.HT16K33_BLINK_1HZ, fourletterphat.HT16K33_BLINK_2HZ]: fourletterphat.set_blink(blink_speed) time.sleep(4) fourletterphat.set_blink(fourletterphat.HT16K33_BLINK_OFF) fourletterphat.print_str("BOOM") fourletterphat.show() time.sleep(1)
#!/usr/bin/env python import time import fourletterphat print(""" Four Letter pHAT: scroll.py Scrolls a message across the display. Press Ctrl+C to exit. """) message = "YARR PIRATES " while True: # Display the first four letters of the message fourletterphat.print_str(message[:4]) # Take the first letter (position 0) of the message # and pop it onto the end of the string. message = message[1:] + message[0] fourletterphat.show() time.sleep(0.25)
# End time - number at end (5) is seconds for loading screen (random numbers)$ t_end = time.time() + 5 while time.time() < t_end: flp.clear() flp.set_digit(0, random.choice(numbers)) flp.set_digit(1, random.choice(numbers)) flp.set_digit(2, random.choice(numbers)) flp.set_digit(3, random.choice(numbers)) flp.show() # Sleep for 0.05 seconds before choosing more random numbers time.sleep(0.05) # A bit of fun text before displaying the price flp.clear() flp.print_str("WAIT") flp.show() time.sleep(0.5) flp.clear() flp.print_str("FOR ") flp.show() time.sleep(0.5) flp.clear() flp.print_str("IT ") flp.show() time.sleep(0.5) flp.clear()
#!/usr/bin/python import time import fourletterphat as flp while True: flp.print_str(time.strftime("%I%M")) amp = time.strftime("%p") if amp == "AM": flp.set_decimal(1, 0) else: flp.set_decimal(1, 1) flp.show() time.sleep(0.1)
#!/usr/bin/env python import time import fourletterphat as flp print(""" Four Letter pHAT: blink.py Demonstrate the display blinking at the three available speeds. Press Ctrl+C to exit. """) flp.clear() flp.print_str("BLNK") flp.show() # Display each blinkt speed for 4 seconds for blink_speed in [ flp.HT16K33_BLINK_HALFHZ, flp.HT16K33_BLINK_1HZ, flp.HT16K33_BLINK_2HZ ]: flp.set_blink(blink_speed) time.sleep(4) flp.set_blink(flp.HT16K33_BLINK_OFF) flp.print_str("BOOM") flp.show() time.sleep(1)(10)
#!/usr/bin/env python import time import fourletterphat print(""" Four Letter pHAT: scroll.py Scrolls a message across the display. Press Ctrl+C to exit. """) import fourletterphat as flp message = "YARR PIRATES " while True: # Display the first four letters of the message flp.print_str(message[:4]) # Take the first letter (position 0) of the message # and pop it onto the end of the string. message = message[1:] + message[0] flp.show() time.sleep(0.25)
#!/usr/bin/env python import fourletterphat as flp print(""" Four Letter pHAT: glow.py This example will glow a message at different speeds and durations. Press Ctrl+C to exit. """) while True: flp.clear() flp.print_str("P1D4") flp.show() flp.glow(period=1, duration=4) flp.print_str("P4D8") flp.show() flp.glow(period=4, duration=8)
import fourletterphat as flp import button_shim countdown = 10 while button_shim.button_A == True: str_time = time.strftime("%M%S") flp.print_number_str(countdown) flp.show() countdown -=1 time.sleep(0.55) if button_shim.button_A == True and button_shim.button_B == True and button_shim.button_C == True: break if button_shim.button_E == True or button_shim.button_D == True: flp.print_str('BOOM') flp.show() break if countdown <= 0: flp.print_str('BOOM') flp.show() break countdown_1 = 60 while button_shim.button_B == True: str_time = time.strftime("%M%S") flp.print_number_str(countdown_1) flp.show() countdown_1 -=1
import speedtest import fourletterphat as flp servers = [] flp.scroll_print("STARTING TEST") flp.show() s = speedtest.Speedtest() s.get_servers(servers) s.get_best_server() flp.print_str("DOWN") flp.show() s.download() flp.print_str("UP") flp.show() s.upload() result = s.results down_mb = result.download / 1024 / 1024 up_mb = result.upload / 1024 / 1024 print("Download: " + "{:.2f}".format(down_mb)) print("Download: " + "{:.2f}".format(up_mb))