Hi, I am learning how to program my Arduino chip using the book "Making things Talk". I am stumped on one of the programs it has made me write. I can not seem to debug it. There must be a syntax error but I cant figure it out, could someone please help me see what I have done wrong.
Here is the code:
When I try to compile it it gives me this error message.
"error: variable or field 'serialEvent' declared void In function 'void setup()':
At global scope:"
/*
Serial String Reader
Language: Processing
reads in a string of characters from a serial port
until it gets a linefeed (ASCII 10).
The splits the string into sections seperated by commas.
Then converts the sections to ints, and prints them out.
*/
import processing.serial.*; // import the Processing serial library
int linefeed = 10; //Linefeed in ASCII
Serial myPort; //The serial port
void setup() {
//List all the available serial ports
println(Serial.list());
//I know that the first port in the serial list on my mac is always my Arduino module,
//so I open Serial.list () [0]. Change 0 to the apropriate number of the serial port
//that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[3],9600);
//read bytes into a buffer until you get a linefeed (ASCII 10);
myPort.bufferUntil(linefeed);
}
void draw() {
// twiddle your thumbs
}
// serialEvent method is run automatically by the Processing sketch
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort){
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
//split the string at the commas
//and convert the sections into integers:
int sensors[] = int(split(myString, ','));
//print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ":" + sensors[sensorNum] + "\t");
}
//add a linefeed after all the sensor values are printed:
println();
}
}