We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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++;
}
} }
Answers
@mateuszk95 --
Are you trying to save a screenshot image? If so, have you looked at saveFrame()?
Yes I have tried the saveFrame function but I do not want a screenshot. When the code is running it is real time ECG waveform, I would like to record possibly 10seconds of it or more if possible and save it and then replay it. Any ideas?
There are different examples if you browse previous posts. You will need to review some of them and find one that would fit your purposes and your likes. Previous relevant posts:
https://forum.processing.org/two/search?Search=arduino
One that could be useful:
https://forum.processing.org/two/discussion/comment/88886#Comment_88886
This last one triggers data collection above a certain threshold value related to the nature of the input signal. It could be modified to collect a data sample of certain time length or a specific number of points.
Kf