Esempio n. 1
0
def ScrollSomeText(textToScroll):

    global scrollText

    scrollphathd.scroll_to(0, 0)
    ScrollTextThread = Thread(target=scrollText.run, args=(textToScroll, ))
    ScrollTextThread.start()
def scrollList(output):
    #accepts a list of strings and displays to the scrollphat
    #buffer size is limited, suggesting to limit lines < 10, depending on length of each object

    #setup the display default parameters
    scrollphathd.rotate(displayrotation)
    scrollphathd.set_brightness(displaybrightness)
    # displayRewind = True # rapidly displayRewind after the last line
    # delay = 0.009 # Delay is the time (in seconds) between each pixel scrolled

    # Draw each line in lines to the Scroll pHAT HD buffer
    scrollphathd.clear()  #clear the buffer before displaying the next list
    line_height = scrollphathd.DISPLAY_HEIGHT + 3  # Determine how far apart each line should be spaced vertically
    offset_left = 0  # Store the left offset for each subsequent line (starts at the end of the last line)
    lengths = [0] * len(output)  # Get the length of each 'line' for the buffer

    for line, text in enumerate(output):
        lengths[line] = scrollphathd.write_string(
            text, x=offset_left, y=line_height * line
        )  # scrollphathd.write_string returns the length of the written string in pixels
        offset_left += lengths[
            line]  # we can use this length to calculate the offset of the next line for scrolling effect lateer

    scrollphathd.set_pixel(
        offset_left - 1, (len(output) * line_height) - 1, 0
    )  # adds some horizontal/vertical padding to the buffer at the very bottom right of the last line to wrap nice
    scrollphathd.scroll_to(0, 0)  # Reset animation
    scrollphathd.show()

    pos_x = 0  # Keep track of the X and Y position for the displayRewind effect
    pos_y = 0

    for current_line, line_length in enumerate(lengths):
        time.sleep(
            displayScrollSpeed *
            10)  # Delay a slightly longer time at the start of each line
        for y in range(line_length):  # Scroll to the end of the current line
            scrollphathd.scroll(1, 0)
            pos_x += 1
            time.sleep(displayScrollSpeed)
            scrollphathd.show()

        if current_line == len(
                output
        ) - 1 and displayRewind:  # If on the very last line and displayRewind is True, rapidly scroll back to the first line.
            for y in range(pos_y):
                scrollphathd.scroll(-int(pos_x / pos_y), -1)
                scrollphathd.show()
                time.sleep(displayScrollSpeed)
                scrollphathd.clear()  #Clear the buffer

        else:  # Otherwise, progress to the next line by scrolling upwards
            for x in range(line_height):
                scrollphathd.scroll(0, 1)
                pos_y += 1
                scrollphathd.show()

    time.sleep(displayScrollSpeed)
def display_string(string):
    print('[Display] Showing message "{0}"'.format(string))
    string += '      '
    buffer = scrollphathd.write_string(string,
                                       x=17,
                                       y=0,
                                       font=font5x7,
                                       brightness=0.5)

    for i in range(buffer):
        scrollphathd.show()
        scrollphathd.scroll(1)
        time.sleep(0.02)

    scrollphathd.scroll_to(0, 0)
    scrollphathd.clear()
    scrollphathd.show()
Esempio n. 4
0
def display(e):
    global output
    global index

    while True:
        message = output[index]
        index = 1 - index
        e.set()
        e.clear()

        scrollphathd.clear()
        length = scrollphathd.write_string(message, x=width, font=font5x7)

        scrollphathd.scroll_to(0, 0)
        for i in range(length + width):
            scrollphathd.show()
            time.sleep(0.05)
            scrollphathd.scroll()
