Hi I am trying to detect pin change from the out put pin of a laser detector circuit i.e the output of an op amp is my input for interrupt pin But i cant seem to get it right because the count keeps on increasing and increasing. dnt know what is the problem. I've tried to debounce it by putting an rc circuit in front of the pin but no use. please help.
Here is my code:
include
define mypin 3
//#define m2 13
volatile int a=0;
volatile int a1=0;
void func(){
//digitalWrite(m2,1);
//delay(10);
//digitalWrite(m2,0);
a1=a;
a++;
}
Hi I am trying to detect pin change from the out put pin of a laser detector circuit i.e the output of an op amp is my input for interrupt pin But i cant seem to get it right because the count keeps on increasing and increasing. dnt know what is the problem. I've tried to debounce it by putting an rc circuit in front of the pin but no use. please help.
Here is my code:
include
define mypin 3
//#define m2 13
volatile int a=0; volatile int a1=0; void func(){ //digitalWrite(m2,1); //delay(10); //digitalWrite(m2,0); a1=a; a++; }
void setup(){ pinMode(mypin, INPUT_PULLUP); // pinMode(m2, OUTPUT);
attachPinChangeInterrupt(mypin,func, CHANGE); Serial.begin(9600); Serial.println("---------------------------------------");
}
void loop(){ // a=1; // a=0;
//if(a==1) //{ // Serial.println("i HAVE BEEN THERE IT WAS HORRIBLE"); // a=0; //} Serial.print("a="); Serial.println(a,DEC); //delay(750); }