0
我正在使用Olimex EKG Shield与Arduino Uno。将无限循环EKG数据保存为.txt文件
void setup() {
// put your setup code here, to run once:
// initialize serial communication at 9600 bits per second:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float value = sensorValue * (5.0/1023.0);
// print out the value you read:
Serial.println(value);
}
有了此处提供的代码,我正在从0-5V电压值。 由于它是一个循环,数据保持在串行监视器中显示,直到断开连接。因此,我想要做的是测量一段时间的ECG(比方说5分钟)或数据点(比方说100万分),然后将这些数据保存到.txt文件中。
//From Arduino to Processing to Txt or cvs etc.
//import
import processing.serial.*;
//declare
PrintWriter output;
Serial udSerial;
void setup() {
udSerial = new Serial(this, Serial.list()[0], 115200);
output = createWriter ("data.txt");
}
void draw() {
if (udSerial.available() > 0) {
String SenVal = udSerial.readString();
if (SenVal != null) {
output.println(SenVal);
}
}
}
void keyPressed(){
output.flush();
output.close();
exit();
}
我发现,从Arduino的串口监听进口数据并保存为.txt文件该处理的代码,但它不不知何故工作。
我想我需要对Arduino方面和处理方面的代码进行一些更改。
如果有人能帮助我,我会很感激。
谢谢。