saving in excel sheet
in
Programming Questions
•
7 months ago
I want to save two types of data in two separate boxes of an excel sheet . I'm saving the data coming through serial port & keeping an index . These two data (index & serial data) are saved in the same box. I want to have a separation of data boxes here.
Any sort of help is appreciated.
Here is the code :
(
Note: important lines in the code, related to the quarry, are highlighted as
yellow
)
- import processing.serial.*;
- import codeanticode.gsvideo.*;
- import controlP5.*;
- PFont fontB;
- PrintWriter output;
- GSCapture cam;
- Serial port;
- ControlP5 cp5;
- int id = 1;
- int time = 0;
- float distn = 0.00;
- float velocity = 0.00;
- String tripLineSeparation ;
- void setup()
- {
- size(640, 480);
- fontB = loadFont("ArialMT-16.vlw");
- textFont(fontB, 16);
- cp5 = new ControlP5(this);
- cp5.addTextfield("tripLineSeparation")
- .setPosition(10,5)
- .setSize(100,20)
- .setAutoClear(false)
- ;
- cp5.addBang("clear")
- .setPosition(10,45)
- .setSize(60,20)
- .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
- ;
- output = createWriter("velocity_data.csv");
- port = new Serial(this, "COM3", 9600);
- port.bufferUntil('\n');
- String[] cameras = GSCapture.list();
- if (cameras.length == 0)
- {
- println("There are no cameras available for capture.");
- exit();
- }
- else
- {
- println("Available cameras:");
- for (int i = 0; i < cameras.length; i++)
- {
- println(cameras[i]);
- }
- cam = new GSCapture(this, 640, 480, cameras[0]);
- cam.start();
- }
- }
- void draw()
- {
- if (cam.available() == true)
- {
- cam.read();
- image(cam, 0, 0);
- noStroke();
- fill(14, 103, 148, 180);
- rect(140, 5, 100, 40);
- fill(255);
- text(tripLineSeparation + " " + "m" , 160,30);
- fill(245);
- text("current trip " ,140 ,60 );
- text("separtion" ,140 ,76 );
- noStroke();
- fill(0 ,102 ,102 , 200);
- rect(250, 5, 400, 40 );
- fill(0);
- text("Index:", 270,30);
- fill(255);
- text(id ,330 ,30);
- int s = second();// values for 1 to 60
- int m = minute();// values for 1 to 60
- int h = hour();
- String t = nf(h,2) + ":" + nf(m,2) + ":" + nf(s,2) + ".";
- fill(0);
- text("Time:",480 ,30);
- fill(234 ,239 ,49);
- text(t ,526 ,30);
- int d = day(); // Values from 1 to 31
- int mn = month(); // Values from 1 to 12
- int y = year(); // Returns four-digit year (2007, 2008, etc.)
- String dt = nf(d,2) + ":" + nf(mn,2) + ":" + nf(y,2);
- fill(237,241,81);
- text("Date:",5 ,470);
- fill(255);
- text(dt ,46, 470);
- fill(0);
- text("vel:", 360 ,30);
- fill(255);
- text(velocity, 380, 30);
- fill(255);
- text("m/s",430, 30);
- println(velocity);
- }
- }
- public void clear()
- {
- cp5.get(Textfield.class,"tripLineSeparation").clear();
- }
- void serialEvent (Serial port)
- {
- String inString = port.readStringUntil('\n');//reading from serial data until new line
- if (inString != null)
- {
- //conversion of the string into integer
- inString = trim(inString);
- time = int(inString);
- tripLineSeparation = trim(tripLineSeparation);
- distn = float(tripLineSeparation);
- velocity = (distn *1000)/time; // calulating velocity from time
- //text(velocity, 380, 30);
- output.print(id);
- output.println(velocity);// writing to .csv file
- output.flush();// Write the remaining data to .csv file
- if(velocity >= 0.1)
- {
- id++;// incrementing the index in picture
- saveFrame("mine-#######.jpg");// saving the whole frame
- }
- }
- }
1