def _dequeue():
    global status_length
    scrollphathd.clear()
    logger.info("len(q) = {}".format(len(q)))
    status = q.pop()
    status_length = scrollphathd.write_string(status, x=18, y=0, font=font5x7smoothed, brightness=0.4) + 17
    scrollphathd.show()
    time.sleep(0.01)
Exemple #2
0
    """

    # Start a timer
    threading.Timer(interval, autoscroll, [interval]).start()
    # Show the buffer
    scrollphathd.show()
    # Scroll the buffer content
    scrollphathd.scroll()


print("""
Scroll pHAT HD: Hello World

Scrolls "Hello World" across the screen
using the default 5x7 pixel large font.

Press Ctrl+C to exit!

""")

# 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)

# Write the "Hello World!" string in the buffer and
#   set a more eye-friendly default brightness
scrollphathd.write_string(" Hello World!", brightness=0.5)

# Auto scroll using a thread
autoscroll()
Exemple #3
0
    GetResponse()

    # Convert ticketids array to string and comma separate values
    ticketids_string = str(ticketids).strip('[]')

    # Convert numberoftickets int to string
    numberoftickets_string = str(numberoftickets)

    # Combine numberoftickets_string and ticketids_string plus text into output variable
    output = '  Tickets: ' + numberoftickets_string + ' IDs: ' + ticketids_string

    # Clear the pi output
    scrollphathd.clear()

    # Watch a queue - if its empty do nothing. If there more than one ticket, output to pi buffer
    if numberoftickets > 0:

        # Write output string to the pi buffer
        scrollphathd.write_string(output, font=font3x5, y=1, brightness=0.5)

    #if numberoftickets == 0:

        # Saving this section for an action when there are zero ungrabbed crits

    # Call the autoscroll function that will send the pi buffer to the led screen, but make sure it only runs once
    while scroll_limit < 1:
        autoscroll()
        scroll_limit += 1

    # Sleep for duration of poll_interval to rate limit api access
    time.sleep(poll_interval)
Exemple #4
0
    def runClock():
        while True:
            sphd.clear()

            # Grab the "seconds" component of the current time
            # and convert it to a range from 0.0 to 1.0
            float_sec = (time.time() % 60) / 59.0

            # Multiply our range by 15 to spread the current
            # number of seconds over 15 pixels.
            #
            # 60 is evenly divisible by 15, so that
            # each fully lit pixel represents 4 seconds.
            #
            # For example this is 28 seconds:
            # [x][x][x][x][x][x][x][ ][ ][ ][ ][ ][ ][ ][ ]
            #  ^ - 0 seconds                59 seconds - ^
            seconds_progress = float_sec * 15

            if DISPLAY_BAR:
                # Step through 15 pixels to draw the seconds bar
                for y in range(15):
                    # For each pixel, we figure out its brightness by
                    # seeing how much of "seconds_progress" is left to draw
                    # If it's greater than 1 (full brightness) then we just display 1.
                    current_pixel = min(seconds_progress, 1)

                    # Multiply the pixel brightness (0.0 to 1.0) by our global brightness value
                    sphd.set_pixel(y + 1, 6, current_pixel * BRIGHTNESS)

                    # Subtract 1 now we've drawn that pixel
                    seconds_progress -= 1

                    # If we reach or pass 0, there are no more pixels left to draw
                    if seconds_progress <= 0:
                        break

            else:
                # Just display a simple dot
                sphd.set_pixel(int(seconds_progress), 6, BRIGHTNESS)

            # Display the time (HH:MM) in a 5x5 pixel font
            sphd.write_string(
                time.strftime("%H:%M"),
                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:
                sphd.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
            sphd.show()
            time.sleep(0.1)
Exemple #5
0
import time

from netifaces import ifaddresses
from subprocess import check_output

ipaddr = ifaddresses('wlan0')[2][0]['addr']
scanoutput = check_output(["/sbin/iwlist", "wlan0", "scan"])

#lock onto the strongest source, it should be the power generator.
for line in scanoutput.split():
    if line.startswith("ESSID"):
        ssid = line.split('"')[1]
        break

#string the Wifi SSID name to the wlan's IPAddress
msg = '   ' + ssid + ':' + ipaddr
print msg

#Output that at 1/5th brightness.
sphd.write_string(msg, brightness=0.2)

#scroll this message a couple of times and then stop.
cnt = 0
while cnt < (len(msg) * 10):
    sphd.show()
    sphd.scroll(1)
    time.sleep(0.1)
    cnt = cnt + 1

sphd.clear()
Exemple #6
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
def run():
    # create a database connection
    database = "clockBase.db"
    conn = create_connection(database)
    cur = conn.cursor()
    sql = 'SELECT messageNo, text FROM messages WHERE displayedP = 0;'
    showit = True

    scrollphathd.clear()
    scrollphathd.show()
    counter = 1
    weatherD = msWeather.combinedReport()
    brightNow = brightness(weatherD['sunrise_time'], weatherD['sunset_time'])

    while True:
        # check db
        cur.execute(
            "SELECT messageNo,text FROM messages WHERE displayedP = 0;")
        rows = cur.fetchall()

        # pick a message
        if counter < 3:
            text = msClock.paddedTime()
            counter = counter + 1
            showIt = True
#            counter = 7 # for debugging
        elif counter == 3:
            try:
                holderD = msWeather.combinedReport()
            except:
                print('no response from weather server. re-using data.')
                holderD = weatherD
            weatherD = holderD
            text = weatherD['status']
            brightNow = brightness(weatherD['sunrise_time'],
                                   weatherD['sunset_time'])
            counter = counter + 1
        elif 3 < counter <= 5:
            text = msClock.paddedTime()
            counter = counter + 1
        elif counter == 6:
            text = 'forecast: ' + weatherD['detailed_status']
            counter = counter + 1
        elif counter == 7:
            cur.execute(sql)
            rows = cur.fetchall()
            if len(rows) > 0:
                text = rows[0][1]
                cur.execute(
                    '''UPDATE messages SET displayTime = ?, displayedP = 1 WHERE messageNo = ?''',
                    (time.time(), rows[0][0]))
                conn.commit()
                showIt = True
            else:
                text = ''
                showIt = False
            counter = 1

        if (showIt):
            text = "    " + text
        if int(args.db) == 1:
            debugText = text.encode('ascii', 'ignore').decode('ascii')
            print(text)
            with open("./debug.txt", "a") as debugFile:
                debugFile.write(debugText + '\n')
        if (showIt):
            textWidth = scrollphathd.write_string(text,
                                                  x=0,
                                                  y=0,
                                                  font=font5x7,
                                                  brightness=brightNow)
            scrollphathd.show()

            for deltaX in range(textWidth):
                scrollphathd.scroll(x=1)
                scrollphathd.show()
                time.sleep(float(args.dt))
            scrollphathd.clear()
            scrollphathd.show()
            time.sleep(float(args.dm))
Exemple #8
0
#Original code by alexellis, updated to run on scroll-phat-hd by alexmburns.

import math
import sys
import time

import scrollphathd


i = 0
buf = [0] * 17
scrollphathd.set_brightness(0.5)

while True:
    try:
        for x in range(0, 17):
            y = (math.sin((i + (x * 10)) / 10.0) + 1) # Produces range from 0 to 2
            y *= 2.5 # Scale to 0 to 5
            buf[x] = 1 << int(y)

        scrollphathd.write_string(buf)
        scrollphathd.show()
	scrollphathd.scroll()
	scrollphathd.clear()
        time.sleep(0.005)

        i += 1
    except KeyboardInterrupt:
        scrollphathd.clear()
        sys.exit(-1)
Exemple #9
0
def do_test(text):
    for bright in [0.1, 0.25, 0.4, 0.55, 0.7]:
        scrollphathd.clear()
        scrollphathd.write_string(text, font=font5x7, brightness=bright)
        scrollphathd.show()
        time.sleep(0.75)
Exemple #10
0
#!/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)
from six import unichr

print("""
Scroll pHAT HD: Hello utf-8

