Bidirectional led sensing + Processing visualization

I wanted to combine the Arduino's led sensing capabilities with Processing. It's simpler than I thought.

Arduino can send serial signals back to the computer over USB, at 9600 baud. The arduino sends the value of the time it takes for the cathode of the sensor LED to fall. (What this 'value' is based on I'm not sure -- as seen in the post before, it's measured by a while loop that increments a counter with no delay. It probably depends on the clock of the chip or something like that.) We can send said values with Serial.print().

Processing has libraries for serial input that are built-in. Serial() is a constructor for a Serial class that initializes a serial connection, read() reads a value, et cetera. By checking whether or not the serial connection is available, then reading input, we can get the value of the input.

I whipped something up that takes the values of the input and stores them in an ArrayList, deleting the oldest value, and adding the newest one. This way, deleting elements and adding them are constant-time. The bars representing the older values are darker, while the newer values are lighter, and for the sake of being pretty, I mirrored everything.

Here's the Processing code.

And here's what it looks like:

My hand is unnaturally yellow, and that isn't James Brown in the background but Justice.

Posted by provolot on May 20, 2007 3:47 PM | | Comments (0)


TrackBack URL for this entry:

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)