Skip to content

Instantly share code, notes, and snippets.

@DexterHaslem
Last active August 20, 2022 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DexterHaslem/c5ab03960ad418f6421dfec9c8de225c to your computer and use it in GitHub Desktop.
Save DexterHaslem/c5ab03960ad418f6421dfec9c8de225c to your computer and use it in GitHub Desktop.
throwaway voltage runtime set and forget timer
// 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