Esempio n. 1
0
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()
Esempio n. 2
0
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()
Esempio n. 3
0
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()
Esempio n. 4
0
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()
Esempio n. 5
0
    def run(self, textToScroll):

        self._running = True

        print("Starting to Scroll: " + textToScroll)
        print(textToScroll)

        setScrollPhatHDText(textToScroll, 0)

        #
        # Scroll the Message Forever across the display
        #
        while True:

            if self._running == False:
                print("Exitting Scroll Forever")
                clearScrollPhatHD()  # Clear the Display
                break

            try:
                scrollphathd.scroll(1)  # Scroll the Display by 1
                scrollphathd.show()  # Show the newly Scrolled DIsplay
                sleep(0.05)  # Delay by 500ms

            except KeyboardInterrupt:
                clearScrollPhatHD()  # Clear the Display
                sys.exit(-1)  # Exit the Routine
                break
Esempio n. 6
0
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 run(self, textToScroll):

        self._running = True

        print("Starting to Scroll: " + textToScroll)
        print(textToScroll)

        setScrollPhatHDText(textToScroll, 0)

        while True:

            if self._running == False:
                print("Exitting Scroll Forever")
                clearScrollPhatHD()
                break

            try:
                scrollphathd.scroll(1)
                scrollphathd.show()
                sleep(0.05)

            except KeyboardInterrupt:
                clearScrollPhatHD()
                sys.exit(-1)
                break
Esempio n. 8
0
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()
Esempio n. 9
0
    def processMessage():
        timeout = time.time() + 60 * 1 - 10
        while True:
            while not queue.empty():
                #Pause clock thread
                message = queue.get()
                screenFlash()
                while time.time() < timeout:
                    sphd.write_string("  " + message + "  >>")
                    sphd.set_brightness(0.5)
                    sphd.show()
                    sphd.scroll(1)
                    time.sleep(0.05)
                sphd.clear()
                sphd.show()
        #Resume clock thread but keep this checking for messages
        def screenClear():
            sphd.clear()
            sphd.show()

            def screenFlash():
                sphd.fill(1, 0, 0, 17, 7)
                sphd.show()
                time.sleep(0.2)
                screenClear()
                sphd.fill(1, 0, 0, 17, 7)
                sphd.show()
                time.sleep(0.2)
                screenClear()
                sphd.fill(1, 0, 0, 17, 7)
                sphd.show()
                time.sleep(0.2)
                screenClear()
                time.sleep(1)
Esempio n. 10
0
    def run(self):
        global current_value
        next_value = 0.0

        scrollphathd.set_font(font5x7)
        scrollphathd.set_brightness(0.2)
        scrollphathd.rotate(degrees=180)

        while self.running:

            if next_value == 0.0:
                next_value_string = ""
            else:
                next_value_string = self.format_value(next_value)

            if current_value == 0.0:
                curr_value_string = "loading.. "
            else:
                curr_value_string = self.format_value(current_value)
                next_value = current_value

            string_to_display = curr_value_string + next_value_string

            scrollphathd.clear()
            str_len = scrollphathd.write_string(string_to_display)
            for _ in range(str_len):
                scrollphathd.show()
                scrollphathd.scroll()
                time.sleep(0.05)
Esempio n. 11
0
def sticker(memo, input, duration):
    '''Sticker Scroller by AZcoigreach'''
    try:
        click.clear()
        click.secho('Sticker Scroll Running...', fg='red')
        scrollphathd.rotate(degrees=180)
        tmp = str('')
        msg = ' .'
        scrollphathd.write_string(str(msg), font=font3x5, brightness=0.15)
        while True:
            data = pd.DataFrame(pickle.load(open(input, 'rb')))
            datatest = str(data)
            logging.debug('data DataFrame: %s', datatest)
            logging.debug('tmp DataFrame: %s', tmp)
            if datatest != tmp:
                logging.info('Updating DataFrame...')
                tmp = str(data)
                data = data.tail(1)
                data = data.iloc[0, 3]
                msg = memo + str(data)
                scrollphathd.clear()
                scrollphathd.write_string(str(msg),
                                          font=font3x5,
                                          brightness=0.15)
                click.secho(msg, fg='yellow')
            logging.debug('Updating LED...')
            scrollphathd.show()
            scrollphathd.scroll()
            time.sleep(duration)
    except Exception as err:
        logger.error('Scroll Error: %s', err)
        time.sleep(5)
        sticker()
