示例#1
0
    def run(self):
        global current_value
        next_value = 0.0
        scrollphat.set_rotate(True)

        while self.running:

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

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

            string_to_display = curr_value_string + next_value_string

            scrollphat.write_string(string_to_display)
            length = scrollphat.buffer_len()

            for i in range(length):
                scrollphat.scroll()
                time.sleep(0.15)
示例#2
0
    def scroll_message(self):

        time_count_par_sec = 1 / self.lotate_time_sec
        time_count_limit = time_count_par_sec * self.update_time_sec
        time_count = time_count_limit
        while True:
            try:
                if time_count >= time_count_limit:
                    print("")
                    print(" --- Check... ---")
                    time_count = 0
                    if self.get_weather_days(self.check_days):
                        print(" --- Update... ---")
                        self.add_optional_signal_output("start")
                        self.add_get_weather_time_output()
                        self.add_optional_signal_output("end")
                        self.get_weather_info()
                        scrollphat.write_string(self.output)
                        scrollphat.update()
                    else:
                        print(" --- No Update... ---")
                        print("   Updated: " + self.pub_date)
                        print(" --------------------")
                scrollphat.scroll()
                scrollphat.update()
                time.sleep(self.lotate_time_sec)
                time_count += 1

            except KeyboardInterrupt:
                print("\nInterrupted Ctrl + C !!\n")
                return
示例#3
0
 def displayText(text):
     scrollphat.clear()
     scrollphat.write_string(text)
     for i in range(0, scrollphat.buffer_len() - 11):
         scrollphat.scroll()
         sleep(0.1)
     scrollphat.clear()
示例#4
0
 async def poll_queue(self) -> None:
     while True:
         text = await self.queue.get()
         scrollphat.clear()
         scrollphat.write_string(text, 11)
         for _ in range(scrollphat.buffer_len()):
             scrollphat.scroll()
             await asyncio.sleep(self.period)
示例#5
0
def scroll_once(msg):
    scrollphat.write_string(msg, 11)
    length = scrollphat.buffer_len()

    for i in range(length):
        try:
            scrollphat.scroll()
            time.sleep(0.1)
        except KeyboardInterrupt:
            scrollphat.clear()
示例#6
0
def scroll_message_once():
    length = scrollphat.buffer_len()

    for i in range(length):
        try:
            scrollphat.scroll()
            time.sleep(0.1)
        except KeyboardInterrupt:
            scrollphat.clear()
            raise
def display(message):
    if scrollphat_connected:
        scrollphat.clear()
        scrollphat.write_string(message + "       ", 11)
        for i in range(0, scrollphat.buffer_len() - 11):
            scrollphat.scroll()
            time.sleep(0.08)
    else:
        print(message)
        time.sleep(0.1)
    def scroll(self, string=TEST_STRING):

        self.show_str(string)

        length = scrollphat.buffer_len()

        for i in range(length):

            scrollphat.scroll()
            sleep(0.1)
示例#9
0
文件: main.py 项目: recantha/scroller
def display(message):
    if scrollphat_connected:
        scrollphat.clear()
        scrollphat.write_string(message + "       ", 11)
        for i in range(0, scrollphat.buffer_len() - 11):
            scrollphat.scroll()
            time.sleep(0.08)
    else:
        print(message)
        time.sleep(0.1)
示例#10
0
def scrollText(text):
    """Scroll some text on the display once"""
    print("Displaying text: " + text)
    scrollphat.clear()
    # Write the text to the display, the extra space is to make scrolling look better.
    length = scrollphat.write_string("   " + text)
    for i in range(length - matrix_length):
        scrollphat.scroll()
        time.sleep(0.1)
    scrollphat.clear()
示例#11
0
async def poll_queue() -> None:
    if not HAS_SCROLLPHAT:
        return

    while True:
        text = await QUEUE.get()
        scrollphat.clear()
        scrollphat.write_string(text, 11)
        for _ in range(scrollphat.buffer_len()):
            scrollphat.scroll()
            await asyncio.sleep(1 / SPEED)
