Hi i have the following code written and tested...it works with some strangeness...the led dims three times before going to on or off state....
I think the debounce is not working properly...i guess there is some modification needed in my code....some hints and tips please...thanks in advance for you time
ps my input pin is pulled high...so should work when grounded or button pressed
//////////////////////////////////////////////////////////////////////
int led = 12;
int presentState=1;
int buttonPress,countLow,countHigh;
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
buttonPress=digitalRead(3); //pin 3 is pulled high......so the function is activated only when button pressed and pin3 connected to ground....
if(buttonPress==LOW)
{
countLow++;//get some increment to assure the button is pressed continuously...manually...~~
countHigh=0;
}
else
{
countHigh++; //~~
countLow=0;
if(countHigh>60)
countHigh=60;
}
if(countLow>40)//when pressed long eg...40 machine cycles.....i hope we can eliminate debounce
{
presentState=!presentState;
}
else
{
presentState=presentState;
}
digitalWrite(13,presentState);
}
//////////////////////////////////////////////////////////////////////