def show_clock(): # Display a progress bar for seconds # Displays a dot if False BRIGHTNESS = 0.3 while int((time.time() % 60)) not in [20, 40]: phat.clear() float_sec = (time.time() % 60) / 59.0 seconds_progress = float_sec * 15 for y in range(15): current_pixel = min(seconds_progress, 1) phat.set_pixel(y + 1, 6, current_pixel * BRIGHTNESS) seconds_progress -= 1 if seconds_progress <= 0: break phat.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 ) if int(time.time()) % 2 == 0: phat.clear_rect(8, 0, 1, 5) phat.show() time.sleep(0.1)
def showSecondsOnScrollPhatHD(seconds): scrollphathd.clear() float_sec = (seconds % 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) hours = str(int(seconds) / 60 / 60).zfill(2) minutes = str(int(seconds) / 60 % 60).zfill(2) scrollphathd.write_string( hours + ":" + minutes, 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 ) if int(seconds) % 2 == 0: scrollphathd.clear_rect(8, 0, 1, 5) scrollphathd.show()
def on_message(client, userdara, msg): # dim the display before 7am and after 7pm brightness_modifier = 1 if 7 <= datetime.datetime.now( ).hour <= 19 else night_brightness_modifier if msg.topic == MQTT_TOPIC: global pos_x payload = json.loads(msg.payload) print payload["actual_temperature"] last_temperature_received = str(payload["actual_temperature"]) # display height is 7, save the bottom row for the graph scrollphathd.clear_rect(0, 0, None, 6) # None defaults to display size scrollphathd.write_string(last_temperature_received, brightness=0.5 * brightness_modifier, font=font3x5) scrollphathd.show() elif msg.topic == SERVER_LOAD_TOPIC: print msg.payload last_load_received = float(msg.payload) scrollphathd.clear_rect(0, 6, None, 1) # None defaults to disqlay size brightness = 0.5 if last_load_received > 8.0: brightness = 1 last_load_received = 8 load_bar_width = last_load_received / 8.0 * 17 scrollphathd.fill(brightness * brightness_modifier, int(17 - load_bar_width), 6, int(load_bar_width + 1), 1) scrollphathd.show()
def clearArea(): if request.is_json: schema = td["actions"]["clearRect"]["input"] valid_input = Draft6Validator(schema).is_valid(request.json) if valid_input: x = 0 y = 0 w = 17 h = 6 try: x = int(request.json["x"]) except Exception as e: print(e) try: y = int(request.json["y"]) except Exception as e: print(e) try: w = request.json["width"] except Exception as e: print(e) try: h = request.json["height"] except Exception as e: print(e) scrollphathd.clear_rect(x, y, w, h) scrollphathd.show() return "", 204 else: abort(400) print("wrong input") else: abort(415) # Wrong media type.
def progress_show(level, per, prev_x, prev_y): #max value for x in the led display max_x = 11 fix_x = prev_x fix_y = prev_y # get the upper value of the percentage e.g. 4.1 = 5 cal_x = math.ceil(per / 10) #print("Cal_x:",cal_x) if cal_x >= max_x: cal_x = max_x for y in range(fix_y, level, 1): x_limit = max_x if y == level - 1: x_limit = cal_x + 1 if x_limit >= max_x: x_limit = max_x for x in range(fix_x, x_limit): if prev_x != 1 or prev_y != 5: scrollphathd.set_pixel(prev_x, 5 - prev_y, 0.1) scrollphathd.set_pixel(x, 5 - y, 0.3) scrollphathd.clear_rect(x=13, y=1, width=3, height=5) scrollphathd.write_string(str(y + 1), x=13, y=1, font=font3x5, brightness=0.3) scrollphathd.show() time.sleep(0.1) prev_x = x prev_y = y fix_x = 1 return prev_x, prev_y
def largeHeart(b): sph.clear_rect(0, 0, 6, 7) sph.show() sph.set_pixel(0, 0, b / 2) sph.set_pixel(1, 0, b) sph.set_pixel(3, 0, b) sph.set_pixel(4, 0, b / 2) sph.set_pixel(0, 1, b) sph.set_pixel(1, 1, b) sph.set_pixel(2, 1, b) sph.set_pixel(3, 1, b) sph.set_pixel(4, 1, b) sph.set_pixel(0, 2, b) sph.set_pixel(1, 2, b) sph.set_pixel(2, 2, b) sph.set_pixel(3, 2, b) sph.set_pixel(4, 2, b) sph.set_pixel(0, 3, b / 2) sph.set_pixel(1, 3, b) sph.set_pixel(2, 3, b) sph.set_pixel(3, 3, b) sph.set_pixel(4, 3, b / 2) sph.set_pixel(1, 4, b) sph.set_pixel(2, 4, b) sph.set_pixel(3, 4, b) sph.set_pixel(1, 5, b / 2) sph.set_pixel(2, 5, b) sph.set_pixel(3, 5, b / 2) sph.set_pixel(2, 6, b) sph.show()
def sweep(): for x in xrange(sphd.width, 0, -1): sphd.clear_rect(x + 3, 0, 1, sphd.height) sphd.fill(0.01, x + 2, 0, 1, sphd.height) sphd.fill(0.1, x + 1, 0, 1, sphd.height) sphd.fill(0.5, x, 0, 1, sphd.height) sphd.show() time.sleep(0.02)
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)
def printBPM(b, msg): sph.clear_rect(6, 0, 11, 8) sph.write_string(msg, x=6, y=1, font=font3x5, letter_spacing=1, brightness=b) sph.show()
def draw_kr_pulse(pos,dir): # clear 5 pixel line (easier than keeping track of where the previous illuminated pixel was) scrollphathd.clear_rect(12,5,5,1) x = pos + 11 #increase position to the actual x offset we need scrollphathd.set_pixel(x, 5, 0.2) #turn on the current pixel scrollphathd.show() time.sleep(KR_PULSE_DELAY) return;
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)
def sweep(direction=Directions.LEFT, delay=0.02): startx = sphd.width if direction == Directions.LEFT else 0 endx = 0 if direction == Directions.LEFT else sphd.width step = -1 if direction == Directions.LEFT else 1 for x in range(startx, endx, -1): sphd.clear_rect(x + (-3 * step), 0, 1, sphd.height) sphd.fill(0.01, x + (-2 * step), 0, 1, sphd.height) sphd.fill(0.1, x + (-1 * step), 0, 1, sphd.height) sphd.fill(0.5, x, 0, 1, sphd.height) sphd.show() time.sleep(delay)
def smallHeart(b): sph.clear_rect(0, 0, 6, 7) sph.show() sph.set_pixel(1, 1, b) sph.set_pixel(2, 1, b) sph.set_pixel(1, 2, b) sph.set_pixel(2, 2, b) sph.set_pixel(3, 2, b) sph.set_pixel(1, 3, b / 2) sph.set_pixel(2, 3, b) sph.set_pixel(3, 3, b / 2) sph.set_pixel(2, 4, b) sph.show()
def displayTime(first, second): scrollphathd.clear() scrollphathd.write_string( '{:02d}:{:02d}'.format(first, second), x=0, # Align to the left of the buffer y=1, # Align to the top of the buffer font=font5x5, # Use the font5x5 font we imported above brightness=BRIGHTNESS # Use our global brightness value ) if int(time.time()) % 2 == 0: scrollphathd.clear_rect(8, 0, 1, 5) scrollphathd.show() time.sleep(0.1)
def display_time(): scrollphathd.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 # 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 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=font3x5, # 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)
def move(self): if self.cycle == PADDLE_FREQ: sphd.clear_rect(x=self.x ,y=self.y-1 ,width=1, height=3) if GPIO.input(self.pin) == GPIO.HIGH: self.y += 1 if self.y > 7: self.y = 7 else: self.y -= 1 if self.y < -1: self.y = -1 #print(self.pos) self.draw() self.cycle = 0 self.cycle += 1
def display_temp_value(): global actual_str global feels_like_str # clear the old temp reading. If temp > 100 then clear an extra digit's worth of pixels if current_temp < 100: scrollphathd.clear_rect(0, 0, 12, 5) else: scrollphathd.clear_rect(0, 0, 17, 5) if CURRENT_TEMP_DISPLAY == 1: # show actual temp scrollphathd.write_string(actual_str, x = 0, y = 0, font = font3x5, brightness = BRIGHT) else: #show feels_like temp scrollphathd.write_string(feels_like_str, x = 0, y = 0, font = font3x5, brightness = BRIGHT) scrollphathd.show() time.sleep(1) return;
def draw_temp_trend(dir): if dir == 0: #equal - don't display anything. Clear the area where direction arrow is shown scrollphathd.clear_rect(14,0,3,6) elif dir == 1: #increasing = up arrow. Draw an up arrow symbol on the right side of the display for y in range(0,5): scrollphathd.set_pixel(15,y,BRIGHT) #draw middle line of arrow scrollphathd.set_pixel(14,1,BRIGHT) #draw the 'wings' of the arrow scrollphathd.set_pixel(16,1,BRIGHT) elif dir == -1: #decreasing = down arrow for y in range(0,5): scrollphathd.set_pixel(15,y,BRIGHT) #draw middle line of arrow scrollphathd.set_pixel(14,3,BRIGHT) scrollphathd.set_pixel(16,3,BRIGHT) return;
def display_temp_value(description, temp): global actual_str global feels_like_str # clear the old temp reading. If temp > 35 then clear an extra digit's worth of pixels if temp < 35: scrollphathd.clear_rect(0, 0, 12, 5) else: scrollphathd.clear_rect(0, 0, 17, 5) scrollphathd.write_string(description, x=0, y=0, font=font3x5, brightness=BRIGHT) scrollphathd.show() time.sleep(1) return
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 clock(): dur = 7 count = 0 while count < dur * (10): scrollphathd.clear() float_sec = (time.time() % 60) / 59.0 seconds_progress = float_sec * 15 if DISPLAY_BAR: # Step through 15 pixels to draw the seconds 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: # 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, y=0, font=font5x5, brightness=0.3) if int(time.time()) % 2 == 0: scrollphathd.clear_rect(8, 0, 1, 5) scrollphathd.show() scrollphathd.flip(x=True, y=True) time.sleep(0.1) count = count + 1 return "", 204 scrollphathd.clear() scrollphathd.show()
def submit_td(ip_addr, tdd_address): global td td = get_td(ip_addr) print("Uploading TD to directory ...") while True: try: r = requests.post("{}/td".format(tdd_address), json=td) r.close() print("Got response: ", r.status_code) if 200 <= r.status_code <= 299: print("TD uploaded!") return else: print( "TD could not be uploaded. Will try again in 15 Seconds..." ) time.sleep(15) except Exception as e: print(e) print("TD could not be uploaded. Will try again in 15 Seconds...") time.sleep(15) dur = 7 count = 0 while count < dur * (10): scrollphathd.clear() float_sec = (time.time() % 60) / 59.0 seconds_progress = float_sec * 15 if DISPLAY_BAR: # Step through 15 pixels to draw the seconds 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: # 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, y=0, font=font5x5, brightness=0.3) if int(time.time()) % 2 == 0: scrollphathd.clear_rect(8, 0, 1, 5) scrollphathd.show() scrollphathd.flip(x=True, y=True) time.sleep(0.1) count = count + 1 return "", 204 scrollphathd.clear() scrollphathd.show()
tempo = int(time.strftime("%H")) if (tempo >= 0) & (tempo <= 8): BRIGHTNESS=0.1 else: BRIGHTNESS=0.2 # 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() time.sleep(0.1)
def runClock(): DISPLAY_BAR = True BRIGHTNESS = 0.1 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)
def _blink_clock_points(self): if int(time.time()) % 2 == 0: scrollphathd.clear_rect(8, 0, 1, 7)
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)