Scrolls the 256 characters Scroll pHAT supports across the screen.

Note: many otherwise useless control characters have been
replaced with symbols you might find useful!

Press Ctrl+C to exit!

""")

# Uncomment to rotate the text
# scrollphathd.rotate(180)

# Set a more eye-friendly default brightness
scrollphathd.set_brightness(0.5)

text = [unichr(x) for x in range(256)]

text = u"{}        ".format(u"".join(text))

scrollphathd.write_string(text, x=0, y=0, font=font5x7, brightness=0.5)

while True:
    scrollphathd.show()
    scrollphathd.scroll()
    time.sleep(0.05)
    scrollphathd.clear()

    if last == 0:
        # show startup logo
        scrollphathd.clear()
        scrollphathd.fill(0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT + 14)
        image_path = os.path.join(os.path.dirname(__file__), IMAGE_FILE)
        image = Image.open(image_path)
        pixels = image.load()

        for x in range(IMAGE_WIDTH):
            for y in range(IMAGE_HEIGHT):
                r, g, b = pixels[x, y]
                scrollphathd.pixel(x, y + 7, (r / 255) * BRIGHTNESS)

        scrollphathd.write_string('%s ' % int(latest), 1, IMAGE_HEIGHT + 8,
                                  font5x5, 1, BRIGHTNESS)
        scrollphathd.scroll_to(0, 0)

        for i in range(IMAGE_HEIGHT + 8):
            scrollphathd.show()
            scrollphathd.scroll(0, 1)
            time.sleep(0.05)

    else:
        scrollphathd.fill(0, 0, 0, 50, 14)  # a nice big canvas to work with

        if latest > last:
            scrollphathd.scroll_to(0, 0)
            scrollphathd.write_string('%s ' % int(last), 1, 1, font5x5, 1,
                                      BRIGHTNESS)
            scrollphathd.write_string('%s ' % int(latest), 1, 8, font5x5, 1,
Exemple #13
0
# Auto scroll using a while + time mechanism (no thread)
eyes = [r, r]
show_eyes()
n = threading.Thread(target=show_eyes_worker)
n.start()
reset = True
val = 0
diff = 10
while True:
    global pressed, reset

    try:
        if reset:
            sphd.clear()
            sphd.write_string(" I'm Batman!  Happy Birthday Alex ",
                              brightness=0.5)
            reset = False
        while pressed == False:
            # Show the buffer
            sphd.show()
            # Scroll the buffer content
            sphd.scroll()

            val += diff
            if val > 127:
                diff = diff * -1
            if val < 0:
                val = 0
                diff = diff * -1

            eyes = [Color(val, val, val), Color(val, val, val)]
Exemple #14
0
def set_test_text():
    sphd.rotate(180)
    sphd.clear()
    sphd.write_string("Test", brightness=0.1)
    sphd.show()
    time.sleep(1)
Exemple #15
0
import scrollphathd
from scrollphathd.fonts import font3x5, font5x5, font5x7, font5x7smoothed
#possible font3x5, font5x5, font5x7 (default), font5x7smoothed, font5x7unicode
FONT = font5x7
Y_PADDING = 0
if FONT.__name__ == "scrollphathd.fonts.font3x5" or FONT.__name__ == "scrollphathd.fonts.font5x5":
    Y_PADDING = 1
if FONT.__name__ == "scrollphathd.fonts.font5x7smoothed":
    BRIGHTNESS += 0.2

# Comment the below if your display is upside down
#   (e.g. if you're NOT using it in a Pimoroni Scroll Bot)
scrollphathd.rotate(degrees=180)
# Auto scroll using a thread
scrollphathd.write_string(getCryptocurrencies(bases),
                          y=Y_PADDING,
                          font=FONT,
                          brightness=BRIGHTNESS)
event = threading.Event()
autoscroll(event, bases, SCROLL_SPEED)


def signal_term_handler(signal, frame):
    print('got SIGTERM')
    scrollphathd.clear()
    scrollphathd.show()
    print("Exiting autoscroll....")
    sys.exit(0)


signal.signal(signal.SIGTERM, signal_term_handler)
            elif '5x7' in font:
                if 'smoothed' in font:
		    scrollphathd.set_font( font5x7smoothed )
                    font_width = font5x7smoothed.width
                else:
		    scrollphathd.set_font( font5x7 )
                    font_width = font5x7.width

        if '<text>' in msg:
            string = msg[ msg.find('>')+1 : ]
            width = len(string) * font_width 
            scrollphathd.clear()
            x = (17/2) - (width/2)
            if x < 0:
               x = 0
    	    scrollphathd.write_string( string, x=x, y=2, brightness=1.0 )
            timeout = time.time() + 1.0
        
        if '<ball>' in msg:
            string = msg[ msg.find('>')+1 : ]
            scrollphathd.clear()
            show_ball = True
            scrollphathd.set_font( fontd3 )
            scrollphathd.write_string( string, x=10, y=1, brightness=1.0 )
            timeout = time.time() + 1.0

    perc = (timeout - time.time()) / 1.0
    if perc > 0:
        if show_ball:
           ball_i = int(14.0*(1.0-perc)) % 7
           scrollphathd.set_font( fontball )
Exemple #17
0
    def wakeUpAlarm(theThing, msg, alarmLink, receiver_email):

        print("waking up for:", os.getpid())
        ##code to start wake up light
        GPIO.setmode(GPIO.BCM)  #it is the same as pHAT
        #vars for button length
        deltaTime = 0
        startTime = 0
        endTime = 0
        sleepTime = 0.1
        #pin being used
        buttonPin = 17  #using gpio pin 17 - physically pin 11
        #GPIO code from https://www.youtube.com/watch?v=LEi_dT9KDJI done by BurgZerg Arcade
        GPIO.setup(
            buttonPin, GPIO.IN,
            pull_up_down=GPIO.PUD_UP)  #setup pint to check for button push

        #wake up light loop
        #exit this loop once wake up time is finished or when button is pushed
        wakingUp = True
        timeCount = 0
        levelCount = 1
        levelTime = 6  #level time of 6 seconds () makes wake up time 1 minute instead of 30 minutes

        while wakingUp:
            try:
                #increase brightness if the time between levels has passed
                if timeCount >= levelTime:
                    levelCount += 1
                    timeCount = 0
                    if levelCount == 11:
                        wakingUp = False
                    else:
                        #set all pixels to current brighness
                        for r in range(0, 7):
                            for c in range(0, 17):
                                sphd.set_pixel(c, r, levelCount * 0.1)
                        sphd.show()

                #increase time spent for this loop
                timeCount += 0.1

                #button code
                if not GPIO.input(
                        buttonPin
                ):  #the circuit closes so button is being pushed
                    if startTime == 0:  #The button is not already being pressed
                        startTime = time.time()
                else:
                    if (not startTime == 0
                        ):  #Button has been pressed and is now released
                        endTime = time.time()
                        deltaTime = endTime - startTime  #Time passed during button press
                        startTime = 0
                        #check length of button push
                        if deltaTime < .15:  #less than 1 second is accidental push
                            #do nothing
                            print("Accidental push")
                        else:
                            raise KeyboardInterrupt

                time.sleep(sleepTime)
                #check if the button has been pushed to skip the rest of wakeup
            except KeyboardInterrupt:  #if the button has been pressed skip to message
                wakingUp = False

        ##end of wake up light code
        sphd.clear()
        sphd.show()
        #start music and show message
        #music
        url = alarmLink
        video = pafy.new(url)
        best = video.getbest()
        playurl = best.url

        media = vlc.MediaPlayer(playurl)
        media.play()

        sphd.write_string(msg + " ")
        print(msg)
        #continously show message
        sphd.set_brightness(0.2)
        cont = True
        while cont:
            try:
                sphd.show()
                sphd.scroll(1)

                #button code
                if not GPIO.input(
                        buttonPin
                ):  #the circuit closes so button is being pushed
                    if startTime == 0:  #The button is not already being pressed
                        startTime = time.time()

                else:
                    if (not startTime == 0
                        ):  #Button has been pressed and is now released
                        endTime = time.time()
                        deltaTime = endTime - startTime  #Time passed during button press
                        startTime = 0
                        #check length of button push
                        if deltaTime < .15:  #less than 1 second is accidental push
                            #do nothing
                            print("Accidental push")
                        else:
                            raise KeyboardInterrupt

                time.sleep(sleepTime)
            except KeyboardInterrupt:
                cont = False
                #stop music
                media.stop()

        #clear led board
        sphd.clear()
        sphd.show()
        GPIO.cleanup()
        #send email to user if one was given
        if receiver_email != 'none':
            smtp_server = "smtp.gmail.com"
            port = 587  # For starttls
            sender_email = "*****@*****.**"
            password = "******"

            # Create a secure SSL context
            context = ssl.create_default_context()

            # Try to log in to server and send email
            try:
                server = smtplib.SMTP(smtp_server, port)
                server.ehlo()  # Can be omitted
                server.starttls(context=context)  # Secure the connection
                server.ehlo()  # Can be omitted
                server.login(sender_email, password)
                #message that tells user the person woke up
                message = MIMEMultipart("alternative")
                message["Subject"] = "The Pi woke them up at " + str(
                    datetime.datetime.now().time())
                message["From"] = sender_email
                message["To"] = receiver_email
                msgText = """\
                They should feel well rested now thanks to the song and time you chose"""
                messageBody = MIMEText(msgText, "plain")
                message.attach(messageBody)
                server.sendmail(sender_email, receiver_email,
                                message.as_string())
            except Exception as e:
                # Print any error messages to stdout
                print(e)
            finally:
                server.quit()
Exemple #18
0
# check it works - light every pixel

for x in range(17):
    for y in range(7):
        sphd.set_pixel(x, y, 0.25)
sphd.show()
time.sleep(0.5)
sphd.clear()
sphd.show()

# read string from website
link = "https://raw.githubusercontent.com/iain-t-bennett/scrollbot/master/example3.msg"
f = requests.get(link)

msg = f.text
# add blank space so no immediate repeat
msg = msg + '         '

sphd.write_string(msg)
sphd.set_brightness(0.25)

# assume 4 pixels per char then add 17 for width of display
while True:
    # assume 4 pixels per char then add 17 for width of display
    for x in range(len(msg) * 4 + 17):
        sphd.show()
        sphd.scroll(1)
        time.sleep(0.05)

# end of script
def clock():
    scrollphathd.clear()
    scrollphathd.write_string(time.strftime("%H:%M"), x=0, y=1, font=font3x5, letter_spacing=1, brightness=BRIGHTNESS)
    scrollphathd.show()
Exemple #20
0
import scrollphathd
from scrollphathd.fonts import font5x7

print("""
Scroll pHAT HD: Hello World

