#include #define samp_siz 4 #define rise_threshold 5 #define irPts 10 // set up LEDs and transistor int sensorPin = 1; int REDLed = 6; int IRLed = 0; int beatLed = 5; 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); pinMode(beatLed,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); if (print_value > 40 && print_value < 80) { digitalWrite(beatLed,HIGH); } 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; digitalWrite(beatLed,LOW); /* Serial.print(last-irZero); Serial.print(","); Serial.print(0); Serial.print(","); Serial.print(print_value); */ } before = last; // Serial.println(); } // while(1) }