Created
July 1, 2016 19:13
-
-
Save javorosas/546b3cfe7643b2a13d2f0fe68020352a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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