I am using ATTiny2313, program with UNO.
I use a switch on attach interrupt input, suppose to be Interrupt on FALLING.
The switch is normally LOW. When switch is tun on, it go High and when the switch is OFF. It shall activate the interrupt because there is a falling from high to low state.
The actual I get when i connected my circuit is the interrupt is turn on when the switch just Turn on instead of Turn OFF. I suspect this is due to glitches on the switch. My code is below.
int ledPin = 0;
long previousMillis = 0;
long interval = 30000; //30 sec
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
attachInterrupt(0, turnOnLed, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
}
void turnOnLed(){
unsigned long currentMillis = millis();
digitalWrite(ledPin, HIGH);//use pwm is better
if(currentMillis - previousMillis > interval){
digitalWrite(ledPin, LOW);
previousMillis = currentMillis;
}
}
Is there any solution to this by software as I try to avoid hardware solution.