Scrolls "Hello World" across the screen
in a 5x7 pixel large font.

Press Ctrl+C to exit!

""")

#Uncomment to rotate the text
#scrollphathd.rotate(180)

#Set a more eye-friendly default brightness
scrollphathd.set_brightness(0.1)

scrollphathd.write_string("Hello World! ",
                          x=0,
                          y=0,
                          font=font5x7,
                          brightness=0.5)

while True:
    scrollphathd.show()
    scrollphathd.scroll()
    time.sleep(0.05)
def date():
    scrollphathd.clear()
    scrollphathd.write_string(time.strftime("%d"), x=0, y=1, font=font3x5, letter_spacing=1, brightness=BRIGHTNESS)
    scrollphathd.fill(BRIGHTNESS, x=8, y=0, width=1, height=7)
    scrollphathd.write_string(time.strftime("%m"), x=10, y=1, font=font3x5, letter_spacing=1, brightness=BRIGHTNESS)
    scrollphathd.show()
Exemple #22
0
            # Subtract 1 now we've drawn that pixel
            seconds_progress -= 1

            # If we reach or pass 0, there are no more pixels left to draw
            if seconds_progress <= 0:
                break

    else:
        # Just display a simple dot
        scrollphathd.set_pixel(int(seconds_progress), 6, BRIGHTNESS)

    # Display the time (HH:MM) in a 5x5 pixel font
    scrollphathd.write_string(
        time.strftime("%H:%M"),
        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!
#prints the contents of test.txt into Scroll pHat HD, remember to change directory to be valid.
import signal
import time

import scrollphathd

print("""
This should be reading your .txt file
Press Ctrl+C to exit!
""")

# Uncomment the below if your display is upside down
#scrollphathd.rotate(degrees=180)

scrollphathd.write_string('  ' + ''.join(file('/home/pi/test.txt')),
                          brightness=0.5)

# Auto scroll using a while + time mechanism (no thread)
while True:
    # Show the buffer
    scrollphathd.show()
    # Scroll the buffer content
    scrollphathd.scroll()
    # Wait for 0.1s
    time.sleep(0.1)
lines = [
    "In the old #BILGETANK we'll keep you in the know",
    "In the old #BILGETANK we'll fix your techie woes",
    "And we'll make things", "And we'll break things",
    "'til we're altogether aching",
    "Then we'll grab a cup of grog down in the old #BILGETANK"
]

lengths = [0] * len(lines)

offset_left = 0

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

scrollphathd.set_pixel(0, (len(lines) * line_height) - 1, 0)

current_line = 0

scrollphathd.show()

while True:
    pos_x = 0
    pos_y = 0
    for current_line in range(len(lines)):
        time.sleep(delay * 10)
        for y in range(lengths[current_line]):
Exemple #25
0
 def show_string(self, this_program, text):
     scrollphathd.write_string(text, brightness=BRIGHTNESS)
     while self.program == this_program and not self._got_stop_event():
         scrollphathd.show()
         scrollphathd.scroll()
         time.sleep(SCROLL_TEXT_RATE_MS / 1000)
Press Ctrl+C to exit!

""")

