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)
Exemplo n.º 2
0
	import glob
	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()