Esempio n. 12
0
def mainloop():
    scrollphathd.rotate(degrees=180)
    scrollphathd.clear()
    scrollphathd.show()

    while True:
        # grab the tweet string from the queue
        try:
            scrollphathd.clear()
            status = q.get(False)
            scrollphathd.write_string(status,font=font5x7, brightness=0.1)
            status_length = scrollphathd.write_string(status, x=0, y=0,font=font5x7, brightness=0.1)
            time.sleep(0.25)

            while status_length > 0:
                scrollphathd.show()
                scrollphathd.scroll(1)
                status_length -= 1
                time.sleep(0.02)


            scrollphathd.clear()
            scrollphathd.show()
            time.sleep(0.25)

            q.task_done()

        except queue.Empty:
            time.sleep(1)
Esempio n. 13
0
def mainloop():
    while True:
        # not q.empty():
        status = q.get()
        scrollphathd.write_string(status, font=font5x7smoothed, brightness=0.1)
        status_length = scrollphathd.write_string(status,
                                                  x=0,
                                                  y=0,
                                                  font=font5x7smoothed,
                                                  brightness=0.1)
        #print(status)
        #print ("<<<<<< Scrolling tweet", status)
        time.sleep(0.25)
        #print 'status length --->',status_length
        while status_length > 0:
            #print 'status length',status_length
            #print 'buffer_len',scrollphathd.write_string(status, x=0, y=0,font=font5x7smoothed, brightness=0.1)
            #scrollphathd.flip(x=True)
            scrollphathd.rotate(degrees=180)
            scrollphathd.show()
            scrollphathd.scroll(1)
            status_length -= 1
            time.sleep(0.01)
        else:
            #scrollphathd.scroll(0)
            #print ">>status length is zero<<"
            scrollphathd.clear()
def weather():
    scrollphathd.clear()
    (resp_headers, content) = h.request("http://api.openweathermap.org/data/2.5/weather?id=" + CITY_ID + "&appid=" + OPENWEATHER_APIKEY + "&units=" + UNITS, "GET", headers={'cache-control':'max-age=' + CACHE_TIME})
    data = json.loads(content.decode('utf-8'))
    t = str(data['main']['temp'])
    con = data['weather'][0]['main']
    tt = float(t)
    if UNITS == "imperial" :
        TF = "F"
    else :
        TF = "C"
    string = " %.1f" % tt + TF + " - " + con + " - "
    strlen = len(string)
    nummax = strlen + 26
    numtimes = nummax*2
    while True:
        scrollphathd.write_string(string, x=0, y=1, font=font3x5, letter_spacing=1, brightness=BRIGHTNESS)
        scrollphathd.show()
        scrollphathd.scroll()
        time.sleep(0.08)
        global num
        num += 1
        if num == numtimes:
            num = 0
            break
Esempio n. 15
0
def mainloop():
    # Uncomment the below if your display is upside down
    #   (e.g. if you're using it in a Pimoroni Scroll Bot)
    # scrollphathd.rotate(degrees=180)
    scrollphathd.clear()
    scrollphathd.show()

    while True:
        # grab the tweet string from the queue
        try:
            scrollphathd.clear()
            status = q.get(False)
            scrollphathd.write_string(status, font=font5x7, brightness=0.1)
            status_length = scrollphathd.write_string(status, x=0, y=0, font=font5x7, brightness=0.1)
            time.sleep(0.25)

            while status_length > 0:
                scrollphathd.show()
                scrollphathd.scroll(1)
                status_length -= 1
                time.sleep(0.02)

            scrollphathd.clear()
            scrollphathd.show()
            time.sleep(0.25)

            q.task_done()

        except queue.Empty:
            time.sleep(1)
