def __init__(self): self.name = 'ScrollPhat' log_str('init {}'.format(self.__module__)) self.rotation = SCROLL_ROTATION scrollphat.set_rotate(self.rotation) self.hour = int(datetime.now().strftime("%H")) if 9 <= self.hour <= 17: self.brightness = HIGH.scrollphat self.brightness_setting = 'day' elif 18 <= self.hour <= 23 or 0 <= self.hour <= 8: self.brightness = LOW.scrollphat self.brightness_setting = 'night' else: self.brightness = self.brightness log_str('scrollphat brightness: {} - {}: {}'.format( self.brightness, self.brightness_setting, self.hour)) scrollphat.set_brightness(self.brightness)
def set_scroll_brightness(cls, level=brightness): cls.brightness = level log_str('set scrollphat brightness: {}'.format(cls.brightness)) scrollphat.set_brightness(cls.brightness) return cls.brightness
async def handle(request: web.Request) -> web.Response: if not HAS_SCROLLPHAT: raise web.HTTPNotImplemented(text="No scrollphat :(") brightness = await request.json() scrollphat.set_brightness(brightness) return web.Response(text="OK")
def ledstage(stage): pause_time = 0.03 scrollphat.set_brightness(2) for y in range(5): for x in range(stage): scrollphat.set_pixel(x, y, 1) scrollphat.update() time.sleep(pause_time)
def ledstage( stage ): pause_time = 0.03 scrollphat.set_brightness(2) for y in range(5): for x in range(stage): scrollphat.set_pixel(x,y,1) scrollphat.update() time.sleep(pause_time)
def __init__(self): MID_LEVEL = 10 scrollphat.clear() scrollphat.update() scrollphat.set_brightness(MID_LEVEL) self.last = 0 self.HEIGHT = 5 self.WIDTH = 11 self.MAX = (self.WIDTH) * (self.HEIGHT)
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()
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)
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 pulse(self): '''Pulse the twitter logo''' if self.args.verbose: print('Running Twitter.pulse') print('Pulsing for %s times' % self.args.pulse_times) for i in range(0, self.args.pulse_times): if self.args.verbose: print('Setting brightness to: 10') scrollphat.set_brightness(10) self.setCentered() scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 5') scrollphat.set_brightness(5) self.setCentered() scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 3') scrollphat.set_brightness(3) self.setCentered() scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear()
def pulse(self, position): '''Pulse the tree vertically from position''' if self.args.verbose: print('Running DisplayVertical.pulse, position: %s' % position) print('Pulsing for %s times' % self.args.pulse_times) for i in range(0, self.args.pulse_times): if self.args.verbose: print('Setting brightness to: 10') scrollphat.set_brightness(10) self.setPositionCenter(position) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 5') scrollphat.set_brightness(5) self.setPositionCenter(position) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 3') scrollphat.set_brightness(3) self.setPositionCenter(position) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear()
def pulseRight(self, position): '''Sets the pacman to pulse with the mouth opened to the right''' if self.args.verbose: print('Running Pacman.pulseLeft, position: {}'.format(position)) print('Pulsing for {} times'.format(self.args.pulse_times)) for i in range(0, self.args.pulse_times): if self.args.verbose: print('Setting brightness to: 10') scrollphat.set_brightness(10) self.mouthOpenDisplayRight(position) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 7') scrollphat.set_brightness(7) self.mouthClosedDisplay(position) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 5') scrollphat.set_brightness(5) self.mouthOpenDisplayRight(position) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 3') scrollphat.set_brightness(5) self.mouthClosedDisplay(position) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear()
unicorn.brightness(0.7) SCREEN_WIDTH, SCREEN_HEIGHT = unicorn.get_shape() screen_size = (SCREEN_WIDTH, SCREEN_HEIGHT) RGB_ENABLED = True BG_COLOR = [0, 150, 200] BG_NOISE = 2 CAVE_COLOR = [244, 164, 96] CAVE_NOISE = 10 PLAYER_COLOR = [255, 0, 0] if SCREEN_TYPE == "SCROLL": import scrollphat SCREEN_WIDTH = 11 SCREEN_HEIGHT = 5 scrollphat.set_brightness(1) if SCREEN_TYPE == "SCROLLHD": import scrollphathd as scrollphat SCREEN_WIDTH = 17 SCREEN_HEIGHT = 7 scrollphat.set_brightness(0.25) screen_size = (SCREEN_WIDTH, SCREEN_HEIGHT) class GameOver(Exception): def __init__(self): print("AI found no possible moves") #input("quit?")
import sys import scrollphat import time import datetime import math YEAR=2018 try: scrollphat.set_brightness(10) last_time=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()
#!/usr/bin/env python import scrollphat as sp import sys import time import random from random import randint 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()
def main(): global _output pygame.init() # Reading only "clicks" via events. These are used for advanced # mappings. Events to avoid tracking state manually. Axes are read # by snapshotting. pygame.event.set_allowed([pygame.JOYBUTTONDOWN, pygame.JOYHATMOTION]) pi_gpio = 1 << PPM_OUTPUT_PIN if pigpio: pi = pigpio.pi() pi.set_mode(PPM_OUTPUT_PIN, pigpio.OUTPUT) pi.wave_add_generic([pigpio.pulse(pi_gpio, 0, 2000)]) # padding to make deleting logic easier waves = [None, None, pi.wave_create()] pi.wave_send_repeat(waves[-1]) else: pi = None if scrollphat: scrollphat.clear() scrollphat.set_brightness(DISPLAY_BRIGHTNESS) # fork to avoid crash in case of I2C connection issues th = threading.Thread(target=render) th.daemon = True th.start() prev = None while _running: # clicks for advanced mapping clicks, hats = [], [] for evt in pygame.event.get(): if evt.type == pygame.JOYBUTTONDOWN: #print "JOYBUTTONDOWN: %r\n%s" % (evt, dir(evt)) clicks.append(evt) elif evt.type == pygame.JOYHATMOTION and any(evt.value): #print "JOYHATMOTION: %r\n%s" % (evt, dir(evt)) hats.append(evt) # tuple to enforce immutability _output = tuple(max(min(ch((clicks, hats)), 1.), -1.) for ch in CHANNELS) if _output == prev: # do nothing pass elif pigpio: pulses, pos = [], 0 for value in _output: # calibrated with Taranis to [-99.6..0..99.4] us = int(round(1500 + 500 * value)) pulses += [pigpio.pulse(0, pi_gpio, 300), pigpio.pulse(pi_gpio, 0, us - 300)] pos += us pulses += [pigpio.pulse(0, pi_gpio, 300), pigpio.pulse(pi_gpio, 0, 20000 - 300 - pos - 1)] pi.wave_add_generic(pulses) waves.append(pi.wave_create()) pi.wave_send_using_mode(waves[-1], pigpio.WAVE_MODE_REPEAT_SYNC) last, waves = waves[0], waves[1:] if last: pi.wave_delete(last) else: # debugging print str(_output) prev = _output # NO BUSYLOOPING. And locking with ``pygame.event.wait`` doesn't sound # very sophisticated. (At this point, at least.) time.sleep(.02) if scrollphat: scrollphat.clear() if pi: pi.stop()
def __init__(self, brightness): scrollphat.set_brightness(brightness) scrollphat.clear() scrollphat.update()
# load all the modules we will need from gps import * import datetime import time import random import threading import scrollphat # initialize some variables gpsd = None # setting the global variable first = True # first pass will set filenames tzfix = time.altzone/3600 # time zone doesn't change scrollphat.set_brightness(128) # bright for daylight display # initialize thread, we don't use all data class GpsPoller(threading.Thread): def __init__(self): threading.Thread.__init__(self) global gpsd # bring it in scope gpsd = gps(mode=WATCH_ENABLE) # starting the stream of info self.current_value = None self.running = True # setting the thread running to true def run(self): global gpsd # this will continue to loop and grab EACH set of # gpsd info to clear the buffer and prevent overruns
#!/usr/bin/env python import sys import json import time import scrollphat if len(sys.argv) != 3: print("\nProblem") sys.exit(0) data = json.loads(sys.argv[1]) brightness = int(sys.argv[2]) scrollphat.set_brightness(brightness) for d in data: print data[d] scrollphat.set_pixel(data[d][0], data[d][1], True) scrollphat.update() sys.exit(0)
def main(): global _output pygame.init() # Reading only "clicks" via events. These are used for advanced # mappings. Events to avoid tracking state manually. Axes are read # by snapshotting. pygame.event.set_allowed([pygame.JOYBUTTONDOWN, pygame.JOYHATMOTION]) pi_gpio = 1 << PPM_OUTPUT_PIN if pigpio: pi = pigpio.pi() pi.set_mode(PPM_OUTPUT_PIN, pigpio.OUTPUT) pi.wave_add_generic([pigpio.pulse(pi_gpio, 0, 2000)]) # padding to make deleting logic easier waves = [None, None, pi.wave_create()] pi.wave_send_repeat(waves[-1]) else: pi = None if scrollphat: scrollphat.clear() scrollphat.set_brightness(DISPLAY_BRIGHTNESS) # fork to avoid crash in case of I2C connection issues th = threading.Thread(target=render) th.daemon = True th.start() prev = None while _running: # clicks for advanced mapping clicks, hats = [], [] for evt in pygame.event.get(): if evt.type == pygame.JOYBUTTONDOWN: #print "JOYBUTTONDOWN: %r\n%s" % (evt, dir(evt)) clicks.append(evt) elif evt.type == pygame.JOYHATMOTION and any(evt.value): #print "JOYHATMOTION: %r\n%s" % (evt, dir(evt)) hats.append(evt) # tuple to enforce immutability _output = tuple(max(min(ch((clicks, hats)), 1.), -1.) for ch in CHANNELS) if _output == prev: # do nothing pass elif pigpio: pulses, pos = [], 0 for value in _output: # calibrated with Taranis to [-99.6..0..99.4] us = int(round(1333 + 453 * value)) pulses += [pigpio.pulse(0, pi_gpio, 300), pigpio.pulse(pi_gpio, 0, us - 300)] pos += us pulses += [pigpio.pulse(0, pi_gpio, 300), pigpio.pulse(pi_gpio, 0, 20000 - 300 - pos - 1)] pi.wave_add_generic(pulses) waves.append(pi.wave_create()) pi.wave_send_using_mode(waves[-1], pigpio.WAVE_MODE_REPEAT_SYNC) last, waves = waves[0], waves[1:] if last: pi.wave_delete(last) else: # debugging print str(_output) prev = _output # NO BUSYLOOPING. And locking with ``pygame.event.wait`` doesn't sound # very sophisticated. (At this point, at least.) time.sleep(.02) if scrollphat: scrollphat.clear() if pi: pi.stop()
def pulse(self): '''Displays the space invader pulsing''' if self.args.verbose: print('Running SpaceInvader.pulse') print('Pulsing for {} times'.format(self.args.pulse_times)) for i in range(0, self.args.pulse_times): # Arm Down if self.args.verbose: print('Setting brightness to: 10') scrollphat.set_brightness(10) self.armDownDisplay(0) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 5') scrollphat.set_brightness(5) self.armDownDisplay(0) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 3') scrollphat.set_brightness(3) self.armDownDisplay(0) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() # Arm Up if self.args.verbose: print('Setting brightness to: 10') scrollphat.set_brightness(10) self.armUpDisplay(0) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 5') scrollphat.set_brightness(5) self.armUpDisplay(0) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear() if self.args.verbose: print('Setting brightness to: 3') scrollphat.set_brightness(3) self.armUpDisplay(0) scrollphat.update() time.sleep(self.args.pause_pulse) scrollphat.clear()
#!/usr/bin/env python import scrollphat as sp import math import time import sys from random import randint i = 0 buf = [0] * 11 sp.set_brightness(20) while True: # light random pixels with random brightness sp.set_brightness(randint(1,100)) for q in range(randint(0,3)): y = randint(0,4) x = randint(0,10) sp.set_pixel(x,y,1) sp.update() time.sleep(0.1) sp.clear()
if ((str(args.RightSpeed)) != 'None'): print '\nRight Speed - ', (str(args.RightSpeed)) rightspeed = args.RightSpeed if ((str(args.LeftSpeed)) != 'None'): print 'Left Speed - ', (str(args.LeftSpeed)) leftspeed = args.LeftSpeed if ((str(args.Speed)) != 'None'): print '\nGeneral Speed - ', (str(args.Speed)) speed = args.Speed if ((str(args.Brightness)) != 'None'): print '\nscrollpHat Brightness - ', (str(args.Brightness)) scrollphat.set_brightness(int(args.Brightness)) if ((str(args.InnerTurnSpeed)) != 'None'): print '\nInner Turn Speed - ', (str(args.InnerTurnSpeed)) innerturnspeed = args.InnerTurnSpeed if ((str(args.OuterTurnSpeed)) != 'None'): print '\nOuter Turn Speed - ', (str(args.OuterTurnSpeed)) outerturnspeed = args.OuterTurnSpeed if ((str(args.ShowCam)) != 'None'): print '\nShow Cam Image - ', (str(args.ShowCam)) showcam = args.ShowCam else: showcam = False
#!/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/text_to_scroll.txt' ).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)
import forecastio as f import scrollphat as s import time as t from apikey import api_key lat = 50.781999 lng = -1.086579 s.set_brightness(2) forecast = f.load_forecast(api_key, lat, lng, units='si') current_forecast = forecast.currently() start_time = t.time() while True: try: temp = str(int(round(current_forecast.d['apparentTemperature']))) temp_str = temp + '\'C ' summary = current_forecast.d['summary'].upper() hour = t.strftime('%H') minute = t.strftime('%M') display_str = hour + ":" + minute + " " + temp_str + summary # 'M' and 'W' take 6 spaces, rather than 4 num_m = display_str.count('M') 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
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)
#!/usr/bin/env python import time import scrollphat scrollphat.set_brightness(64) while True: print("0 to 5") scrollphat.graph([0,1,2,3,4,5]) time.sleep(1.0) scrollphat.clear() print("0 to 10") scrollphat.graph([0,2,4,6,8,10]) time.sleep(1.0) scrollphat.clear()
scrollphat.clear() scrollphat.write_string(str(count)) last = count def process(): try: params = {"key": apiKey} r = requests.get(server, params=params, timeout=5) count = int(r.text) update(count) except: status(1) #update(None) if __name__ == "__main__": scrollphat.set_brightness(brightness) scrollphat.write_string("0") while True: process() time.sleep(updatePeriod)
import scrollphat as sp import time sp.set_brightness(64) while True: print("0 to 5") sp.graph([0,1,2,3,4,5]) time.sleep(1.0) sp.clear() print("0 to 10") sp.graph([0,2,4,6,8,10]) time.sleep(1.0) sp.clear()
brightness = 20 # Setting brightness on scroll phat w, h = (11, 5) # Setting width and height x, y = (0, 0) # Setting x and y grav = 0.5 # Setting Gravity jump_vel = 0 # Setting jump velocity jump_decay = 0.8 # Setting jump decay move_speed = 1 # Setting movement speed while True: # Loop forever scrollphat.clear() # Clearing the display scrollphat.set_brightness(brightness) # Getting the brightness for LEDS scrollphat.set_pixel(int(x), int(y), 1) # Setting pixel to show in bottom left corner scrollphat.update() # Updating scroll phat time.sleep(0.03) # Set scroll phat to sleep for .3 seconds pygame.event.pump() # Processes pygame event handlers internally axis_value = joystick.get_axis(0) # Setting axis value for x if axis_value > 0.8: # If axis value is greater than 0.8 x += move_speed # increase move speed of x elif axis_value < -0.8: # If axis value is less than 0.8 x -= move_speed # Decrease move speed if x >= w: # if x is greater than width x = w - 1 # x = width - 1
#!/usr/bin/env python import scrollphat as sp import math import time import sys from random import randint while True: change_brightness = (randint(0,2)) if change_brightness == 2: sp.set_brightness(randint(1,32)) y = randint(0,4) x = randint(0,10) sp.set_pixel(x,y,(randint(0,1))) sp.update() time.sleep(0.02) for r in range(0,2): y = randint(0,4) x = randint(0,10) sp.set_pixel(x,y,0) sp.update() time.sleep(0.01)
#!/usr/bin/env python import scrollphat as sp import math import time import sys from random import randint sp.set_rotate(False) clear = randint(0,10) if clear > 5: for w in range(0,randint(5,20)): for x in range(0,11): for y in range(0,5): sp.set_pixel(x,y,randint(0,1)) sp.set_brightness(128) sp.update() time.sleep(0.01) sp.clear() else: for w in range(0,randint(5,20)): for x in range(0,11): for y in range(0,randint(1,5)): sp.set_pixel(x,y,1) sp.set_brightness(128) sp.update() time.sleep(0.01) sp.clear()
def runForFunctionName(): '''Runs functions from the pacman classe from parsed function name''' try: if args.verbose: print('seting brightness to: {}'.format(args.brightness)) print('Running {}'.format(args.function)) # Set brightness scrollphat.set_brightness(args.brightness) if args.function == 'dance-left': pacman.danceLeft(args.position) elif args.function == 'dance-right': pacman.danceRight(args.position) elif args.function == 'pulse-left': pacman.pulseLeft(args.position) elif args.function == 'pulse-right': pacman.pulseRight(args.position) elif args.function == 'show-closed': pacman.mouthClosedDisplay(args.position) scrollphat.update() time.sleep(args.pause_show) scrollphat.clear() elif args.function == 'show-open-left': pacman.mouthOpenDisplayLeft(args.position) scrollphat.update() time.sleep(args.pause_show) scrollphat.clear() elif args.function == 'show-open-right': pacman.mouthOpenDisplayRight(args.position) scrollphat.update() time.sleep(args.pause_show) scrollphat.clear() elif args.function == 'scroll-left-right-in': pacman.scrollLeftRightIn() elif args.function == 'scroll-left-right-out': pacman.scrollLeftRightOut() elif args.function == 'scroll-left-right': pacman.scrollLeftRightIn() pacman.setPositionMiddleClosed() pacman.scrollLeftRightOut() elif args.function == 'scroll-left-right-dance': pacman.scrollLeftRightIn() pacman.setPositionMiddleClosed() time.sleep(args.pause_scroll) scrollphat.clear() pacman.danceRight(3) pacman.setPositionMiddleClosed() pacman.scrollLeftRightOut() elif args.function == 'scroll-left-right-pulse': pacman.scrollLeftRightIn() pacman.setPositionMiddleClosed() scrollphat.clear() pacman.pulseRight(3) pacman.setPositionMiddleClosed() pacman.scrollLeftRightOut() elif args.function == 'scroll-right-left-in': pacman.scrollRightLeftIn() elif args.function == 'scroll-right-left-out': pacman.scrollRightLeftOut() elif args.function == 'scroll-right-left': pacman.scrollRightLeftIn() pacman.setPositionMiddleClosed() pacman.scrollRightLeftOut() elif args.function == 'scroll-right-left-dance': pacman.scrollRightLeftIn() pacman.setPositionMiddleClosed() time.sleep(args.pause_scroll) scrollphat.clear() pacman.danceLeft(3) pacman.setPositionMiddleClosed() pacman.scrollRightLeftOut() elif args.function == 'scroll-right-left-pulse': pacman.scrollRightLeftIn() pacman.setPositionMiddleClosed() scrollphat.clear() pacman.pulseLeft(3) pacman.setPositionMiddleClosed() pacman.scrollRightLeftOut() elif args.function == 'clear': scrollphat.clear() else: print('Function unknown: {}'.format(args.function)) args.function except KeyboardInterrupt: scrollphat.clear()
#!/usr/bin/env python import scrollphat as sp import sys import time import random from random import randint sp.set_rotate(True) sp.set_brightness(10) lines = open('text_to_scroll.txt').read().splitlines() while True: 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()
aio.send('sensor_temp', round(sensor_temp, 1)) aio.send('sensor_pressure', round(sensor_pressure, 1)) aio.send('sensor_humidity', round(sensor_humidity, 1)) # write log_string to log file weather_logger.info(log_string) # return the output string for the scroll pHAT return scroll_output # write everything to the scroll pHAT for the first time... than update the data in the loop timeout = get_timeout() count = 0 msg = get_weather() scrollphat.clear() scrollphat.set_brightness(brightness) # from 0 to 255 scrollphat.write_string(msg) # run the loop to print the output to scroll pHAT # TODO: Learn how this works cause it's creepy shit and could be done better... but it works ;) while True: try: scrollphat.scroll() time.sleep(pause) if count > timeout: msg = get_weather() scrollphat.clear() scrollphat.set_brightness(brightness) # from 0 to 255 scrollphat.write_string(msg) timeout = get_timeout()
#!/usr/bin/env python import scrollphat as sp import math import time import sys from random import randint i = 0 buf = [0] * 11 while True: # light random pixels with random brightness clear = (randint(0, 1000)) sp.set_brightness(randint(1, 128)) y = randint(0, 4) x = randint(0, 10) sp.set_pixel(x, y, (randint(0, 1))) sp.update() time.sleep(0.02) for r in range(0, 2): y = randint(0, 4) x = randint(0, 10) sp.set_pixel(x, y, 0) sp.update() time.sleep(0.01) if clear > 990: if clear > 995: for w in range(0, randint(3, 9)): for x in range(0, 11): for y in range(0, 5): sp.set_pixel(x, y, randint(0, 1))
def runForFunctionName(): '''Runs funcations from the other classes from parsed function name''' try: if args.verbose: print('seting brightness to: {}'.format(args.brightness)) print('Running {}'.format(args.function)) # Set brightness scrollphat.set_brightness(args.brightness) if args.function == 'dance': spaceInvader.dance() elif args.function == 'pulse': spaceInvader.pulse() elif args.function == 'show-arms-down': spaceInvader.armDownDisplay(0) scrollphat.update() time.sleep(args.pause_show) scrollphat.clear() elif args.function == 'show-arms-up': spaceInvader.armUpDisplay(0) scrollphat.update() time.sleep(args.pause_show) scrollphat.clear() elif args.function == 'scroll-in': spaceInvader.scrollIn() elif args.function == 'scroll-out': spaceInvader.scrollOut() elif args.function == 'scroll': spaceInvader.scrollIn() spaceInvader.armDownDisplay(0) scrollphat.update() time.sleep(args.pause_scroll) scrollphat.clear() spaceInvader.scrollOut() elif args.function == 'scroll-and-dance': spaceInvader.scrollIn() spaceInvader.dance() spaceInvader.scrollOut() elif args.function == 'scroll-and-pulse': spaceInvader.scrollIn() spaceInvader.pulse() spaceInvader.scrollOut() elif args.function == 'clear': scrollphat.clear() else: print('Function unknown: {}'.format(args.function)) args.function except KeyboardInterrupt: scrollphat.clear()
def __init__(self, game): self.brightness = 5 scrollphat.set_brightness(self.brightness) scrollphat.set_rotate(True)
def flash(): scrollphat.set_pixels(lambda x, y: 1, True) time.sleep(0.1) scrollphat.clear() time.sleep(0.1) total_time = (minutes * 60) popov = total_time / 5.0 start = time.time() scrollphat.clear() scrollphat.set_rotate(True) scrollphat.set_brightness(1) blinkstate = False elapsed = 0 while total_time > elapsed: try: elapsed = time.time() - start # print elapsed blinkstate = not blinkstate blinker_line = (int)(elapsed / popov) # print blinker_line scrollphat.clear_buffer() for x in range(0, 11, 1):
#!/usr/bin/env python import scrollphat as sp import math import time import sys from random import randint i = 0 buf = [0] * 11 while True: clear = (randint(0,1000)) # rnd var for timing of crashes change_brightness = (randint(0,2)) if change_brightness == 2: sp.set_brightness(randint(1,128)) y = randint(0,4) x = randint(0,10) sp.set_pixel(x,y,(randint(0,1))) sp.update() time.sleep(0.02) for r in range(0,2): y = randint(0,4) x = randint(0,10) sp.set_pixel(x,y,0) sp.update() time.sleep(0.01) if clear > 993: if clear > 996: for w in range(0,randint(3,9)): for x in range(0,11):
import forecastio as f import scrollphat as s import time as t from apikey import api_key lat = 53.768983 lng = -2.764714 s.set_brightness(2) s.set_rotate(True) forecast = f.load_forecast(api_key, lat, lng, units='si') current_forecast = forecast.currently() start_time = t.time() while True: try: temp = str(int(round(current_forecast.d['apparentTemperature']))) temp_str = temp + '\'C ' summary = current_forecast.d['summary'].upper() hour = t.strftime('%H') minute = t.strftime('%M') display_str = hour + ":" + minute + " " + temp_str + summary # 'M' and 'W' take 6 spaces, rather than 4 num_m = display_str.count('M') 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
#!/usr/bin/env python import math, time, scrollphat, sys, socket, psutil s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("gmail.com",80)) ip = s.getsockname()[0] s.close() print(ip) i = 0 scrollphat.set_brightness(20) #scrollphat.write_string("This is a test, hurrah! The quick brown fox jumps over the lazy dog. y2 = (math.sin(((i/2.0)+(x*10.0))/10.0) + 1) * 2.5", 0) cpu_values = [0] * 11 while True: cpu_values.pop(0) cpu_values.append(psutil.cpu_percent()) scrollphat.graph(cpu_values, 0, 25) time.sleep(0.2) # scrollphat.clear() # scrollphat.write_string("IP: " + ip + " ", 11) # for i in range(0, scrollphat.buffer_len() - 11): # scrollphat.scroll() # time.sleep(0.05)
#!/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)
def runForFunctionName(): '''Runs functions from the twitter classe from parsed function name''' try: if args.verbose: print('seting brightness to: %d' % args.brightness) print('Running %s' % args.function) # Set brightness scrollphat.set_brightness(args.brightness) # Logo: REGULAR if args.function == 'logo-show': twitter.logo.show() elif args.function == 'logo-pulse': twitter.logo.pulse() elif args.function == 'logo-scroll-in': twitter.logo.scrollLeftRightIn() elif args.function == 'logo-scroll-out': twitter.logo.scrollLeftRightOut() elif args.function == 'logo-scroll': twitter.logo.scrollLeftRightIn() twitter.logo.setCentered() scrollphat.update() time.sleep(args.pause_scroll) scrollphat.clear() twitter.logo.scrollLeftRightOut() elif args.function == 'logo-scroll-pulse': twitter.logo.scrollLeftRightIn() twitter.logo.pulse() twitter.logo.scrollLeftRightOut() elif args.function == 'logo-scroll-right-left-in': twitter.logo.scrollRightLeftIn() elif args.function == 'logo-scroll-right-left-out': twitter.logo.scrollRightLeftOut() elif args.function == 'logo-scroll-right-left': twitter.logo.scrollRightLeftIn() twitter.logo.setCentered() scrollphat.update() time.sleep(args.pause_scroll) scrollphat.clear() twitter.logo.scrollRightLeftOut() elif args.function == 'logo-scroll-right-left-pulse': twitter.logo.scrollRightLeftIn() twitter.logo.pulse() twitter.logo.scrollRightLeftOut() # Logo: REVERSE elif args.function == 'logo-show-inverted': #~ twitter.showRightLeft() twitter.logo.setOrientation('inverted') twitter.logo.show() elif args.function == 'logo-pulse-inverted': twitter.logo.setOrientation('inverted') twitter.logo.pulse() elif args.function == 'logo-scroll-in-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollLeftRightIn() elif args.function == 'logo-scroll-out-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollLeftRightOut() elif args.function == 'logo-scroll-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollLeftRightIn() twitter.logo.setCentered() scrollphat.update() time.sleep(args.pause_scroll) scrollphat.clear() twitter.logo.scrollLeftRightOut() elif args.function == 'logo-scroll-pulse-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollLeftRightIn() twitter.logo.pulse() twitter.logo.scrollLeftRightOut() elif args.function == 'logo-scroll-right-left-in-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollRightLeftIn() elif args.function == 'logo-scroll-right-left-out-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollRightLeftOut() elif args.function == 'logo-scroll-right-left-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollRightLeftIn() twitter.logo.setCentered() scrollphat.update() time.sleep(args.pause_scroll) scrollphat.clear() twitter.logo.scrollRightLeftOut() elif args.function == 'logo-scroll-right-left-pulse-inverted': twitter.logo.setOrientation('inverted') twitter.logo.scrollRightLeftIn() twitter.logo.pulse() twitter.logo.scrollRightLeftOut() # MESSAGE elif args.function == 'message-write': twitter.textScroll(args.message) elif args.function == 'fetch': tweets = twitter.fetchTweets() for tweet in tweets: twitter.textScroll(tweet.text.encode('utf-8')) elif args.function == 'fetch-with-logo': twitter.logo.scrollLeftRightIn() twitter.logo.pulse() twitter.logo.scrollLeftRightOut() tweets = twitter.fetchTweets() for tweet in tweets: twitter.textScroll(tweet.text.encode('utf-8')) elif args.function == 'clear': scrollphat.clear() else: print('Function unknown: %s' % args.function) args.function except KeyboardInterrupt: scrollphat.clear()
def POST(self): deserialized = json.loads(web.data()) scrollphat.write_string(deserialized["message"] + " ") scrollphat.set_brightness(deserialized["brightness"]) if not scrollThread.is_alive(): scrollThread.start()
def __init__(self, matrix_updater): self.setup_signal_handler() self.matrix_updater = matrix_updater scrollphat.set_brightness(self.BRIGHTNESS)
args = parser.parse_args() temp = get_cpu_temperature() client = docker.from_env() nb_containers = len(client.containers.list()) if args.verbose: print('monitor.py - program wrote by FX') print('Last modification: 02-may-2020') print('Verbosity mode turned on') print('Press Ctrl+C to exit!') print('Brightness: ' + str(args.brightness)) print('CPU temperature: ' + str(temp)) print('Rotate: ' + str(args.rotate)) print('Interval: ' + str(args.interval)) print('Number of docker containers running: ' + str(nb_containers)) scrollphat.set_rotate(args.rotate) scrollphat.set_brightness(args.brightness) prev_temp = 0 prev_load = 0 prev_nb_containers = 0 while True: try: # Display the temperature temp = get_cpu_temperature() if (temp > prev_temp): for x in range(int(temp / 80 * 11)): scrollphat.set_pixel(x, args.temperature, 1) elif (temp < prev_temp): for x in range(int(temp / 80 * 11), int(prev_temp / 80 * 11)): scrollphat.set_pixel(x, args.temperature, 0) prev_temp = temp
#!/usr/bin/env python import math import time import scrollphat def millis(): return int(round(time.time() * 1000)) scrollphat.set_brightness(2) while True: for x in range(11): for y in range(5): scrollphat.set_pixel(x, y, 1) scrollphat.update() time.sleep(0.03) for x in range(11): for y in range(5): scrollphat.set_pixel(x, y, 0) scrollphat.update() time.sleep(0.03)
def switchon(): for x in range(11): for y in range(5): scrollphat.set_brightness(4) scrollphat.set_pixel(x,y,1) scrollphat.update();
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)
import scrollphat as hat import time str = 'Merry Christmas ' hat.set_brightness(2) hat.write_string(str) # for i in range(len(str) * 5): # hat.scroll() # time.sleep(0.150) hat.graph([2, 4, 6, 8, 10, 8, 6, 4, 2, 0, 3]) hat.update()