i tried to use interrupts to debounce my buttons but my code registers two button presses, and the second "press" comes in at my debounce time (i.e. if i set debounce time to 1 second, the second press comes in after 1 sec).
// CHANGES THE DEFAULT GAME TIME
while(dip1==1){
dip1 = digitalRead(timePin); // read the input pin for dipswitch 1
if(millis() - interrupt0Time >= 1000){
attachInterrupt(0, digitSelect, RISING);
}
if(millis() - interrupt1Time >= 1000){
attachInterrupt(1, timeSelect, RISING);
}
if(dip1==0){
disp1Metro.reset();
disp2Metro.reset();
}
if(blinkMetro.check() == 1){
blinkMetro.reset();
shiftOut(dataPin, clockPin, MSBFIRST, d2);
shiftOut(dataPin, clockPin, MSBFIRST, c2);
shiftOut(dataPin, clockPin, MSBFIRST, b2);
shiftOut(dataPin, clockPin, MSBFIRST, a2);
timeDelay = millis();
}
if(millis() - timeDelay >= 100){
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, c);
shiftOut(dataPin, clockPin, MSBFIRST, b);
shiftOut(dataPin, clockPin, MSBFIRST, a);
}
}
}
void digitSelect(void){
setDigit += 1;
if(setDigit >= 4){
setDigit = 0;
}
switch(setDigit){
case 0:
d2 = 0x78;
c2 = c;
b2 = b;
a2 = a;
break;
case 1:
d2 = d;
c2 = 0x78;
b2 = b;
a2 = a;
break;
case 2:
d2 = d;
c2 = c;
b2 = 0x78;
a2 = a;
break;
case 3:
d2 = d;
c2 = c;
b2 = b;
a2 = 0x78;
break;
}
interrupt0Time = millis();
detachInterrupt(0);
}
void timeSelect(void){
if(d2==0x78){
d += 1;
if(d >= 10){
d = 0;
}
}
else if(c2==0x78){
c += 1;
if(c >= 10){
c = 0;
}
}
else if(b2==0x78){
b += 1;
if(b >= 10){
b = 0;
}
}
else{
a += 1;
if(a >= 10){
a = 0;
}
}
interrupt1Time = millis();
detachInterrupt(1);
}
btw, can i use pins 2 and 3 as normal inputs for the majority of my code (where i don't need debouncing) and still use them as interrupts in the portion of code i pasted above (where i need debouncing)?