Esempio n. 5
0
def scroll(textmsg="???", bright=0.3, speed=0.04, ignore_quiet_time=False):
    global scrollphathd

    #if quiet hours do not display
    if is_quiet_time() and ignore_quiet_time == False:
        return None

    #  Clear buffer
    # Reset the animation
    scrollphathd.scroll_to(0, 0)
    scrollphathd.clear()  # so we can rebuild it
    scrollphathd.show()

    # Keep track of the X and Y position for the rewind effect
    pos_x = 0

    textmsg = " " + textmsg + "   ."  # append 3 spaces tp message  to prevent wrapping of start
    print "Scrolling  %s. size: %d" % (textmsg, len(textmsg))
    scrollphathd.write_string(textmsg,
                              x=0,
                              y=0,
                              font=font5x7,
                              brightness=bright)

    # Scroll to the end of the current line
    msgpixels = len(textmsg) * 7
    for y in range(msgpixels):
        scrollphathd.scroll(1, 0)
        pos_x += 1
        time.sleep(speed)
        scrollphathd.show()

    #time.sleep(0.05)
    scrollphathd.clear()  # so we can rebuild it
    scrollphathd.show()
    return
Esempio n. 6
0
        lengths[line] = scrollphathd.write_string(text,
                                                  x=offset_left,
                                                  y=line_height * line)
        offset_left += lengths[line]

    # This adds a little bit of horizontal/vertical padding into the buffer at
    # the very bottom right of the last line to keep things wrapping nicely.
    scrollphathd.set_pixel(offset_left - 1, (len(lines) * line_height) - 1, 0)
    return


#check for hardware and make sure no GPIO / hardware faults

try:
    print "Checking Hardware ScrollPhat HD is availble"
    scrollphathd.scroll_to(0, 0)
    print " Passed!"

    print "Rotatng display - for placing upside down with Pi zero"
    scrollphathd.rotate(180)

except KeyboardInterrupt:
    # here you put any code you want to run before the program
    # exits when you press CTRL+C
    print "\n", counter  # print value of counter

except:
    # this catches ALL other exceptions including errors.
    # You won't get any error messages for debugging
    # so only use it once your code is working
    print "Hardware Error SchrollPhat HD is no responding. Check hardware."
Esempio n. 7
0
# source https://learn.pimoroni.com/tutorial/tanya/santabot-xmas-timer
import datetime
import time
import signal
import scrollphathd
from scrollphathd.fonts import font5x7

# as upside down in scrollbot
scrollphathd.rotate(180) 

str_len = 0
scroll_x = 0

while True:
    xmas = datetime.datetime(2018, 12, 25) - datetime.datetime.now()
    daysleft = xmas.days
    hoursleft = xmas.seconds/3600

    scrollphathd.set_brightness(0.5)
    scrollphathd.clear()

    str_len = scrollphathd.write_string("Ho ho ho! It's %i days and %i hours until xmas!" %(daysleft, hoursleft), x=0, y=0, font=font5x7)
    scrollphathd.scroll_to(scroll_x, 0)
    scrollphathd.show()
    time.sleep(0.05)
    scroll_x += 1
    if scroll_x >= str_len:
        scroll_x = 0
Esempio n. 8
0
def clearScrollPhatHD():

    scrollphathd.scroll_to(0, 0)
    scrollphathd.clear()
    scrollphathd.show()
Esempio n. 9
0
        #  build message to scroll
        msg = "Temp" + str(
            ((w.temp['temp_min'] + w.temp['temp_max']) / 2)) + "c"
        # forecast
        fc = owm.three_hours_forecast('Basel,CH')

        if fc.will_have_rain():
            w.rain = fc.when_rain()[0]
            time.rain = w.rain.get_reference_time(timeformat='date')
            msg = msg + " rain at " + str(time.rain.hour) + "h"
        else:
            msg = msg + " No rain"

        # avoid immediate loop
        msg = msg + "     "
    # set message
    sphd.clear()
    str_len = sphd.write_string(msg)
    sphd.set_brightness(0.25)

    # do the scrolling
    sphd.scroll_to(scroll_x, 0)
    sphd.show()
    time.sleep(0.05)
    scroll_x += 1
    time_since_update += 1
    if scroll_x >= str_len:
        scroll_x = 0