示例#12
0
def print_tweet(tweet):
    scrollphat.clear()
    scrollphat.set_brightness(7)
    scrollphat.write_string(tweet)
    x = 0
    # scroll the message twice
    while x < (scrollphat.buffer_len()*2):
        scrollphat.scroll()
        sleep(0.1)
        x += 1
    scrollphat.clear()
示例#13
0
def scroll_message(output):
    scrollphat.write_string(output)
    scrollphat.update()

    while (True):
        try:
            scrollphat.scroll()
            scrollphat.update()
            time.sleep(0.2)
        except KeyboardInterrupt:
            return
示例#14
0
def scroll_message(output):
    scrollphat.write_string(output)
    scrollphat.update()

    while(True):
        try:
            scrollphat.scroll()
            scrollphat.update()
            time.sleep(0.2)
        except KeyboardInterrupt:
            return
示例#15
0
def test_scrollphat():
    import scrollphat
    scrollphat.set_brightness(2)

    scrollphat.write_string("BOOZER", 11)
    length = scrollphat.buffer_len()

    for i in range(length):
        try:
            scrollphat.scroll()
            time.sleep(0.1)
        except KeyboardInterrupt:
            scrollphat.clear()
            sys.exit(-1)
示例#16
0
    def textScroll(self, text):
        '''Displays a text at the scroll-pHAT'''

        if self.args.verbose:
            print('Running Twitter.textScroll, text: %s' % text)

        scrollphat.write_string(text, 11)
        length = scrollphat.buffer_len()

        for i in range(length):
            try:
                scrollphat.scroll()
                time.sleep(self.args.pause_text_scroll)
            except KeyboardInterrupt:
                scrollphat.clear()
                sys.exit(-1)
  def run(self):
    global currency_value
    next_value = 0.0
    while running:

      curr_value_string = "{:7.2f}".format( round( next_value,      2 ) ) + self.symbol + " "
      next_value_string = "{:7.2f}".format( round( currency_value,  2 ) ) + self.symbol + " "

      next_value = currency_value

      string_to_display = curr_value_string + next_value_string

      scrollphat.write_string( string_to_display )
      string_length = self.count_letters( curr_value_string )
      for _ in range( string_length ):
        scrollphat.scroll()
        time.sleep(0.1)
示例#18
0
文件: r2d2.py 项目: jaygit/r2d2_clock
def led_status(buttonPin):
	global option, RED, YELLOW, BLUE, GREEN, LED
	if GPIO.input(buttonPin) == GPIO.HIGH:

		print ("LED OFF")
	else:
		print ("LED ON")
		time_hour = int(strftime("%H", time.localtime()))
		say_greeting(time_hour)
		if option == 1:
			LED = GREEN
			current = say_clock()
			cur_time = strftime("%H:%M", time.localtime())

			current =  cur_time + "     " + current

		elif option == 2:
			LED=RED
			current = say_date()

		elif option == 3:
			LED = YELLOW
			current = say_weather() 

		print current

		scrollphat.set_brightness(4)
		while True:
		    try:
			GPIO.output(LED, GPIO.HIGH)
			scrollphat.write_string(current ) 
			scrollphat.scroll()
			time.sleep(0.1)
			GPIO.output(LED, GPIO.LOW)
			if GPIO.input(buttonPin) == GPIO.HIGH:
				raise KeyboardInterrupt()
		    except KeyboardInterrupt:
			play_sound("stop")
			scrollphat.clear()
			GPIO.output(LED, GPIO.LOW)
			option += 1
			if option > 3:
				option = 1

			return
    def draw(self, game):

        text = game.get_scroller_text()

        if text != '':

           scrollphat.write_string(text)
           scrollphat.scroll()
           time.sleep(0.06)

        else:

            scrollphat.clear()

            for x, y in game.get_pixels():
                pixel = int(x), int(y)
                scrollphat.set_pixel(pixel[0], pixel[1], 1)

            scrollphat.update()