Esempio n. 16
0
def news():
    # Put the Twitter usernames of the news organisations you want to read here
    twits = ["BBCNews", "GranadaReports", "SkyNews", "itvnews", "MENnewsdesk"]
    for index in range(len(twits)):
        # The count parameter defines how many tweets from each account you'll read
        tweets = api.get_user_timeline(screen_name=twits[index], count=3)
        for tweet in tweets:
            clean_tweet = '%s: %s' % (tweet['user']['screen_name'],
                                      tweet['text'])

            # This line clear URLs from the tweets
            clean_tweet = re.sub(r"(https?\://|http?\://|https?\:)\S+", "",
                                 clean_tweet)
            clean_tweet = clean_tweet.encode('ascii', 'ignore').decode('ascii')
            scrollphathd.write_string(clean_tweet, x=17, font=font5x7)
            tweet_length = scrollphathd.write_string(
                clean_tweet, x=17, y=0, font=font5x7) + 7
            time.sleep(0.25)
            while tweet_length > 0:
                scrollphathd.show()
                scrollphathd.scroll()
                tweet_length -= 1
                time.sleep(0.01)
            scrollphathd.clear()
            scrollphathd.show()
	def _loop(self):
		while True:
			self.scroll_remaining -= 1
			if self.scroll_remaining == 0:
				leds.clear()
				leds.show()
			elif self.scroll_remaining > 0:
				leds.scroll()
				leds.show()
			elif len(self.phrases) > 0:
				self.scroll_remaining = leds.write_string("|      " + self.phrases.pop(0) + "      |") - 20
			else:
				t = self.scroll_remaining
				fade_in = min(1.0, -t / 30000.0)  # fade in over 10 minutes, at sleep(0.02) (50Hz)
				ox = math.sin(t/50.0) * 2.0
				oy = math.cos(t/50.0) * 2.0
				for x in range(17):
					dx = float(x) + ox - 8.0
					for y in range(7):
						dy = float(y) + oy - 3.0
						d = math.sqrt(math.pow(dx, 2) + math.pow(dy, 2))
						b = math.sin(d + (t/5.0))
						b = (b + 1) / 2
						b = b * fade_in
						leds.set_pixel(x, y, b)
				leds.show()
			time.sleep(0.02)
Esempio n. 18
0
    def _write_scroll_worker(self, wait_time):
        """Method for the worker thread. It is running until the stop event
        occurs."""

        while not self.stop_event.is_set():
            scroll.scroll()
            scroll.show()
            time.sleep(wait_time)
Esempio n. 19
0
 def run(self):
     if self._is_enabled is True:
         # Start a timer
         threading.Timer(self._interval, self.run).start()
         # Scroll the buffer content
         scrollphathd.scroll()
         # Show the buffer
         scrollphathd.show()
Esempio n. 20
0
 def show_red_string(self, message):
     sphd.clear()
     sphd.write_string(message, font=font3x5)
     while self.turn_on_red_flag:
         sphd.show()
         sphd.scroll(1)
         time.sleep(0.1)
     print("red")
Esempio n. 21
0
def display_scroll_text(text, display_time=5):
    update_time = 0.05  # scroll speed in seconds per pixel
    sphd.clear()  # blank the screen ready to write some text
    sphd.write_string(text)
    for t in range(int(display_time / update_time)):
        sphd.show()
        sphd.scroll(1)
        time.sleep(update_time)
Esempio n. 22
0
def mainloop():
    scrollphathd.rotate(degrees=180)
    scrollphathd.clear()
    scrollphathd.show()

    while True:
        # grab the tweet string from the queue
        try:
            scrollphathd.clear()
            status = q.get(False)

            scrollphathd.write_string(status, font=font5x7, brightness=0.1)
            status_length = scrollphathd.write_string(status,
                                                      x=0,
                                                      y=0,
                                                      font=font5x7,
                                                      brightness=0.1)
            time.sleep(0.25)

            while status_length > 0:
                scrollphathd.show()
                scrollphathd.scroll(1)
                status_length -= 1
                time.sleep(0.02)

            scrollphathd.clear()
            scrollphathd.show()
            time.sleep(0.25)

            q.task_done()

        except queue.Empty:
            float_sec = (time.time() % 60) / 59.0
            seconds_progress = float_sec * 15

            if DISPLAY_BAR:
                for y in range(15):
                    current_pixel = min(seconds_progress, 1)
                    scrollphathd.set_pixel(y + 1, 6,
                                           current_pixel * BRIGHTNESS)
                    seconds_progress -= 1
                    if seconds_progress <= 0:
                        break

            else:
                scrollphathd.set_pixel(int(seconds_progress), 6, BRIGHTNESS)

            scrollphathd.write_string(time.strftime("%H:%M"),
                                      x=0,
                                      y=0,
                                      font=font5x5,
                                      brightness=BRIGHTNESS)

            if int(time.time()) % 2 == 0:
                scrollphathd.clear_rect(8, 0, 1, 5)

            scrollphathd.show()
            time.sleep(0.25)
