Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Convert Arduino serial numbers into variables?

$
0
0
Hello Processing community!

I'm trying to visualize some data gathered via Arduino in Processing. Right now, the Arduino collects a string of numbers via EEG, all separated by commas. I'm just really confused at to what I should do in processing to get the program to use these separate numbers as variables in a visualization...... Can anyone shed some light?  

Right now I have it so that Processing is able to print the serials form the Arduino:

  1. import processing.serial.*; //import the Serial library

  2. int end = 10; 
  3. String serial;
  4. Serial port;  

  5. void setup() {
  6.   port = new Serial(this, Serial.list()[0], 9600); 
  7.   port.clear();
  8.   serial = port.readStringUntil(end); 
  9.   serial = null;
  10. }

  11. void draw() {

  12.   while (port.available () > 0) { 
  13.     serial = port.readStringUntil(end);
  14.   }
  15.   if (serial != null) { 


  16.     String[] a = split(serial, ','); 

  17.     delay(100);
  18.     print("a[0] : "); 
  19.     println(a[0]); //print Value1 (in cell 1 of Array - remember that arrays are zero-indexed)
  20.     print("a[3] : ");
  21.     println(a[3]);
  22.     print("a[5] : ");
  23.     println(a[5]);
  24.     print("a[7] : ");
  25.     println(a[7]); //print Value7 value
  26.     delay(100);
  27.   }
  28. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles