コード例 #1
0
      self.position += self.direction
      if self.position+self.length >= self.tape.getSize() or self.position<=0:
         # We've just hit a wall
         self.direction=-self.direction

   def getOccupiedSpaces(self):
      return range(self.position, self.position+self.length)

   def getColour(self):
      return self.colour

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
コード例 #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]

  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
コード例 #3
0
if sys.platform.startswith('win'):
    serialPorts = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
    # this excludes your current terminal "/dev/tty"
    serialPorts = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
    serialPorts = glob.glob('/dev/tty.*')
else:
    raise EnvironmentError('Unsupported platform')

for thisPort in serialPorts:
    if 'usb' in thisPort:
        port = thisPort

bt = BlinkyTape(port)

storageFileName = 'lifeline.p'
tickTime = 0.01

# the format of the data will be:
# {
# 	'eventsById': {
# 		<id>: {
# 			'id': <id>,
# 			'date': <timestamp>
# 		}
# 	},
# 	'eventsByWeek': {
# 		<weekIndex>: {
# 			0: {
コード例 #4
0
ファイル: test.py プロジェクト: stijnvanhulle/ControlYourHome
if __name__ == "__main__":
	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