Esempio n. 23
0
def scrollMsgOnce(msg):
    msg = msg + "      " # 6 spaces
    buffer = shd.write_string(msg, x=17, y=0, brightness=0.5)
    for i in range(buffer):
        shd.show()
        shd.scroll(1)
        sleep(0.05)
    shd.clear()
    shd.show()
Esempio n. 24
0
 def DisplayScrollOnce(self):
     if self.LEDscrollLeft > 0:
         self.LEDscrollLeft -= 1  # decrementa il contatore dei pixel rimasti da far scorrere
         scrollphathd.show()
         scrollphathd.scroll()
     if self.LEDscrollLeft == 0:
         scrollphathd.show()
         scrollphathd.clear()
     return
Esempio n. 25
0
 def show_green_string(self, message):
     sphd.clear()
     sphd.write_string('-' + message + '-', font=font3x5, brightness=0.5)
     # sphd.write_string(message)
     sphd.show()
     sphd.scroll(1)
     print("green")
     time.sleep(3)
     self.turnoff_led()
Esempio n. 26
0
def scrollText(text, dateTime=None):
	if sphd is not None:
		sphd.clear()
		sphd.write_string(text, 10)
		while True:
			sphd.show()
			sphd.scroll(1)
			time.sleep(0.015)
			# Update clock time
			if dateTime is not None and text != dateTime['time']:
				scrollText(dateTime['time'], dateTime)
Esempio n. 27
0
def scroll_message(output):
    scrollphathd.write_string(output)
    scrollphathd.show()

    while (True):
        try:
            scrollphathd.scroll()
            scrollphathd.show()
            time.sleep(0.1)
        except KeyboardInterrupt:
            return
Esempio n. 28
0
def scroll(scrollTextArray):

    while True:
        scrollText = scrollTextArray[0] + '   '
        sphd.clear()
        sphd.write_string(scrollText, brightness=0.3)

        for xPos in range(len(scrollText) * 6):
            sphd.show()
            sphd.scroll(1)
            time.sleep(0.02)
Esempio n. 29
0
 def start(self):
     # Uncomment the below if your display is upside down
     #   (e.g. if you're using it in a Pimoroni Scroll Bot)
     scrollphathd.rotate(degrees=180)
     
     start = time.time()
     end=start + 1 + 10 #25 * 60
     
     while end>time.time():
         scrollphathd.clear()
         now=time.time()
         delta_t=end-now
         secs=int(delta_t)
         
         text=datetime.fromtimestamp(delta_t).strftime("%M:%S")
         # Display the time (HH:MM) in a 5x5 pixel font
         scrollphathd.write_string(
             text,
             x=0, # Align to the left of the buffer
             y=0, # Align to the top of the buffer
             font=font5x5, # Use the font5x5 font we imported above
             brightness=BRIGHTNESS # Use our global brightness value
         )
     
         # int(time.time()) % 2 will tick between 0 and 1 every second.
         # We can use this fact to clear the ":" and cause it to blink on/off
         # every other second, like a digital clock.
         # To do this we clear a rectangle 8 pixels along, 0 down,
         # that's 1 pixel wide and 5 pixels tall.
         if int(time.time()) % 2 == 0:
             scrollphathd.clear_rect(8, 0, 1, 5)
     
         # Display our time and sleep a bit. Using 1 second in time.sleep
         # is not recommended, since you might get quite far out of phase
         # with the passing of real wall-time seconds and it'll look weird!
         #
         # 1/10th of a second is accurate enough for a simple clock though :D
         scrollphathd.show()
         time.sleep(0.1)
     
     scrollphathd.clear()
     scrollphathd.show()
     scrollphathd.write_string(
         "Time's up! ",
         x=0, # Align to the left of the buffer
         y=0, # Align to the top of the buffer
         font=font5x7, # Use the font5x5 font we imported above
         brightness=BRIGHTNESS # Use our global brightness value
     )
     
     while True:
         scrollphathd.scroll()
         scrollphathd.show()
         time.sleep(0.1)
Esempio n. 30
0
def showFact(message):
    message = message[:255]  # cut down to 255 chars
    message += "....."
    print("Fact: ", message)
    sphd.write_string(message)
    for x in range(0, ((len(message) - 4) * 5)):
        sphd.show()
        sphd.scroll(1)
        time.sleep(0.01)
    time.sleep(0.4)
    sphd.clear()
    sphd.show()
Esempio n. 31
0
def _scroll():
    global status_length
    scrollphathd.scroll(1)
    status_length -= 1
    scrollphathd.show()
    time.sleep(0.01)