powerGood.ino 859 B

123456789101112131415161718192021222324252627282930
  1. unsigned long lastPwrCheck_millis = 0;
  2. boolean powerOut = false;
  3. void checkPowerGood() {
  4. //if ((millis() - lastPwrCheck_millis) >= 1000) {
  5. // Serial.println(analogRead(A3));
  6. // lastPwrCheck_millis=millis();
  7. //}
  8. if (powerGoodMinValue > 0) {
  9. if (!powerOut && analogRead(PIN_IN_ADC_PWRGOOD) < powerGoodMinValue) {
  10. powerOut = true;
  11. saveAllCurrentData(false);
  12. Serial.println("POWER IS GOING DOWN...");
  13. //doHardreset();
  14. }
  15. else if (powerOut && analogRead(PIN_IN_ADC_PWRGOOD) > (powerGoodMinValue + 20)) {
  16. powerOut = false;
  17. Serial.println("POWER RESTORED...");
  18. }
  19. }
  20. }
  21. void printPowerValue() {
  22. Serial.print(F("POWER: pwrCurr="));
  23. Serial.print(analogRead(PIN_IN_ADC_PWRGOOD));
  24. Serial.print(F(", pwrGood="));
  25. Serial.print(powerGoodMinValue);
  26. Serial.println();
  27. }