Professional Documents
Culture Documents
#include <SoftwareSerial.h>
#include <math.h>
long measurementStartTime = 0;
int beats = 0;
byte pin = 10;
int currentSensorValue;
boolean counted = false;
unsigned long sensorValue;
int beat;
int bpm;
// These are the Arduino pins required to create a software seiral
// instance. We'll actually only use the TX pin.
const int softwareTx = 8;
const int softwareRx = 7;
const int refreshTime = 20000;
const int delayTime = 400;
const int missThreshhold = 20;
SoftwareSerial s7s(softwareRx, softwareTx);
char tempString[10];
void setup()
{
// Must begin s7s software serial at the correct baud rate.
// The default of the s7s is 9600.
s7s.begin(9600);
pinMode(pin, INPUT);
}
void loop()
{
measurementStartTime = millis();
int misses = 0;
bool done = false;
beats = 0;
while ((millis() - measurementStartTime < refreshTime)) {
currentSensorValue = digitalRead(pin);
if (currentSensorValue == 1) {
beats++;
} else {
misses++;
}
delay(delayTime);