示例#20
0
    def run(self):
        global currency_value
        next_value = 0.0
        while running:

            curr_value_string = "{:7.2f}".format(round(next_value,
                                                       2)) + self.symbol + " "
            next_value_string = "{:7.2f}".format(round(currency_value,
                                                       2)) + self.symbol + " "

            next_value = currency_value

            string_to_display = curr_value_string + next_value_string

            scrollphat.write_string(string_to_display)
            string_length = self.count_letters(curr_value_string)
            for _ in range(string_length):
                scrollphat.scroll()
                time.sleep(0.1)
示例#21
0
 def on_success(self, data):
     if 'text' in data:
         h = HTMLParser.HTMLParser()
         user = data['user']['screen_name'].encode('utf-8')
         raw_tweet = h.unescape(data['text'])
         tweet = self.remove_link('     @{}: {}'.format(user.encode('utf-8'), raw_tweet.encode('utf-8')))
         if enable_scrollphat == True:
             scrollphat.write_string(tweet.upper())
             status_length = scrollphat.buffer_len()
             while status_length > 0:
                 scrollphat.scroll()
                 time.sleep(0.1)
                 status_length -= 1
             scrollphat.clear()
         else:
             try:
                 # i can't figure out how to print things reliably on windows with this crapping itself
                 print unicode(tweet).encode('ascii')
             except:
                 print '     @{}: Could not display tweet'.format(user.encode('utf-8'))
示例#22
0
 def on_success(self, data):
     if 'text' in data:
         h = HTMLParser.HTMLParser()
         user = data['user']['screen_name'].encode('utf-8')
         raw_tweet = h.unescape(data['text'])
         tweet = self.remove_link('     @{}: {}'.format(
             user.encode('utf-8'), raw_tweet.encode('utf-8')))
         if enable_scrollphat == True:
             scrollphat.write_string(tweet.upper())
             status_length = scrollphat.buffer_len()
             while status_length > 0:
                 scrollphat.scroll()
                 time.sleep(0.1)
                 status_length -= 1
             scrollphat.clear()
         else:
             try:
                 # i can't figure out how to print things reliably on windows with this crapping itself
                 print unicode(tweet).encode('ascii')
             except:
                 print '     @{}: Could not display tweet'.format(
                     user.encode('utf-8'))
示例#23
0
  while True:
    my_delta = datetime.datetime(year=YEAR,month=1,day=1,hour=0,minute=0) - datetime.datetime.now()
    days_left = math.floor(my_delta.days + (my_delta.seconds/86400))
    hours_left = math.ceil((my_delta.days * 24) + (my_delta.seconds/3600))
    minutes_left = math.ceil((my_delta.days * 24 * 60) + (my_delta.seconds/60))
    seconds_left = math.ceil((my_delta.days * 24 * 3600) + my_delta.seconds)
    if hours_left >= 55:
      count_string = '{0}D'.format(days_left)
    elif minutes_left >= 60:
      count_string = '{0}H'.format(hours_left)
    elif seconds_left >= 60:
      count_string = '{0}M'.format(minutes_left)
    else:
      count_string = '{0}S'.format(seconds_left)
    if count_string != last_time:
      scrollphat.clear_buffer()
      for i in range(11):
        scrollphat.scroll()
        time.sleep(0.01)
      scrollphat.clear_buffer()
      scrollphat.write_string(count_string, 11)
      for i in range(scrollphat.buffer_len()-12):
        scrollphat.scroll()
        time.sleep(0.05)
      last_time = count_string
      time.sleep(0.2)

except KeyboardInterrupt:
  scrollphat.clear()
  sys.exit(-1)
示例#24
0
 def scroll_graph(self, length):
     for i in range(length):
         scrollphat.scroll()
         self.sleep_interval()
