def countdown(self): scrollphathd.set_brightness(0.5) scrollphathd.rotate(0) # 3 - 2 - 1 scrollphathd.clear() scrollphathd.write_string('3', x=6, y=0, font=font5x7) scrollphathd.show() time.sleep(0.75) scrollphathd.clear() scrollphathd.show() time.sleep(0.25) scrollphathd.clear() scrollphathd.write_string('2', x=6, y=0, font=font5x7) scrollphathd.show() time.sleep(0.75) scrollphathd.clear() scrollphathd.show() time.sleep(0.25) scrollphathd.clear() scrollphathd.write_string('1', x=7, y=0, font=font5x7) scrollphathd.show() time.sleep(0.75) scrollphathd.clear() scrollphathd.show() time.sleep(0.25) return
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)
def __init__(self, host="localhost"): self.subscribed_topic2method = { "scrolly/write_scroll": self.write_scroll, "scrolly/write": self.write, "scrolly/power": self.power, "scrolly/brightness": self.set_brightness } scroll.flip(x=True, y=True) scroll.set_brightness(0.2) scroll.clear() scroll.write_string("on") scroll.show() status_topic = "scrolly/status" self.mos = mosquitto.Mosquitto() self.mos.will_set(status_topic, "offline") self.mos.on_message = self.on_message self.debug("connecting to " + host) self.mos.connect(host) self.mos.publish("scrolly/power", 1) self.mos.publish(status_topic, "online") self.mos.subscribe("scrolly/#") self.stop_event = threading.Event() # start thread that is waiting for action in bluedot app th = threading.Thread(target=self._shutdown_on_bluedot_press_waiter) th.start() self.mos.loop_forever()
def gol(): iterations = 0 while True: # process runs until manually killed # the update_life method creates a new life sequence and returns repeating if sequence is repeating. # if we have a repeating sequence, quit current game, and start new game game = Life(17, 7) # create a new game with the size of the LED screen # print('new game created') # see if it is dark outside to set the default brightness if s['sunrise'].replace(tzinfo=None) < datetime.datetime.now() < s['sunset'].replace(tzinfo=None): # print('daytime') sphd.set_brightness(0.25) # set a default brightness at 25% else: # print('nighttime') sphd.set_brightness(0.1) # set a default brightness at 10% while game.update_life() == 'unique': # keeps looping as long as no repeating patterns # print_grid(game.life) display_life(game.life) # send the current game to display on the LED screen time.sleep(.5) # leave the display for a split second before refreshing # display the stats for each game before starting a new game. if game.update_life() == 'repeating': # end of game, patterns are now repeating display_scroll_text('Current game iteration was {}'.format(game.iteration), 5) if game.iteration > iterations: iterations = game.iteration display_scroll_text('Highest game iterations were {}'.format(iterations), 5) time.sleep(1)
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)
def endrec(self): scrollphathd.set_brightness(0.5) scrollphathd.rotate(0) scrollphathd.clear() scrollphathd.write_string('ok', x=3, y=0) scrollphathd.show() return
def graphAnim(): sphd.set_brightness(0.2) sphd.set_graph(values, 3, 7, 1.0, 0, 0, 17, 6) sphd.show() for index in range(0, 17): changeValue(index) time.sleep(0.008)
def scroll_life(delay): def count_neighbours(ibuf, i, j): tot=0 for x,y in ((-1,-1), (-1,0), (-1,1), ( 0,-1) , (0,1), (+1,-1), (+1,0), (+1,1)): ix=(i+x)%11 jy=(j+y)%5 tot+=ibuf[ix][jy] return tot def buffer(ibuf): return [ibuf2buf[tuple(v)] for v in ibuf] def rand_ibuf(): return [[(random.random()>0.8)+0 for j in range(5)] for i in range(11)] def glider_ibuf(): return [[0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,1,0,0], [0,1,0,0,0], [0,1,1,1,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0]] ibuf=rand_ibuf() ibuf2buf={(i,j,k,l,m): (i<<0)+(j<<1)+(k<<2)+(l<<3)+(m<<4) for i in (0,1) for j in (0,1) for k in (0,1) for l in (0,1) for m in (0,1)} samecount=0 while True: ibufbuf=copy.deepcopy(ibuf) for i in range(11): for j in range(5): c=count_neighbours(ibufbuf, i, j) if ibuf[i][j]: if c in (0,1,4,5,6,7): ibuf[i][j]=0 else: if c in (3,): ibuf[i][j]=1 buf=buffer(ibuf) scrollphathd.set_brightness(0.5) scrollphathd.write_string(buf) scrollphathd.show() scrollphathd.clear() time.sleep(delay) if ibufbuf==ibuf: samecount+=1 if samecount>20: ibuf=rand_ibuf()
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 screenFlash(): i = 1 while i <= 5: sphd.fill(1, 0, 0, 17, 7) sphd.set_brightness(1) sphd.show() time.sleep(0.2) screenClear() i = i + 1
def main(): scrollphathd.set_brightness(0.5) scrollphathd.rotate(180) scrollphathd.clear() countdown(datetime.datetime(2018, 12, 16, 18, 0, 0)) scrollMessage(" KNALLEN!!! ") countdown(datetime.datetime(2018, 12, 18, 18, 0, 0)) scrollMessage(" STOPPEN!!! ")
def __init__(self): super(LedManager, self).__init__(target=self._loop) leds.rotate(180) leds.clear() leds.set_brightness(0.2) self.daemon = True self.scroll_remaining = 0 self.phrases = [] self.start()
def show(self): for w in range(self.width): for h in range(self.height): if self.pixels[w][h]: sphd.set_pixel(w, h, self.pixels[w][h].get_brightness()) else: sphd.set_pixel(w, h, 0) sphd.set_brightness(0.1) sphd.show()
def _start(self): """ @see Notifier._start() """ # Turn it up etc. scrollphathd.set_brightness(self._brightness) # The thread which will maintain the display thread = Thread(target=self._updater) thread.deamon = True thread.start()
def __init__(self): super(OutputScrollPhatHD, self).__init__() self.running = False self.busy = False scrollphathd.set_brightness(0.5) self.messages = queue.Queue() self._thread = threading.Thread(target=self.run_messages) self._thread.daemon = True self._thread.start()
def recblink(self): scrollphathd.set_brightness(0.15) scrollphathd.rotate(0) for i in range(5): scrollphathd.clear() scrollphathd.write_string('REC', x=0, y=0) scrollphathd.show() time.sleep(0.7) scrollphathd.clear() scrollphathd.show() time.sleep(0.3) return
def display_text(text): sphd.clear() sphd.show() timeout = time.time() + 30 sphd.write_string(text) sphd.set_brightness(1) while time.time() < timeout: sphd.show() sphd.scroll(1) time.sleep(0.1) sphd.clear() sphd.show()
def clockVert(self): scrollphathd.set_brightness(0.3) scrollphathd.rotate(270) scrollphathd.clear() # Ore scrollphathd.write_string(time.strftime("%H"), x=0, y=0, font=font5x5) # Minuti scrollphathd.write_string(time.strftime("%M"), x=0, y=6, font=font5x5) # Secondi scrollphathd.write_string(time.strftime("%S"), x=0, y=12, font=font5x5) scrollphathd.show() return
def cleanup(): if utf8.is_active(): utf8.terminate() if plasma.is_active(): plasma.terminate() if message.is_active(): message.terminate() scrollphathd.set_brightness(BRIGHTNESS) scrollphathd.set_font(font5x7) scrollphathd.clear() scrollphathd.show()
def LEDmessage(self, txtMessage, loop=False): self.DisplayOff() scrollphathd.rotate(0) scrollphathd.clear() scrollphathd.set_brightness(0.5) scrollphathd.write_string(txtMessage, x=18, y=0, font=font5x7) if loop == True: self.textMessageDisplay = True self.LEDscrollLeft = 0 else: self.textMessageDisplay = False self.LEDscrollLeft = scrollphathd.get_buffer_shape()[0] #print self.LEDscrollLeft #print self.scrollphathd.get_buffer_shape() scrollphathd.show() self.clockDisplay = False
def on_success(self, data): if 'text' in data: username = data['user']['screen_name'] tweet = data['text'] # print("@{}: {}".format(username, tweet)) # trim special characters out un = re.sub('[^A-Za-z0-9 /:@]+', '', username) twt = re.sub('[^A-Za-z0-9 /:@]+', '', tweet) msg = "@{}: {}".format(un, twt) sphd.write_string(msg) sphd.set_brightness(0.01) # 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)
def display_data(p_data='No Data '): config = get_current_config(silent=True) scrollphathd.rotate(180) scrollphathd.set_brightness(0.3) delay = 0.1 scrollphathd.write_string(config.p_data, x=0, y=0, font=font5x7, brightness=0.5) while True: scrollphathd.show() scrollphathd.scroll() time.sleep(delay)
def clockHor(self): scrollphathd.set_brightness(0.5) scrollphathd.rotate(0) scrollphathd.clear() BRIGHTNESS = 0.7 # prende il resto della divisione per 60 (= secondi) e lo convert nel campo 0.0-15.0 seconds_progress = 15 * ( (time.time() % 60) / 59.0) # ogni pixel sono 4 secondi # barra dei secondi a luminosita' variabile for y in range(15): # 15 = numero di pixel # 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 scrollphathd.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 # 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! # # 1/10th of a second is accurate enough for a simple clock though :D scrollphathd.show() return
def in_lights(input_value='Nothing to see here', scroll_time=10): """ Take a vaule and scroll it on the Pi Phat HD - I assume it is attached! For some reason you might want to scroll a value from your code in all its LED glory... Parameters ---------- input_value : str, int the value to scroll. if its a number this function tries to cast to a str scroll_time : int the length of time in seconds the input_value is scrolled for Returns ------- Nothing is returned - hopefully you see some LED lights scrolling! """ MY_STRING = ' ' + str(input_value) + ' ' t_end = time.time() + scroll_time sphd.write_string(MY_STRING) sphd.set_brightness(0.5) while time.time() < t_end: sphd.show() sphd.scroll(1, 0) sleep(0.05) sphd.clear() sphd.show()
def displayBtcPrice(): screenClear() f = urllib.urlopen("https://api.coindesk.com/v1/bpi/currentprice.json") values = json.load(f) f.close() timeout = time.time() + 30 curFloatPrice = values['bpi']['USD']['rate_float'] if curFloatPrice < 5000: while True: screenFlash() time.sleep(3) print 'Current price in USD: $',str(curFloatPrice) sphd.write_string(' USD ' + "%.2f" % curFloatPrice + " >>") sphd.set_brightness(0.1) while time.time() < timeout: sphd.show() sphd.scroll(1) time.sleep(0.1) screenClear()
def takePhoto(self): self.DisplayOff() scrollphathd.rotate(0) scrollphathd.set_brightness(0.25) #scorre scritta foto scrollphathd.clear() scrollphathd.write_string('foto', x=18, y=0, font=font5x7) scrollphathd.show() buffL = scrollphathd.get_buffer_shape()[0] time.sleep(0.5) for i in range(buffL + 1): scrollphathd.show() scrollphathd.scroll() time.sleep(0.015) # cancella immagine precedente try: os.remove('image.jpg') except OSError: pass self.camera.resolution = (1920, 1080) time.sleep(0.25) self.countdown() # clic (piccolo flash) scrollphathd.clear() scrollphathd.set_brightness(0.7) scrollphathd.fill(1, x=0, y=0, width=17, height=7) #scrollphathd.write_string('c', x= 0, y=0) #scrollphathd.write_string('l', x= 5, y=0) #scrollphathd.write_string('i', x= 9, y=0) #scrollphathd.write_string('c', x=12, y=0) scrollphathd.show() #scatta la foto time.sleep(0.05) scrollphathd.clear() scrollphathd.show() time.sleep(0.15) # scatta la foto self.camera.capture('image.jpg') return
def main(): parser = ArgumentParser() parser.add_argument("-p", "--port", type=int, help="HTTP port.", default=8080) parser.add_argument("-H", "--host", type=str, help="HTTP host.", default="0.0.0.0") args = parser.parse_args() scrollphathd.set_clear_on_exit(False) scrollphathd.set_brightness(0.1) scrollphathd.write_string(str(args.port), font=font3x5, x=1, y=1) scrollphathd.show() app = Flask(__name__) app.register_blueprint(scrollphathd_blueprint, url_prefix="/scrollphathd") app.run(port=args.port, host=args.host)
def hello_monkey(): """Respond to incoming calls with a simple text message.""" newMsg = 1 fromNo = request.form['From'] msgBdy = request.form['Body'] print "From:", fromNo print "Saying:", msgBdy resp = MessagingResponse() resp.message("Message displayed on pi ! You can send a new one now !") screenFlash() sphd.write_string(" " + msgBdy + " >>") sphd.set_brightness(0.5) timeout = time.time() + 60 * 1 - 10 while time.time() < timeout: sphd.show() sphd.scroll(1) time.sleep(0.05) sphd.clear() sphd.show() print str(resp) return str(resp)
def makeVideo(self): self.DisplayOff() scrollphathd.rotate(0) scrollphathd.set_brightness(0.25) #scorre scritta video scrollphathd.clear() scrollphathd.write_string('video', x=18, y=0, font=font5x7) scrollphathd.show() buffL = scrollphathd.get_buffer_shape()[0] time.sleep(0.5) for i in range(buffL + 1): scrollphathd.show() scrollphathd.scroll() time.sleep(0.015) # cancella video precedente try: os.remove('video.h264') except OSError: pass try: os.remove('video.mp4') except OSError: pass self.camera.resolution = (1280, 720) time.sleep(0.25) self.countdown() # registra self.camera.start_recording('video.h264') # lampeggia REC per 5 secondi self.recblink() # fine registrazine self.camera.stop_recording() # scrive ok self.endrec() time.sleep(1) self.DisplayOff()
def main(): scrollphathd.rotate(180) print(""" Overbeautiful clock Press Ctrl+C to exit! """) scrollphathd.set_brightness(0.5) while True: subroutine_anim_picker = pick_next_anim() current_subroutine = next(subroutine_anim_picker) #current_subroutine = display_animated_square() time_displaying = True last_time_changed = math.floor(time.time()) while True: time.sleep(0.05) try: next(current_subroutine) except StopIteration: current_subroutine = next(subroutine_anim_picker) next(current_subroutine)