在StackOverflow社区,
在过去的几周里,我一直没有找到解决我的问题的方法。我的问题是,我无法从Arduino创建的自制ECG中检索数据。我在这方面完全是个外行,但我很确定这是电路问题。这是我的电路现在的样子。(注:最左边写着“双O”的是仪表放大器,而不是像中间那样的运算放大器)
下面是我的代码:
const int signal = 5; // Pin connected to the filtered signal from the circuit
unsigned long currentBeatTime;
unsigned long previousBeatTime;
unsigned long frequency;
// Internal variables
unsigned long period = 0;
int input = 0;
int lastinput = 0;
void setup() {
pinMode(signal, INPUT);
Serial.begin(9600);
previousBeatTime = millis();
}
void loop() {
delay(500);
input = digitalRead(signal);
if ((input != lastinput) && (input == HIGH)) {
// If the pin state has just changed from low to high (edge detector)
currentBeatTime = millis();
period = currentBeatTime - previousBeatTime; // Compute the time between the previous beat and the one that has just been detected
previousBeatTime = currentBeatTime; // Define the new time reference for the next period computing
}
lastinput = input; // Save the current pin state for comparison at the next loop iteration
// Detect if there is no beat after more than 2 seconds
if ( (millis() - previousBeatTime) > 2000 )
{
Serial.println("dead");
}
else
{
if (period <= 0)
{
frequency = 0;
}
else
{
frequency = 60000/period; // Compute the heart rate in beats per minute (bpm) with the period in milliseconds
}
Serial.print(frequency);
Serial.println(" : alive! ");
}
}
如果有人能尽快回复我,我将不胜感激。谢谢!
发布于 2014-12-22 11:30:48
在电流通过LED之后,您看起来是在第5针上读取电压。LED会产生电压降,因此电压可能永远不会高到足以在digitalRead()调用中注册为高。可能更改了采样电压的位置,或者尝试使用analogRead()。
在任何情况下,您都需要确定这是一个与编程相关的问题,并将其发布在此板上。也许,electronics.stackexchange会提供更好的帮助。
https://stackoverflow.com/questions/27595354
复制相似问题