示例#25
0
def main(win):
    direction = "RIGHT"
    snakeX=[2, 1, 0]
    snakeY=[2, 2, 2]
    snakeLength = 3
    score = 0

    gameOver = False
    
    scrollphat.set_brightness(5)
    scrollphat.write_string("      PI SNAKE")
    length = scrollphat.buffer_len()

    for i in range(length):
        scrollphat.scroll()
        time.sleep(0.06)
            
    fruitX = random.randint(0,10)
    fruitY = random.randint(0,4)

    fruitBlink = True

    win.nodelay(True)
    key=""
    while 1:
        if gameOver == False:

            # move snake head forward in the direction its travelling
            if direction == "RIGHT":
                if snakeX[0] < 10:
                    snakeX[0] = snakeX[0] + 1
            if direction == "LEFT":
                if snakeX[0] > 0:
                    snakeX[0] = snakeX[0] - 1
            if direction == "UP":
                if snakeY[0] > 0:
                    snakeY[0] = snakeY[0]- 1
            if direction == "DOWN":
                if snakeY[0] < 4:
                    snakeY[0] = snakeY[0] + 1
                    
            # check if the new head position is illegal
            for i in range(1, snakeLength):
                if snakeX[i] == snakeX[0] and snakeY[i] == snakeY[0]:
                    gameOver = True
                    
            # check if the new head position is at a fruit
            if snakeX[0] == fruitX and snakeY[0] == fruitY:
                snakeLength = snakeLength + 1
                score = score + 1
                snakeX.append(fruitX)
                snakeY.append(fruitY)
                fruitX = random.randint(0,10)
                fruitY = random.randint(0,4)

            time.sleep(0.15)
            scrollphat.clear_buffer()

            # shift all the snake parts forward
            for i in range(1, snakeLength):
                snakeX[snakeLength - i] = snakeX[snakeLength - i - 1]
                snakeY[snakeLength - i] = snakeY[snakeLength - i - 1]

            # draw the snake
            for i in range(0, snakeLength):                                                  
                scrollphat.set_pixel(snakeX[i],snakeY[i],True)

            # blink the fruit
            if fruitBlink:
                scrollphat.set_pixel(fruitX,fruitY,True)
                fruitBlink = False
            else:
                scrollphat.set_pixel(fruitX,fruitY,False)
                fruitBlink = True
                
            scrollphat.update()
        else:
            # game over
            gameOverText = "GAME OVER - SCORE: " + str(score) + " PRESS SPACE TO RESTART"
            time.sleep(0.7)
            scrollphat.clear_buffer()
            scrollphat.write_string(gameOverText,len(gameOverText))
            win.clear()
            win.addstr(gameOverText)
            while True:
                try:
                    scrollphat.scroll()
                    time.sleep(0.07)
                    key = win.getkey()
                    if str(key) == " ":
                        break
                except Exception as e:
                    # No input
                    pass
            direction = "RIGHT"
            snakeX=[2, 1, 0]
            snakeY=[2, 2, 2]
            snakeLength = 3
            score = 0
            gameOver = False

        try:
           key = win.getkey()
           win.clear()
           win.addstr("PI SNAKE - SCORE: ")           
           win.addstr(str(score))
           
           if str(key) == "KEY_RIGHT":
               direction = "RIGHT"
           if str(key) == "KEY_LEFT":
               direction = "LEFT"
           if str(key) == "KEY_UP":
               direction = "UP"
           if str(key) == "KEY_DOWN":
               direction = "DOWN"
               
           if key == os.linesep:
              break
        except Exception as e:
           # No input
           pass
def scroll():
    while True:
        scrollphat.scroll()
        time.sleep(0.1)
示例#27
0
def update_display(text):
    scrollphat.write_string(text + " | ")
    scrollphat.scroll(delta=3)
