Example #1
0
        sender = data_sender.Sender(SERIAL_DEVICE)
    # Open the serial connection.
    with sender:

        # 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()