Post date: Jul 01, 2010 2:8:11 AM
This code starts in Processing, where it begins by including the Processing serial library. Then it goes on to declare val and Serial myPort. It sets up the size of the window, the serial port, and data is sent at 9600 bps. Each time draw is run, it tests where the cursor is. If it is within the certain parameters, it sends "H" to the specified port and changes the fill color. If the cursor is outside the parameters, it sends "L" to the specified port and changes the fill color.
It then goes into Arduino, where the variables are set. It sets up the LED, attached to pin 4, as an output, and begins serial communication at 9600 bps. It then reads what Processing is sending through the port and stores that as val. If Processing is sending "H" through the port, then the LED is set to high and lights up. If Processing is sending "L" through the port, the LED is set to low and turns off. Then there's a 10 millisecond delay before loop runs again.