#include #define samp_siz 4 #define rise_threshold 4 #define irPts 10 // set up LEDs and transistor int sensorPin = A1; int REDLed = 4; int IRLed = 3; int T = 20; // slot milliseconds to read a value from the sensor void setup() { // set the connection to computer and clear data: Serial.begin(9600); Serial.flush(); // set up the arduino pins for I/O pinMode(sensorPin,INPUT); pinMode(REDLed,OUTPUT); pinMode(IRLed,OUTPUT); // flash red LED to say hello for (int i=0;i<3;i++){ digitalWrite(REDLed,HIGH); delay(1000); digitalWrite(REDLed,LOW); delay(1000); } } void loop() { // initialise some variables int n; float irSignal; float reads[samp_siz]; float sum,start,last,before,first,second,third,print_value; int rise_count; bool rising; long int last_beat; float irZero=0; for (int i=0;i before) { rise_count++; if (!rising && rise_count > rise_threshold) { rising = true; first = millis() - last_beat; last_beat = millis(); // Calculate the weighed average of heartbeat rate // according to the three last beats print_value = 60000. / (0.4*first+0.3*second+0.3*third); third = second; second = first; Serial.print(last-irZero); Serial.print(","); Serial.print(last-irZero); Serial.print(","); Serial.print(print_value); } } else { rising = false; rise_count = 0; Serial.print(last-irZero); Serial.print(","); Serial.print(0); Serial.print(","); Serial.print(print_value); } before = last; Serial.println(); } // while(1) }