help - arduino firmware and heart rate monitor

  • FTDI buffer using Serial.print() /
    checkDigitalInputs();
    if(timer0_overflow_count > nextExecuteTime) {
    nextExecuteTime = timer0_overflow_count + 19; // run this every 20ms
    /
    SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
  • all serialReads at once, i.e. empty the buffer /
    checkForSerialReceive();
    /
    SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over
  • 60 bytes. use a timer to sending an event character every 4 ms to
  • trigger the buffer to dump. */

/* ANALOGREAD - right after the event character, do all of the

  • analogReads(). These only need to be done every 4ms. */
    for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
    if( analogPinsToReport & (1 << analogPin) ) {
    analogData = analogRead(analogPin);
    Serial.print(ANALOG_MESSAGE + analogPin, BYTE);
    // These two bytes converted back into the 10-bit value on host
    Serial.print(analogData % 128, BYTE);
    Serial.print(analogData >> 7, BYTE);
    }
    }
    }
    }

void loop()
{
heartDetect = digitalRead(heart);
//assigns value of pin to a variable

if ((heartDetect == HIGH) && (prevState == 0)){
prevState = 1;
heartRate = heartRate + 1;
//Used to add each heart beat to the next
}
else if (heartDetect == LOW) {
prevState = 0;
}

if (millis() - previousPrintTime > 10000){
previousPrintTime = millis();
Serial.print(heartRate, DEC);
Serial.print(0, BYTE);

heartRate = 0;
//Above statement sends values to the serial port which are pulled in by Flash
}

}