You are on page 1of 1

BPM Counter Example1

#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];

// Will be used with sprintf to create strings

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);
}

// Clear the display before jumping into loop


clearDisplay();

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);

if (beats > 0 && !done) {


// update the display
bpm = beats*3;
sprintf(tempString, "%4d", bpm);
} else {
sprintf(tempString, "%4d", 9999);
}
// This will output the tempString to the S7S
s7s.print(tempString);
setDecimals(0b00000000); // Sets digit 3 decimal on

You might also like