# end of script
Esempio n. 10
0
def scrollup(lines, ignore_quiet_time=False):

    #if quiet hours do not display
    if is_quiet_time() and ignore_quiet_time == False:
        return None

    # Delay is the time (in seconds) between each pixel scrolled
    delay = 0.03
    scrollphathd.set_brightness(0.2)

    # Determine how far apart each line should be spaced vertically
    line_height = scrollphathd.DISPLAY_HEIGHT + 2

    # Store the left offset for each subsequent line (starts at the end of the last line)
    offset_left = 0

    # Draw each line in lines to the Scroll pHAT HD buffer
    # scrollphathd.write_string returns the length of the written string in pixels
    # we can use this length to calculate the offset of the next line
    # and will also use it later for the scrolling effect.
    lengths = [0] * len(lines)

    for line, text in enumerate(lines):
        lengths[line] = scrollphathd.write_string(text,
                                                  x=offset_left,
                                                  y=line_height * line)
        offset_left += lengths[line]
        print text

    # This adds a little bit of horizontal/vertical padding into the buffer at
    # the very bottom right of the last line to keep things wrapping nicely.
    scrollphathd.set_pixel(offset_left - 1, (len(lines) * line_height) - 1, 0)

    # Reset the animation
    scrollphathd.scroll_to(0, 0)
    scrollphathd.show()

    # Keep track of the X and Y position for the rewind effect
    pos_x = 0
    pos_y = 0

    for current_line, line_length in enumerate(lengths):
        # Delay a slightly longer time at the start of each line
        time.sleep(delay * 10)

        # Scroll to the end of the current line
        for y in range(line_length):
            scrollphathd.scroll(1, 0)
            pos_x += 1
            time.sleep(delay)
            scrollphathd.show()

        for x in range(line_height):
            scrollphathd.scroll(0, 1)
            pos_y += 1
            scrollphathd.show()
            time.sleep(delay)

    scrollphathd.fill(0)
    scrollphathd.show()
    print "Ending scrollup() "
Esempio n. 11
0
def scroll(content=None):
    scrollphathd.clear()
    if content is None:
        content = ["I could be bounded in a nutshell,",
                   "and count myself a king of infinite space.",
                   "--Hamlet: Act II, scene ii"
                   ]
    # Build the message
    lines = content

    # Determine how far apart each line should be spaced vertically
    line_height = scrollphathd.DISPLAY_HEIGHT + 2

    # Store the left offset for each subsequent line (starts at the end of the last line)
    offset_left = 0

    # Draw each line in lines to the Scroll pHAT HD buffer
    # scrollphathd.write_string returns the length of the written string in pixels
    # we can use this length to calculate the offset of the next line
    # and will also use it later for the scrolling effect.
    lengths = [0] * len(lines)

    for line, text in enumerate(lines):
        lengths[line] = scrollphathd.write_string(text, x=offset_left, y=line_height * line)
        offset_left += lengths[line]

    # This adds a little bit of horizontal/vertical padding into the buffer at
    # the very bottom right of the last line to keep things wrapping nicely.
    scrollphathd.set_pixel(offset_left - 1, (len(lines) * line_height) - 1, 0)

    # Reset the animation
    scrollphathd.scroll_to(0, 0)
    scrollphathd.show()

    # Keep track of the X and Y position for the rewind effect
    pos_x = 0
    pos_y = 0

    for current_line, line_length in enumerate(lengths):
        # Delay a slightly longer time at the start of each line
        time.sleep(DELAY * 10)

        # Scroll to the end of the current line
        for y in range(line_length):
            scrollphathd.scroll(1, 0)
            pos_x += 1
            time.sleep(DELAY)
            scrollphathd.show()
            global LOOP
            if not LOOP:
                break

        # If we're currently on the very last line and rewind is True
        # We should rapidly scroll back to the first line.
        if current_line == len(lines) - 1 and REWIND:
            for y in range(pos_y):
                scrollphathd.scroll(-int(pos_x / pos_y), -1)
                scrollphathd.show()
                time.sleep(DELAY)

        # Otherwise, progress to the next line by scrolling upwards
        else:
            for x in range(line_height):
                scrollphathd.scroll(0, 1)
                pos_y += 1
                scrollphathd.show()
                time.sleep(DELAY)