Read analog sensor from AD8232, Question

i try to run this code using arduino uno and AD8232, and display the analog graph of electrocardiogram(ECG). if your know about this problem please tell me.

Thanks.

Bellow is my code on .ino

unsigned int average_value[60];
int i = 0;

long lastDebounceTime = 0;
long debounceDelay = 300;

long counter = 0;

void setup() {
// initialize the serial communication:
Serial.begin(9600);
pinMode(10, INPUT); // Setup for leads off detection LO +
pinMode(3, INPUT); // Setup for leads off detection LO -

attachInterrupt(0, right_Hand_Detect, FALLING);
//attachInterrupt(1, left_Hand_Detect, FALLING);

}

void loop() {
float sum = 0.0;
float average = 0.0;

if((digitalRead(10) == 1)||(digitalRead(11) == 1)){
Serial.print('!');
}
else{
//Serial.print('@');
if ((millis() - lastDebounceTime) > debounceDelay){
average_value = analogRead(A0);

  • i++;*

  • if (i >= 30){*

  • for (int j = 0; j < 60; j++){*

  • sum = sum + average_value[j];*

  • if (average_value[j] > 370){*

  • Serial.println(average_value[j]);*

  • }*

  • //Serial.println(average);*

  • }*

  • average = sum/60.0;*

  • //Serial.print("The Average is: ");*

  • //Serial.println(average);*

  • i = 0;*

  • }*

  • }*

  • }*

  • //Wait for a bit to keep serial data from saturating*

  • delay(1);*
    }
    void right_Hand_Detect(){

  • if(digitalRead(3) == 0){*

  • //Serial.print(counter);*

  • //Serial.println("Right hand");*

  • //counter++;*

  • lastDebounceTime = millis();*

  • Serial.println(lastDebounceTime);*

  • }*
    }

Since you did not post your code properly in code tags, the forum software mangled your code. Read the "how to use the forum-please read" sticky to see how to post code. Edit your post to put the code in code tags. Can't be of much help until the code is readable and complete.

One thing that I see is that you are doing Serial.print in an ISR (Interrupt Service Routine). Serial print depends on interrupts, interrupts are disabled in an ISR. See the problem?