コード例 #1
0
 def __UpdateColorsAndOffset(self):
     if self.__seq is None:
         return
     if self.__t is None:
         self.__t = time.time()
     t = time.time()
     self.__offset += (t - self.__t) * self.__speed
     self.__t = t
     while self.__offset >= 1.0:
         try:
             c = self.__seq.next()
         except StopIteration:
             self.__seq = None
             break
         self.InsertAndPop(c)
         self.__offset -= 1.0
コード例 #2
0
 def __updateColorsAndOffset(self):
     if self.__seq is None:
         return
     if self.__t is None:
         self.__t = time.time()
     t = time.time()
     self.__offset += (t - self.__t) * self.__speed
     self.__t = t
     while self.__offset >= 1.0:
         try:
             c = self.__seq.next()
         except StopIteration:
             self.__seq = None
             break
         self.insertAndPop(c)
         self.__offset -= 1.0
コード例 #3
0
ファイル: pulser.py プロジェクト: markfickett/LED-Controller
 def __GeneratePositions(self, max_index):
     t = time.time()
     if self.__t0 is None:
         self.__t0 = t
     dt = t - self.__t0
     max_pos = max_index + self.__radius
     repeats = int(dt / self.__add_delay)
     dt -= repeats * self.__add_delay
     i = 0
     p = -self.__radius + self.__speed * dt
     while i <= repeats and p <= max_pos:
         yield p
         p += self.__interval
         i += 1
コード例 #4
0
ファイル: Pulser.py プロジェクト: DoIIIT/ncrc-activiz
	def __generatePositions(self, maxIndex):
		t = time.time()
		if self.__t0 is None:
			self.__t0 = t
		dt = t - self.__t0
		maxPos = maxIndex + self.__radius
		repeats = int(dt / self.__addDelay)
		dt -= repeats*self.__addDelay
		i = 0
		p = -self.__radius + self.__speed*dt
		while i <= repeats and p <= maxPos:
			yield p
			p += self.__interval
			i += 1
コード例 #5
0
		# SendingBuffer has a list of Color objects and encapsulates
		# requisite logic for generating bytes and sending.
		# For simulating, TurtleBuffer subclasses SendingBuffer and
		# draws to the screen using Turtle Graphics as well.
		if DRAW:
			sendingColorBuffer = TurtleBuffer(sender=sender)
		else:
			sendingColorBuffer = SendingBuffer(sender=sender)

		# Put some known colors at the beginning.
		for c in Sequences.GetSentinels():
			sendingColorBuffer.insertAndPop(c)

		for c in colorSequence:
			t = time.time()

			# Insert the next color into one end of the strip (and
			# pop the oldest color from the other end).
			sendingColorBuffer.insertAndPop(c)
			"""
			insertAndPop, see Buffer.py
			Insert the given Color into the beginning (index 0) of the color
			list, and pop a Color from the end (maintaining size).
			"""

			# Send the updated colors to the Arduino.
			sendingColorBuffer.send(data_receiver_color_key="COLOR2")
			sendingColorBuffer.send(data_receiver_color_key="COLORS")
			sys.stdout.write('.')
			sys.stdout.flush()
コード例 #6
0
    speed=5.0))
  color_sender.Append(Pulser(
      color=Color(rgb=(0, 0, 1)),
      reverse=True,
      add_delay=3.0))

  # Open the serial device (connection to the Arduino).
  if DUMMY_SERIAL:
    serial_sender = data_sender.DummySender(SERIAL_DEVICE, silent=True)
  else:
    serial_sender = data_sender.Sender(SERIAL_DEVICE)

  with serial_sender:
    color_sender.SetSender(serial_sender)

    t = time.time()
    actual_trials = 0
    exc_count = 0

    # Continue updating until all the Patterns expire.
    # If this does not happen, wait for control-C.
    print 'Type ^C (hold control, press c) to stop.'
    try:
      while True:
        actual_trials += 1
        try:
          color_sender.UpdateAndSend()  # Uses serial_sender to send the colors.
          serial_sender.ReadAndPrint()  # Reads any responses from the Arduino.
        except data_sender.TimeoutError as e:
          print 'Timeout waiting for acknowledgement during read/write.'
          exc_count += 1
コード例 #7
0
        # SendingBuffer has a list of Color objects and encapsulates
        # requisite logic for generating bytes and sending.
        # For simulating, TurtleBuffer subclasses SendingBuffer and
        # draws to the screen using Turtle Graphics as well.
        if DRAW:
            sending_color_buffer = TurtleBuffer(sender=sender)
        else:
            sending_color_buffer = SendingBuffer(sender=sender)

        # Put some known colors at the beginning.
        for c in sequences.GetSentinels():
            sending_color_buffer.InsertAndPop(c)

        for c in color_sequence:
            t = time.time()

            # Insert the next color into one end of the strip (and
            # pop the oldest color from the other end).
            sending_color_buffer.InsertAndPop(c)

            # Send the updated colors to the Arduino.
            sending_color_buffer.Send()
            sys.stdout.write('.')
            sys.stdout.flush()

            sender.ReadAndPrint()

            dt += time.time() - t

    print 'Elapsed per %d updates: %.2fs' % (TRIALS, dt)