Guest User

Charging

a guest
Sep 17th, 2015
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef CHARGING
  2. if (adc_ticks > 0) {
  3. --adc_ticks;
  4. }
  5. if (adc_ticks == 0) {
  6. // See if conversion is done
  7. if (PINB & (1 << STAR3_PIN)) {
  8. // See if voltage is lower than what we were looking for
  9. if (ADCH < ((mode_idx == 1) ? 255)) {
  10. ++lowbatt_cnt;
  11. } else {
  12. lowbatt_cnt = 0;
  13. }
  14. }
  15.  
  16. // See if it's been low for a while
  17. if (lowbatt_cnt >= 4) {
  18. prev_mode();
  19. lowbatt_cnt = 0;
  20. // If we reach 0 here, main loop will go into sleep mode
  21. // Restart the counter to when we step down again
  22. adc_ticks = 0;
  23. }
  24.  
  25. // Make sure conversion is running for next time through
  26. ADCSRA |= (1 << ADSC);
  27. }
  28. #endif
RAW Paste Data