def show_pressure(): # Makes sure scrollphat buffer is clear sphd.clear() # Pressure value is fetched from weather module pressurevalue = (weather.pressure()) # Uses say_value() to speak the current pressure value speakpressure = ("The current pressure is " + str(round(pressurevalue / 1000, 1)) + " kilopascals") print(speakpressure) say_value(x=speakpressure) # Writes the currnet pressure value to scrollphat buffer sphd.write_string("Pressure: " + str(round(pressurevalue / 1000, 1)) + " kPa", brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def show_temp(): # Makes sure scrollphat buffer is clear sphd.clear() # Declares local variable "degrees", fetches value form weather module and rounds to 1 decimal place degrees = round(weather.temperature(), 1) # Section that controls speach output # "speaktemp" string is set speaktemp = ("The temperature is currently " + str(degrees) + " degrees celcius") print(speaktemp) # "speaktemp" is passed into say_value() function say_value(speaktemp) # Section taht controls scrollphat output # "temperature" string is set temperature = (' Temp: ' + str(degrees) + 'C') # "temperature" string is written to sphd buffer sphd.write_string(temperature, brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def show_light(): # Makes sure scrollphat buffer is clear sphd.clear() # variable is set to be the current light value lightvalue = light.light() # Uses say_value() to speak the current light level speaklight = ("The current light level is " + str(lightvalue)) print(speaklight) say_value(x=speaklight) # Light value is stored in scrollphat buffer lightoutput = (" Light: " + str(lightvalue)) sphd.write_string(lightoutput, brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def show_datetime(): # Makes sure scrollphat buffer is clear sphd.clear() # Current date/time is stored in "currentDT" variable currentDT = datetime.datetime.now() # Prints the current time value print(currentDT.strftime("%I:%M %p")) # Uses say_value() to speak the current time speaktime = ("It is currently " + str(currentDT.strftime("%I:%M %p"))) print(speaktime) say_value(speaktime) sphd.write_string("Time: " + str(currentDT.strftime("%I:%M %p")), brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def show_altitude(): # Makes sure scrollphat buffer is clear sphd.clear() # Altitude value is fetched from weather module altitudevalue = weather.altitude(qnh=1032) # If statement controls if speach output will say "below" or "above" sea level if (altitudevalue <= 0): sealevel = " meters below sea level" elif (altitudevalue >= 1): sealevel = " meters above sea level" # Uses say_value() to speak the current atititude speakaltitude = ("You are roughly " + str(int(altitudevalue)) + sealevel) print(speakaltitude) say_value(x=speakaltitude) # Writes the current sphd.write_string("Altitude: " + str(int(altitudevalue)) + "m", brightness=0.25) # Length of buffer is calculated length = sphd.get_buffer_shape()[0] - 17 # Scrolls for the total length value for x in range(length): sphd.show() sphd.scroll(1) time.sleep(0.03) # Sleeps for 1 second once complete time.sleep(1) # Clears buffer and runs show() to clear display sphd.clear() sphd.show() # Makes sure all button LED's are turned off touchphat.all_off()
def ripple_price(): url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=XRP&convert=USD' headers = { 'Accept': 'application/json', 'Accept-Encoding': 'deflate, gzip', 'X-CMC_PRO_API_KEY': 'd49c4a54-e879-4f24-8a73-af853d3d444f', } r = requests.get(url, headers=headers) if r.status_code == 200: response = json.loads(r.text) price_usd = ("{0:.2f}".format( (response['data']['XRP']['quote']['USD']['price']))) market_cap_usd = ("{0:.2f}".format( (response['data']['XRP']['quote']['USD']['market_cap']))) cryptocurrency_name = response['data']['XRP']['slug'] fetch('The price of 1 Ripple is' + price_usd) play() scrollphathd.write_string('The price of ripple is: ' + price_usd + 'USD', brightness=0.25) length = scrollphathd.get_buffer_shape()[0] - 17 for x in range(length): scrollphathd.show() scrollphathd.scroll(1) time.sleep(0.04) time.sleep(1.5) scrollphathd.clear() scrollphathd.show()
def get_news(): scrollphathd.clear() scrollphathd.show() Pinews = feedparser.parse("https://www.raspberrypi.org/feed/") headline = Pinews["entries"][randint(0,5)]["title"] scrollphathd.write_string(headline + " ", x=0, y=1, font=font3x5) status_length = scrollphathd.get_buffer_shape() status_length = status_length[0] while status_length > 0: scrollphathd.show() scrollphathd.scroll() time.sleep(0.1) status_length -= 1
def bnc_show_title(): scr.write_string(title, x=0, y=0, brightness=bright) scr.show() time.sleep(delay * 20) [bw, bh] = scr.get_buffer_shape() for y in [1, -1]: for x in range(0, bw - width - 1): scr.scroll(x=y, y=0) scr.show() time.sleep(delay) time.sleep(delay3) scr.clear() scr.show()
def LEDmessage(self, txtMessage, loop=False): self.DisplayOff() scrollphathd.rotate(0) scrollphathd.clear() scrollphathd.set_brightness(0.5) scrollphathd.write_string(txtMessage, x=18, y=0, font=font5x7) if loop == True: self.textMessageDisplay = True self.LEDscrollLeft = 0 else: self.textMessageDisplay = False self.LEDscrollLeft = scrollphathd.get_buffer_shape()[0] #print self.LEDscrollLeft #print self.scrollphathd.get_buffer_shape() scrollphathd.show() self.clockDisplay = False
def wifi_show_ssid(): [id, s] = wifi_info() scr.write_string(id, x=0, y=0, brightness=bright) scr.show() time.sleep(delay3) [bw, bh] = scr.get_buffer_shape() for i in range(0, 2): for y in [1, -1]: for x in range(0, bw - width - 1): scr.scroll(x=y, y=0) scr.show() time.sleep(delay) time.sleep(delay3) scr.clear() scr.show()
def run(self): if self._is_enabled is False: return next_interval = self._interval if self._currentIndexCountdown < 0: if len(self._items) > 0: upcoming = self._items.pop() if ALL_UPPERCASE: upcoming = upcoming.upper() scrollphathd.clear() scrollphathd.write_string(upcoming, x=PREFIX_OFFSET, y=0, font=None, letter_spacing=1, brightness=0.2, monospaced=False, fill_background=False) scrollphathd.show() shape = scrollphathd.get_shape() buffer_shape = scrollphathd.get_buffer_shape() self._overflow_length = buffer_shape[0] - shape[0] logging.info("Autoscroll.run: Decreasing index countdown: {} ({} - {})".format(str(self._overflow_length), shape[0], buffer_shape[0])) self._currentIndexCountdown = self._overflow_length next_interval = INITIAL_DELAY # inital delay else: logging.info("Autoscroll.run: No items to pop..") # self.demo() else: logging.info("Autoscroll.run: Just scrolling..") # Scroll the buffer content scrollphathd.scroll(x=SCROLL_PAGE_SIZE) # Show the buffer scrollphathd.show() self._currentIndexCountdown -= SCROLL_PAGE_SIZE # Start a timer threading.Timer(next_interval, self.run).start()
def takePhoto(self): self.DisplayOff() scrollphathd.rotate(0) scrollphathd.set_brightness(0.25) #scorre scritta foto scrollphathd.clear() scrollphathd.write_string('foto', x=18, y=0, font=font5x7) scrollphathd.show() buffL = scrollphathd.get_buffer_shape()[0] time.sleep(0.5) for i in range(buffL + 1): scrollphathd.show() scrollphathd.scroll() time.sleep(0.015) # cancella immagine precedente try: os.remove('image.jpg') except OSError: pass self.camera.resolution = (1920, 1080) time.sleep(0.25) self.countdown() # clic (piccolo flash) scrollphathd.clear() scrollphathd.set_brightness(0.7) scrollphathd.fill(1, x=0, y=0, width=17, height=7) #scrollphathd.write_string('c', x= 0, y=0) #scrollphathd.write_string('l', x= 5, y=0) #scrollphathd.write_string('i', x= 9, y=0) #scrollphathd.write_string('c', x=12, y=0) scrollphathd.show() #scatta la foto time.sleep(0.05) scrollphathd.clear() scrollphathd.show() time.sleep(0.15) # scatta la foto self.camera.capture('image.jpg') return
def makeVideo(self): self.DisplayOff() scrollphathd.rotate(0) scrollphathd.set_brightness(0.25) #scorre scritta video scrollphathd.clear() scrollphathd.write_string('video', x=18, y=0, font=font5x7) scrollphathd.show() buffL = scrollphathd.get_buffer_shape()[0] time.sleep(0.5) for i in range(buffL + 1): scrollphathd.show() scrollphathd.scroll() time.sleep(0.015) # cancella video precedente try: os.remove('video.h264') except OSError: pass try: os.remove('video.mp4') except OSError: pass self.camera.resolution = (1280, 720) time.sleep(0.25) self.countdown() # registra self.camera.start_recording('video.h264') # lampeggia REC per 5 secondi self.recblink() # fine registrazine self.camera.stop_recording() # scrive ok self.endrec() time.sleep(1) self.DisplayOff()
speedkts = 1.944 * gpsd.fix.speed # display speed over ground on scroll pHAT fixed for speeds < 12 kts # Speeds over 12 kts need to scroll the display. The initial offset of 17 # will allow a complete scroll. scrollphathd.clear() kts = ("{0:0.1f}").format(speedkts) if (speedkts < 12.): scrollphathd.write_string(kts, x=1, y=0, font=font5x7) scrollphathd.show() time.sleep(10) # set to delta seconds between grabs else: scrollphathd.write_string(kts, x=17, y=0, font=font5x7) (buf1, buf2) = scrollphathd.get_buffer_shape() for i in range(buf1): scrollphathd.show() scrollphathd.scroll() time.sleep(0.25) # sets scrolling speed # no delay as scrolling takes the time track = gpsd.fix.track # open in append mode and write data, then close files so a system # crash won't prevent output # but first correct time to right time zone lclhrs = int(utc[11:13]) - tzfix if (lclhrs < 0): lclhrs = lclhrs + 24 lcltm = str(lclhrs) + utc[13:19]
string = ' The next ' + bus_num + ' buses arrive in: ' + (', '.join(str(e) for e in nxt_times[0:-1])) + ' and ' + str(nxt_times[-1]) + ' minutes. ' message.append(string) # MESSAGE FOR IF NO BUSES ARE COMING if message == []: message = ' No buses today. ' # MESSAGE FOR IF BUSES ARE COMING else: message = ' '.join(str(e) for e in message) prevTime = currentTime # SETS MESSAGE TO BUFFER sphd.write_string(message) # SCROLLS MESSAGE msg_len = sphd.get_buffer_shape()[0] for i in range(msg_len): sphd.show() sphd.scroll() # CLEARS SCREEN AND PAUSES 2 SECONDS sphd.clear() sphd.show() time.sleep(2)
#!/usr/bin/env python import time import signal import sys import scrollphathd from scrollphathd.fonts import font5x7 for line in sys.stdin: scrollphathd.clear() scrollphathd.write_string(line.rstrip(), x=17, y=0, font=font5x7, brightness=0.3) buffer_length = scrollphathd.get_buffer_shape()[0] for i in range(buffer_length + 1): scrollphathd.show() scrollphathd.scroll() time.sleep(0.05) time.sleep(0.5)
internet_available = internet_on() print("Internet available") sphd.set_brightness(0.3) # could add a light sensor and adjust the brightness automatically # Loop to refresh the headlines from the Internet for n in range(0,2): # clear the lists headlines = [] sport_headlines = [] # refresh the info from the internet get_news_headlines() get_sport_headlines() tech_headline = get_tech_headline() # scroll them on the scrollphathd sphd.write_string("Headlines 1: " + headlines[0] + " 2: " + headlines[1] + " Sport: " + sport_headlines[0] + " Tech: " + tech_headline + " ") buffer = sphd.get_buffer_shape() # Loop to scroll the headlines n times for i in range(0, 2): print(i) # Loop to scroll the buffer for j in range(0, buffer[0] - 10): sphd.show() sphd.scroll(1) time.sleep(0.02) # used 0.02 initially print("Headlines scrolled 2 times. Refreshing headlines.")
import scrollphathd as scroll import sys import time scroll.set_brightness(0.2) output = ' ' + ' '.join(sys.argv[1:]) + (5*' ') scroll.clear() scroll.flip(x=True, y=True) scroll.write_string(output) print("buffer shape", scroll.get_buffer_shape()) width, height = scroll.get_buffer_shape() for _ in range(width): scroll.scroll() scroll.show() time.sleep(0.05)