Hello,
The following code is supposed to lit 2 leds (with a delay between them) whenever button is pressed. And also when first booted. When booted, it does it perfectly.
However, when button is pressed, both leds flash twice and nothing else happened.
I have tried "Rising" instead of "High" with no difference.
Debounce is important as the button is very noisy.
Appreciate any help.
//Arduino pro/mini running
long debouncing_time = 15; //Debouncing Time in Milliseconds
volatile unsigned long last_micros;
#define poweruppin 3
#define playbackpin 4
const byte interruptPin = 2;
volatile byte state = LOW;
long intervalogle = 10000; // interval at which to do something (milliseconds) 1 minute = 60,000
unsigned long previousMillisogle = 0;
long intervalaksam = 5000;
unsigned long previousMillisaksam = 0;
int firstrun = 1;
void setup()
{
pinMode(poweruppin, INPUT);
pinMode(playbackpin, INPUT);
pinMode(interruptPin, INPUT_PULLUP);
digitalWrite(poweruppin, LOW); //OFF by default
digitalWrite(playbackpin, LOW);
attachInterrupt(digitalPinToInterrupt(interruptPin), debounceInterrupt, HIGH);
Serial.begin(115200);
}
void loop()
{
if (firstrun == 1)
{
Serial.println("First run baby...");
showtime();
}
/*
unsigned long currentMillisogle = millis();
if(currentMillisogle - previousMillisogle > intervalogle)
{
previousMillisogle = currentMillisogle;
showtime();
}
*/
}
void showtime()
{
firstrun = 0;
Serial.println("Power up...");
digitalWrite(poweruppin, HIGH);
delay(5000);
Serial.println("Playback...");
digitalWrite(playbackpin, HIGH);
delay(30000); //wait for playback to complete
digitalWrite(poweruppin, LOW);
digitalWrite(playbackpin, LOW);
Serial.println("All Off...");
}
void debounceInterrupt() {
if((long)(micros() - last_micros) >= debouncing_time * 1000) {
Interrupt();
last_micros = micros();
}
}
void Interrupt() {
Serial.println("interrupt happened...");
showtime();
}