Last active
August 20, 2022 21:48
-
-
Save DexterHaslem/c5ab03960ad418f6421dfec9c8de225c to your computer and use it in GitHub Desktop.
throwaway voltage runtime set and forget timer
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
// simple voltage babysitter. hook up eg battery or a dcdc output to d7 to get total minutes | |
// it was digital high. this is useful to see effective runtime of a battery fed boost buck system etc | |
#define BAT_PIN (7) | |
#define DEGLITCH (5) | |
static unsigned int on_minutes = 0; | |
static unsigned char c = 0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(BAT_PIN, INPUT); | |
} | |
void loop() { | |
for (int i = 0; i < DEGLITCH; ++i) { | |
if (digitalRead(BAT_PIN)) { | |
++c; | |
} | |
} | |
if (c >= DEGLITCH) { | |
++on_minutes; | |
} | |
c = 0; | |
Serial.print(F("on minutes: ")); | |
Serial.print(on_minutes, DEC); | |
Serial.print(F("\r\n")); | |
delay(59999); // one minute | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment