Skip to content

Instantly share code, notes, and snippets.

@javorosas
Created July 1, 2016 19:13
Show Gist options
  • Save javorosas/546b3cfe7643b2a13d2f0fe68020352a to your computer and use it in GitHub Desktop.
Save javorosas/546b3cfe7643b2a13d2f0fe68020352a to your computer and use it in GitHub Desktop.
#include <RTCZero.h>
const byte button = 5;
bool ledIsOn = false;
volatile bool shouldBeSleeping = false;
volatile bool isResetPressed = false;
bool wasResetPressed = false;
int millisLastTimeResetWasPressed = 0;
RTCZero rtc;
void setup() {
delay(5000);
rtc.begin();
pinMode(button, INPUT);
Serial.begin(115200);
while (!Serial) {
;
}
Serial.println("== Interrupt test ==");
// attachInterrupt(button, resetNP, HIGH);
attachInterrupt(button, resetHigh, RISING);
// attachInterrupt(button, resetLow, FALLING);
}
void loop() {
// Serial.println(millis());
// if (isResetPressed && !wasResetPressed) {
// Serial.println("Reset has just been pressed");
// millisLastTimeResetWasPressed = millis();
// wasResetPressed = true;
// detachInterrupt(button);
// attachInterrupt(button, resetLow, LOW);
// } else if (!isResetPressed && wasResetPressed) {
// Serial.println("Reset has just been released");
// int duration = millis() - millisLastTimeResetWasPressed;
// Serial.println(duration);
// wasResetPressed = false;
// detachInterrupt(button);
// attachInterrupt(button, resetHigh, HIGH);
// }
// if (shouldBeSleeping) {
// Serial.println("Now going to sleep");
// rtc.standbyMode();
// }
// digitalWrite(LED_BUILTIN, ledIsOn = !ledIsOn);
// delay(1000);
if (isResetPressed) {
Serial.println("Back to the main loop!");
isResetPressed = false;
// attachInterrupt(button, resetLow, FALLING);
}
}
void resetNP() {
return;
}
void resetHigh() {
Serial.println("high");
isResetPressed = true;
// detachInterrupt(button);
}
void resetLow() {
Serial.println("low");
isResetPressed = false;
// detachInterrupt(button);
// attachInterrupt(button, resetHigh, HIGH);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment