void setup() { // put your setup code here, to run once: Serial.begin(9600); } bool inPeak = false; bool upSlope = false; int numBeats = 0; int array[3] = {0,0,0}; int array2[200]; int jj = 0; int heartRate = 0; void loop() { // put your main code here, to run repeatedly: int heartVoltage = analogRead(A4); array[0] = array[1]; array[1] = array[2]; array[2] = heartVoltage; for (int i = 0; i < 3; i++){ Serial.print(array[i]); Serial.print(" "); } if(array[0] < array[1] && array[1] < array[2] && array[2] - array[0] > 150){ if(!upSlope) { numBeats++; } upSlope = true; // Serial.print(" upslope"); } else{ upSlope = false; } Serial.print(numBeats); if (jj == 300){ heartRate = numBeats * 4; jj = 0; Serial.print("--------------------"); Serial.println(heartRate); numBeats = 0; } int count = heartVoltage; while (count > 50) { Serial.print("|-"); count = count - 50; } Serial.println(); jj = jj +1; delay(50); }