Pass an Array of Serial Values
in
Core Library Questions
•
1 years ago
Hey I am having trouble with creating an array of serial values and using the values. I can get the serial values in, change it to a float and print out the value but I can't seem to find a way to use the values in the circle function. The serial information is coming from a ping sensor through arduino. What I am trying to achieve is
1.put the serial values into a array,
2.get an average value of the serial data from the array
3. pass the average value onto another function - circle()
4. use average value to do stuff
I have added a portion of the code.
can anyone help.....
cheers
ekinsy
1.put the serial values into a array,
2.get an average value of the serial data from the array
3. pass the average value onto another function - circle()
4. use average value to do stuff
I have added a portion of the code.
- import processing.serial.*;
Serial myPort;
// float [] maxValues;
float average, sum;
float pulse;
float maxValues[] = new float[10]; - average = 0;
sum = 0;
void serialEvent (Serial myPort) {
String bufferString = myPort.readStringUntil('\n'); // get the string from the serial buffer if (bufferString != null) {
bufferString = trim(bufferString); // get rid of any whitespace
float maxValues = float(bufferString); // declare a variable to hold our value.
maxValues = map(maxValues,0,350,0,1);
}
//in the loop assign a value to each index in the "maxValues" array
for(int i = 0; i <= maxValues.length; i++) {
maxValues[i] = maxValues[i];
}
//to calculate the average sum all the values inside the maxValues array
for(int i = 0; i < maxValues.length;) {
sum += maxValues[i];
}
average = sum/maxValues.length;
println(average);
}
void circle() {
//do stuff
}
can anyone help.....
cheers
ekinsy
1