accumulating data in arrays
in
Programming Questions
•
1 year ago
Hi, I'm a massive noob to programming and I'm trying to bash together some code to plot data from the serial cable sent by my Arduino. The data comes in as individual lines of comma separated values from a few temperature and light sensors. Using code from
this thread I can split the CSV values and convert them to floats but I'm struggling to work out how then to add them to an array for real time plotting. I can't find the blog that I got the plotting code from but it needs the data as arrays.Can someone help me out?
Many thanks,
- import processing.serial.*; // serial library
- Serial myPort; // The serial port
- String inBuffer = null; // one line of data from serial port
- void setup () {
- // List all the available serial ports
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[2], 9600);
- }
- void draw () {
- // everything happens in the serialEvent()
- }
- void serialEvent (Serial myPort) {
- // get the ASCII string:
- String inString = myPort.readStringUntil('\n');
- if (inString != null) {
- // trim off any whitespace:
- inString = trim(inString);
- float[] dat; // array of numbers read in on one line from serial port
- println("SERIAL:" + inString); // show the line of serial input
- dat = float(split(inString, ',')); // parse comma-separated number string into numbers
- println("DAT_IN:" + dat[0] + "," + dat[1] + "," + dat[2]);
- println();
- float[] arrayA = dat[0];
- float[] arrayB = dat[1];
- float[] arrayC = dat[2];
- println(arrayA);
- println(arrayB);
- println(arrayC);
- }
- }
1