serialPorts = glob.glob("/dev/ttyACM*") port = serialPorts[0] bt = BlinkyTape(port) # Initialise pixels = [] for i in range(length): pixels.append(0) while(True): # Update current pixels for i in range(length): if pixels[i]>0: pixels[i]-=decayRate if pixels[i]<0: pixels[i]=0 # Spawn new pixels for n in range(0,random.randint(0, maxNewPerTick)): pixels[random.randint(0,length-1)] = maxIntensity # Display for x in range(length): bt.setPixel(x, pixels[x], pixels[x], pixels[x]) bt.sendUpdate() time.sleep(tickLength)
if __name__ == "__main__": serialPorts = glob.glob("/dev/ttyACM*") port = serialPorts[0] bt = BlinkyTape(port) blocks = [ Block(bt,[255,0,0],30,-1,2), # Red block Block(bt,[0,0,255],10,-1,5), # Blue block Block(bt,[0,255,0],40,1,6) # Green block ] tickTime = 0.01 while True: # Run a tick on each block for block in blocks: block.tick(blocks) # Once we've ticked all blocks, redraw everything # Lets get lazy and set everything to blank first for i in range(0,bt.getSize()): bt.setPixel(i,0,0,0) # Now loop all blocks and get colours for block in blocks: colour = block.getColour() for x in block.getOccupiedSpaces(): bt.setPixel(x,colour[0],colour[1],colour[2]) bt.sendUpdate() time.sleep(tickTime)
import optparse 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 != None: port = options.portname else: serialPorts = glob.glob("/dev/ttyACM*") port = serialPorts[0] bb = BlinkyTape(port) pixel=0 while pixel<bb.getSize(): bb.setPixel(pixel, 255, 255, 255,True) time.sleep(0.02) bb.clear() print(pixel) if pixel==bb.getSize() - 1 : while pixel>0: pixel=pixel-1 bb.setPixel(pixel, 255, 255, 255,True) time.sleep(0.02) bb.clear() pixel=pixel+1 #bb.setPixel(pixel, 100, 100, 100) #bb.sendUpdate()