Esempio n. 1
0
        # 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)
    print 'Updates per second: %.2f' % (TRIALS / dt)