Arduino Port Code:
int red=255; Create variables to store the data to be sent
int green = 2;
int blue = 3;
void Setup ()
{
serial.begin (9600);//define a data transfer rate of 9600 bits
}
void Loop ()
{
serial.print (red);
Serial.print (",");
Serial.print (green);
Serial.print (",");
Serial.print (blue);
Serial.print ("\ n");
Delay (+);
}
Above red, Green,blue is replaced with the value obtained by the color sensor in the actual application. Processing-Side code:
Import processing.serial.*;//introduces serial library
int r = 0;
int g = 0;
int b = 0;
Serial myport;//Create a Serial object named "MyPort"
Void Setup () {
myport = new Serial (This, "COM7", 9600);
Myport.bufferuntil (' \ n '); Buffer until meet ' \ n ', then call the event listener
//define MyPort port and data transfer rate
//should be consistent with Arduino
}
void Draw () {
background (204);
Fill (R, G, b);
Rect (+,-);
}
Listen to the event. When the buffer filled, run this method
void Serialevent (Serial p) {
String instring = p.readstring ();
Print (instring);
string[] List = Split (instring, ', ');
List[0] is now "Chernenko", List[1] is "Andropov"
... r = Int (list[0]);
g = Int (list[1]);
b = Int (list[2]);
}