示例#28
0
 def scroll_string(self):
     self.thread_running = True
     while self.thread_running:
         scrollphat.scroll()
         time.sleep(0.1)
def scroll():
    while True:
        scrollphat.scroll()
        time.sleep(0.1)
示例#30
0
		num_w = display_str.count('W')
		neg = display_str.count('-')
                # Each letter takes 4 LEDs to display (including trailing space)
                # -1 because the degree symbol only takes 2 LEDs
		# -1 because colon symbol only takes 2 LEDs
		# -2 for each space added to string
                # -11 because they are shown before we need to scroll
                # -1 because there's no trailing space after last letter
		scroll_len = len(display_str)*4 - 1 - 1 - 4 - 11 - 1 + 2*(num_m+num_w) - 1*neg

		s.clear()
		s.write_string(display_str)
		t.sleep(1)
		for i in range(scroll_len):
			t.sleep(0.08)
			s.scroll()
		t.sleep(0.5)

                # Update the weather forecast every 5 minutes
		if ((t.time() - start_time) > 5*60):
			try:
				forecast = f.load_forecast(api_key, lat, lng, units='si')
				current_forecast = forecast.currently()
			except:
				pass
			start_time = t.time()
			print(t.asctime()[11:-5], '\r')

	except KeyboardInterrupt:
		s.clear()
		break
示例#31
0
        neg = display_str.count('-')
        # Each letter takes 4 LEDs to display (including trailing space)
        # -1 because the degree symbol only takes 2 LEDs
        # -1 because colon symbol only takes 2 LEDs
        # -2 for each space added to string
        # -11 because they are shown before we need to scroll
        # -1 because there's no trailing space after last letter
        scroll_len = len(display_str) * 4 - 1 - 1 - 4 - 11 - 1 + 2 * (
            num_m + num_w) - 1 * neg

        s.clear()
        s.write_string(display_str)
        t.sleep(1)
        for i in range(scroll_len):
            t.sleep(0.08)
            s.scroll()
        t.sleep(0.5)

        # Update the weather forecast every 5 minutes
        if ((t.time() - start_time) > 5 * 60):
            try:
                forecast = f.load_forecast(api_key, lat, lng, units='si')
                current_forecast = forecast.currently()
            except:
                pass
            start_time = t.time()
            print(t.asctime()[11:-5], '\r')

    except KeyboardInterrupt:
        s.clear()
        break
#!/usr/bin/env python

import scrollphat as sp
import sys, time, random, math
from random import randint

sp.set_rotate(False)
sp.set_brightness(50)

lines = open('/home/pi/Pimoroni/scrollphat/my_scrolls/boomkat_output_file').read().splitlines()

#while True:
try:        
    line_to_scroll = random.choice(lines)
    sp.write_string("      " + line_to_scroll + "     ")
    string_length = sp.buffer_len()
    while string_length > 0:
        sp.scroll()
        time.sleep(0.065)
        string_length -= 1
except KeyboardInterrupt:
    sp.clear()
    sys.exit(-1)

示例#33
0
scrollphat.set_rotate(
    True
)  #to sit the zero flat with the usb cable on the top you have to set this as true to rotate the message

while True:
    now = datetime.datetime.now()
    print(now.strftime("%Y-%m-%d %H:%M:&S"))
    birthday = datetime.datetime(
        YYYY, M, D, 0, 0
    )  #replace this with the day you want to use - time not important for this application
    print(birthday.strftime("%Y-%m-%d %H:%M:&S"))
    delta = birthday - now
    print(delta.days)
    #cause we're doing sleeps need +1
    if delta.days + 1 < 1:
        message = "Happy birthday Phina!!!   "
        scroll_delta = 1
    else:
        message = str(delta.days + 1)
        scroll_delta = 0  #because days is a short message don't need to scroll it
    print(message)
    scrollphat.write_string(message)
    length = scrollphat.buffer_len()
    for i in range(length):
        try:
            scrollphat.scroll(delta=scroll_delta)
            time.sleep(0.1)
        except KeyboardInterrupt:
            scrollphat.clear()
            sys.exit(-1)