# 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)

# Set a more eye-friendly default brightness
scrollphathd.set_brightness(0.5)

# Write the string to scroll
scrollphathd.write_string(" Hello World! ",
                          x=0,
                          y=1,
                          font=font3x5,
                          brightness=1.0)


def draw_static_elements(buf):
    # Buf is given as a two dimensional array of elements buf[x][y]
    # This method will blink a frame of alternating lights around
    # our scrolling text twice a second.

    if int(time.time() * 2) % 2 == 0:
        for x in range(scrollphathd.DISPLAY_WIDTH):
            if x % 2 == 0:
                buf[x][0] = 1.0
                buf[x][scrollphathd.DISPLAY_HEIGHT - 1] = 1.0
Exemple #27
0
#scrollphathd.rotate(180)

while True:
    string = ''
    pos = 0
    for currency in currencies:

        url = 'https://www.bitstamp.net/api/v2/ticker/%s/' % currency
        #print(url)
        data = json.load(urllib.urlopen(url))
        print(data)

        string += '%s ' % symbol[pos]
        string += u'$%s' % data['last'] + '   '
        pos += 1

    for i in range(3):
        scrollphathd.clear()
        #print(string)
        buffer = scrollphathd.write_string(string,
                                           x=17,
                                           y=0,
                                           font=font5x5,
                                           brightness=0.2)
        for c in range(buffer):
            scrollphathd.show()
            scrollphathd.scroll(1)
            time.sleep(0.05)

    sleep(20)
