Saving a recording using Processing

edited March 2017 in Library Questions

Hi guys, I'm working on a ECG device for my project. How do I save a recording of the waveforms that I read in the processing to the hard disc? Here is the recording of a waveform that I want to save: http://tinypic.com/r/2r1zfx5/9

Below is the code:

import processing.serial.*;

Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph float height_old = 0; float height_new = 0; float inByte = 0;

void setup () { // set the window size: size(1000, 400);

// List all the available serial ports println(Serial.list()); // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); // set inital background: background(0xff); }

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);

// If leads off detection is true notify with blue line
if (inString.equals("!")) { 
  stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)
  inByte = 512;  // middle of the ADC range (Flat Line)
}
// If the data is good let it through
else {
  stroke(0xff, 0, 0); //Set stroke to red ( R, G, B)
  inByte = float(inString); 
 }

 //Map and draw the line for new data point
 inByte = map(inByte, 0, 1023, 0, height);
 height_new = height - inByte; 
 line(xPos - 1, height_old, xPos, height_new);
 height_old = height_new;

  // at the edge of the screen, go back to the beginning:
  if (xPos >= width) {
    xPos = 0;
    background(0xff);
  } 
  else {
    // increment the horizontal position:
    xPos++;
  }

} }

Tagged:

Answers

Sign In or Register to comment.