示例#34
0
文件: scrolljob.py 项目: ollej/piapi
 def scroll(self):
     scrollphat.scroll()
     self.sleep_interval()
sp.set_rotate(True)
sp.set_brightness(10)

lines = open('text_to_scroll.txt').read().splitlines()

#while True:
#   try:
myline = random.choice(lines)
spacer = "   -   "
random_spacer = randint(3, 5)
random_spacer_length = len(spacer) * random_spacer
text_length = len(myline)

sp.write_string((spacer * random_spacer) + random.choice(lines) +
                (spacer * random_spacer))

length = (text_length + (random_spacer_length * 2) * 5
          )  # pixels to scroll, in total.
print length

for x in range(0, length):
    try:
        sp.scroll()
        time.sleep(0.075)
    except KeyboardInterrupt:
        sp.clear()
        sys.exit(-1)

print "finished"
示例#36
0
        if "ROUTING TABLE" in line:
            break
        else:
            userlist = (line.split(","))
            name = userlist[0]
            connect_time = userlist[4].replace("\n", "")
            connect_time = datetime.strptime(connect_time, '%c')
            time_now = datetime.now()
            connected = time_now - connect_time
            connected = str(connected).split('.', 2)[0]
            msg += (name.upper() + " SESSION TIME: " + connected + " ")

    vpnlog.close()

    scrollphat.set_brightness(25)
    scrollphat.write_string(msg, 11)
    length = scrollphat.buffer_len()

    for i in range(length):  # for one off's
        try:
            scrollphat.scroll(1)
            time.sleep(0.06)
            msg = " "
        except KeyboardInterrupt:
            scrollphat.clear()
            sys.exit(-1)

    # clear the phat buffer and sleep for 30 seconds
    scrollphat.clear()
    time.sleep(30)
        def get_day_sufx(dNum):        # Work out "st", "nd", "rd" or "th"
            if dNum == ("1","21","31"):
                return "st"
            if dNum == ("2","22"):
                return "nd"
            if dNum == ("3","23"):
                return "rd"
            else:
                return "th"

        sufx = get_day_sufx(dNum)   # Run above, supply date, create suffix
        dNam = time.strftime("%A")  # Day name
        mnth = time.strftime("%B")  # Month name (full)
        year = time.strftime("%Y")  # Year (4 digits)
        hour = time.strftime("%H")  # Hours (24 hours)
        mins = time.strftime("%M")  # Minutes
        secs = time.strftime("%S")  # Seconds

        # Assemble all the variables into a single string
        assembled = " " + dNam + " " + dNum + sufx + " " + mnth + " " + year + "    " + hour + ":" + mins + ":" + secs + "    "

        scrollphat.set_brightness(10)      # Readable brightness?
        scrollphat.write_string(assembled) # Create the string for the pHAT
        scrollphat.scroll()                # Scroll the string
        time.sleep(0.1)                    # Control the speed

    except KeyboardInterrupt: # Stop script if "Ctrl+C" is pressed
        scrollphat.clear()    # Clear pHAT display before exiting
        sys.exit(-1)
示例#38
0
        json_data = json.loads(res.text)

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

scrollphat.set_brightness(3)

while True:	
    try:
        scrollphat.clear()
        scrollphat.write_string("IP: " + str(ip) + "    ")
        for i in range(0, scrollphat.buffer_len() - 11):
            scrollphat.scroll()
            time.sleep(0.1)
    except KeyboardInterrupt:
        scrollphat.clear()
        sys.exit(-1)
示例#39
0
def show_text(text: str, speed: float = 20):
    scrollphat.write_string(text, 11)
    for _ in range(scrollphat.buffer_len()):
        scrollphat.scroll()
        time.sleep(1 / speed)
    scrollphat.clear()