Exemple #28
0
def run():

    start = 0
    end = 0
    countdown_running = False
    finish_countdown = False

    while True:
        # Check if there's any HTTP actions
        if (api_queue.qsize() > 0):
            action = api_queue.get(block=True)
            print(action.action_type)

            if action.action_type == "start":
                cleanup()

                # 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
                countdown_running = True
                finish_countdown = False

            if action.action_type == "clear":
                cleanup()
                countdown_running = False
                finish_countdown = False

            if action.action_type == "stop":
                countdown_running = False
                finish_countdown = False

        if countdown_running:
            if end > time.time():
                now = time.time()
                delta_t = end - now
                secs = int(delta_t)

                text = datetime.fromtimestamp(delta_t).strftime("%M:%S")
                scrollphathd.clear()
                # 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)

            else:
                print("Finished countdown")
                countdown_running = False
                finish_countdown = True
                scrollphathd.clear()
                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
                )

        if finish_countdown:
            scrollphathd.scroll()

        # 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)
Exemple #29
0
        # this response also contains rich geo-location data
        ip = json_data['ip']
    return ip

def get_ip(mode):
    return get_public_ip() if mode == "public" else get_internal_ip()
#    return mode == "public" ? get_public_ip() : get_internal_ip()
    
address_mode = "public"
if(len(sys.argv) == 2):
    address_mode = sys.argv[1]

ip = get_ip(address_mode)

print(address_mode + " IP Address: " +str(ip))

scrollphathd.set_brightness(0.5)

scrollphathd.write_string("  IP: " + str(ip) + "    ")

while True: 
    try:
	scrollphathd.show()
	scrollphathd.scroll()
        time.sleep(0.05)

    except KeyboardInterrupt:
        scrollphathd.clear()
        sys.exit(-1)
Exemple #30
0
import scrollphathd as sphd
import time
import requests
sphd.rotate(180)

while True:
    try:
        resp = requests.post('http://localhost:3000/minutes')
        minutes = resp.content.decode('utf-8') + 'm'
    except:
        minutes = 'Nanm'
    print(minutes)
    sphd.clear()
    sphd.write_string(minutes, brightness=0.8)
    sphd.show()
    time.sleep(5)
Exemple #31
0
import scrollphathd as sphd
from scrollphathd.fonts import font5x7
import time

sphd.set_brightness(0.5)
sphd.rotate(degrees=180)

sphd.write_string('Shiver me timbers!', font=font5x7)

while True:
    sphd.show()
    sphd.scroll(1)
    time.sleep(0.1)