Skip to content

Pin Change Interrrupt from a sensor #2

@rafeey1234

Description

@rafeey1234

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.

problem

Here is my code:

include <PinChangeInt.h>

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions