def __init__(self, port, mailbox): super(BlinkytapeDriver, self).__init__() self.mailbox = mailbox self.color_generator = None self.current_color = (0,0,0) if port == 'gui': # Start GUI process gui_out_connection, gui_in_connection = Pipe() self.led = GUIBackend(gui_out_connection) p = Process(target=run_gui, args=(gui_in_connection,)) p.start() else: # TODO: Implement actual LED stuff self.led = BlinkyTape(port)
class ModeManager(object): def __init__(self, port): self.bb = BlinkyTape(port) def render(self, colors): self.bb.send_list(colors) def run_mode(self, mode): while True: start = time.time() mode.calc_next_step() self.render(mode.get_colors()) if not mode.no_sleep: renderTime = time.time() - start sleepTime = 1.0 / mode.fps - renderTime if sleepTime >= 0.0: time.sleep(sleepTime) diff = time.time() - start sys.stdout.write("%.02f fps \r" % (1.0 / diff))
from blinkytape import BlinkyTape import time bb = BlinkyTape('/dev/ttyACM0', 120) #bb = BlinkyTape('COM8') while True: for x in range(60): bb.sendPixel(100, 100, 100) bb.show() time.sleep(.5) for x in range(60): bb.sendPixel(0, 0, 0) bb.show() time.sleep(.5)
dest="ledcount", help="LED count", default=60, type=int) parser.add_option("-s", "--size", dest="size", help="Size of the light wave", default=20, type=int) (options, args) = parser.parse_args() if options.portname is not None: port = options.portname else: print("Usage: python scanline.py -p <port name>") print("(ex.: python scanline.py -p /dev/ttypACM0)") exit() blinky = BlinkyTape(port, options.ledcount) while True: for position in range(-options.size, options.ledcount + options.size): for led in range(options.ledcount): if abs(position - led) < options.size: blinky.sendPixel(255, 0, 200) else: blinky.sendPixel(0, 0, 0) blinky.show() sleep(0.005)
dest="portname", help="serial port (ex: /dev/ttyACM0)", default="/dev/ttyACM0") (options, args) = parser.parse_args() if options.portname is not None: port = options.portname else: print "Usage: python Huxley_UK_Rail_Station_Delays.py -p <port name>" print "(ex.: python Huxley_UK_Rail_Station_Delays.py -p /dev/ttyACM0)" exit() url = "https://huxley.apphb.com/delays/{}/to/{}/50/{}?accessToken={}".format( crs, filterCrs, trainTime, accessToken) bt = BlinkyTape(port) # Some visual indication that it works for headless setups (green tape) bt.displayColor(0, 100, 0) sleep(2) # Tape resets to stored pattern after a couple of seconds of inactivity while True: try: print "GET %s" % (url) rawHttpResponse = urllib.urlopen(url) stationStatus = json.load(rawHttpResponse) if not len(stationStatus) or stationStatus is None: raise Exception("Error parsing data")
from time import sleep import optparse parser = optparse.OptionParser() parser.add_option("-p", "--port", dest="portname", help="serial port (ex: /dev/ttyUSB0)", default=None) parser.add_option("-c", "--count", dest="ledcount", help="LED count", default=60, type=int) parser.add_option("-s", "--size", dest="size", help="Size of the light wave", default=20, type=int) (options, args) = parser.parse_args() if options.portname is not None: port = options.portname else: print("Usage: python scanline.py -p <port name>") print("(ex.: python scanline.py -p /dev/ttypACM0)") exit() blinky = BlinkyTape(port, options.ledcount) while True: for position in range(-options.size, options.ledcount + options.size): for led in range(options.ledcount): if abs(position - led) < options.size: blinky.sendPixel(255,0,200) else: blinky.sendPixel(0,0,0) blinky.show() sleep(0.005)
""" Easily see your GPU temperature while gaming! This sets the LED colors base on your Nvidia GPU temperature, every second. 60F = green, 70F = yellow, 80F = red """ import time from blinkytape import BlinkyTape import subprocess import os import re # To find your COM port number in Windows, run "Pattern Paint -> Help -> System Information" #bb = BlinkyTape('/dev/tty.usbmodemfa131') bb = BlinkyTape('COM3') while True: output = str(subprocess.check_output( ["C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe", "-a"], shell=True)) # os.popen('C:\\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe') #output=os.popen("C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe").read() #print("====" + str(output) + "=====") temp = re.search("GPU Current.*", output).group()[30:33] temp_baseline = 55 # configure to you base line temp here temp_multiplier = 5 color_temp = (int(temp) - temp_baseline) * temp_multiplier green = min(254, max(0, 100 - color_temp)) red = min(254, max(0, 0 + color_temp)) blue = 0 print("Current GPU Temp: %s RGB: %s %s %s" % (temp, red, green, blue))
colours = { "bakerloo" : (137, 78, 36), "central" : (220, 36, 31), "circle" : (255, 206, 0), "district" : (0, 114, 41), "dlr" : (0, 175, 173), "hammersmith-city" : (215, 153, 175), "jubilee" : (106, 114, 120), "london-overground" : (232, 106, 16), "metropolitan" : (117, 16, 86), "northern" : (0, 0, 0), "piccadilly" : (0, 25, 168), "victoria" : (0, 160, 226), "waterloo-city" : (118, 208, 189), "tfl-rail" : (0, 25, 168) } bt = BlinkyTape(port) # Some visual indication that it works for headless setups (green tape) bt.displayColor(0, 100, 0) sleep(2) # Tape resets to stored pattern after a couple of seconds of inactivity while True: try: print "GET %s" % (url) rawHttpResponse = urllib.urlopen(url) lines = json.load(rawHttpResponse) if not len(lines) or lines is None: raise Exception("Error parsing data")
"central": (220, 36, 31), "circle": (255, 206, 0), "district": (0, 114, 41), "dlr": (0, 175, 173), "hammersmith-city": (215, 153, 175), "jubilee": (106, 114, 120), "london-overground": (232, 106, 16), "metropolitan": (117, 16, 86), "northern": (0, 0, 0), "piccadilly": (0, 25, 168), "victoria": (0, 160, 226), "waterloo-city": (118, 208, 189), "tfl-rail": (0, 25, 168) } bt = BlinkyTape(port) # Some visual indication that it works for headless setups (green tape) bt.displayColor(0, 100, 0) sleep(2) # Tape resets to stored pattern after a couple of seconds of inactivity while True: try: print "GET %s" % (url) rawHttpResponse = urllib.urlopen(url) lines = json.load(rawHttpResponse) if not len(lines) or lines is None: raise Exception("Error parsing data")
from blinkytape import BlinkyTape import time bb = BlinkyTape('/dev/ttyACM0', 120) #bb = BlinkyTape('COM8') while True: for x in range(60): bb.sendPixel(100, 100, 100) bb.show() time.sleep(.5) for x in range(120): bb.sendPixel(0, 0, 0) bb.show() time.sleep(.5)
(options, args) = parser.parse_args() if args: print("Unknown parameters: " + args) # grab the values provided by user (or defaults) port = options.portname loc = options.location rate = options.update_rate delta = options.delta_latitude n_leds = options.num_leds i_name = options.image_name # Some visual indication that it works, for headless setups (green tape) bt = BlinkyTape(port, n_leds) bt.displayColor(0, 100, 0) bt.show() sleep(2) while True: try: # first, load image im = Image.open(i_name) # Can be many different formats. cols, rows = im.size a = np.asarray(im) # of shape (rows, cols, channels) # map loc latitude to 0-based index latitude_index = min( rows - 1, max(0, (int)(((loc[0] - -90) / (90 - -90)) * (rows - 0) + 0)))
""" Easily see your GPU temperature while gaming! This sets the LED colors base on your Nvidia GPU temperature, every second. 60F = green, 70F = yellow, 80F = red """ import time from blinkytape import BlinkyTape import subprocess import os import re ## To find your COM port number in Windows, run "Pattern Paint -> Help -> System Information" #bb = BlinkyTape('/dev/tty.usbmodemfa131') bb = BlinkyTape('COM3') while True: output = subprocess.check_output(["C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe", "-a"], shell=True) #os.popen('C:\\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe') #output=os.popen("C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe").read() #print("====" + str(output) + "=====") temp = re.search("GPU Current.*",output).group()[30:33] temp_baseline = 60 temp_multiplier = 5 color_temp = (int(temp) - temp_baseline ) * temp_multiplier green = 100 - color_temp red = 0 + color_temp blue = 0 print "Current GPU Temp: %s RGB: %s %s %s" % (temp, red, green, blue) for x in range(60):
def __init__(self, port): self.bb = BlinkyTape(port)
class BlinkytapeDriver(threading.Thread): def __init__(self, port, mailbox): super(BlinkytapeDriver, self).__init__() self.mailbox = mailbox self.color_generator = None self.current_color = (0,0,0) if port == 'gui': # Start GUI process gui_out_connection, gui_in_connection = Pipe() self.led = GUIBackend(gui_out_connection) p = Process(target=run_gui, args=(gui_in_connection,)) p.start() else: # TODO: Implement actual LED stuff self.led = BlinkyTape(port) def get_color_generator(self, instruction): if instruction.command == "color": return single_color_generator(instruction.color) if instruction.command == "program": return frame_generator(instruction.frames) if instruction.command == "stream": return socket_color_generator() def step(self): """ The update function of the run loop 1) Check the mailbox 2) If instruction in the mailbox, set program_generator to the appropriate generator 3) Get the next value from the generator 4) Display the color if it's not None 5) Sleep for a bit - future enhacement: rate limit? """ try: # Step 1 new_instruction = self.mailbox.get_nowait() self.mailbox.task_done() # Step 2 self.color_generator = self.get_color_generator(new_instruction) except Empty: pass # There's nothing new # Step 3 if self.color_generator == None: return next_color = self.color_generator.next() # Step 4 if next_color is not None: red, green, blue = next_color self.led.displayColor(red, green, blue) self.current_color = next_color # Step 5 time.sleep(STEP_TIME) def run(self): while True: self.step()
blinky.sendPixel(r * int(bit), g * int(bit), b * int(bit)) parser = optparse.OptionParser() parser.add_option("-p", "--port", dest="portname", help="serial port (ex: /dev/ttyUSB0)", default=None) options, args = parser.parse_args() if options.portname is not None: port = options.portname else: print("Usage: python binary_clock.py -p <port name>") print("(ex: python binary_clock.py -p /dev/ttypACM0)") exit() blinky = BlinkyTape(port) # roughly synchronize with seconds time.sleep(1 - datetime.now().microsecond / 1000000.0) while True: timeBegin = time.time() display(blinky) timeEnd = time.time() timeElapsed = timeEnd - timeBegin time.sleep(1 - timeElapsed)
parser = optparse.OptionParser() parser.add_option("-p", "--port", dest="portname", help="serial port (ex: /dev/ttyACM0)", default="/dev/ttyACM0") (options, args) = parser.parse_args() if options.portname is not None: port = options.portname else: print "Usage: python Aurora.py -p <port name>" print "(ex.: python Aurora.py -p /dev/ttyACM0)" exit() # Documentation: http://aurorawatch.lancs.ac.uk/api_info/ # Code and spec: https://github.com/stevemarple/AuroraWatchNet url = 'http://aurorawatch.lancs.ac.uk/api/0.1/status.xml' bt = BlinkyTape(port) request = urllib2.Request(url) request.add_header('User-Agent', 'BlinkyTape Aurora Alert unop.uk') opener = urllib2.build_opener() # Some visual indication that it works, for headless setups (green tape) bt.displayColor(0, 100, 0) sleep(2) while True: try: print "GET %s" % (url) rawXml = opener.open(request).read() tree = ElementTree.fromstring(rawXml)