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方面和處理方面的代碼進行一些更改。
如果有人能幫助我,我會很感激。
謝謝。