Assignment 5.3
Post date: Jun 30, 2010 11:32:37 PM
The code begins at the processing sketch. The serial library is included and declarations are made. In setup(), the size is set to 200 x 200, and the serial port variable is set up at port 0 at 9600 bps. Then in the Draw() function, the background is set to white and the mouse coordinates are tested to be within the boundaries of a rectangle (not yet drawn) with corners at (50, 50) (50, 150) (150, 50) and (150, 150). If the mouse is within these coordinates, the color of the rectangle is set to a light gray (or at least will when it is drawn) and the character 'H' (standing for "HIGH" I assume) is written to the serial port "myPort". However, if the mouse is outside these coordinates, the rectangle's color becomes black and the character 'L' (for LOW) is written to the serial port. Finally, the rectangle is drawn outside of the if… else statement.
Essentially by testing a statement and sending high or low depending on the outcome, the processing sketch is simulating a pin on the arduino board, making it more or less a push button that operates through the serial port.
The data is then read in arduino. After all the obvious setup, the loop simply turns the LED on if the character read was an H and turns it off if the character was an L, and then delays for 10 miliseconds.