Guest User

Untitled

a guest
Jan 23rd, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. unsigned long startMillis = millis();
  2. while (millis() - startMillis < LONG_DELAY_MS);
  3.  
  4. #include <avr/sleep.h>
  5. // This variable is made volatile because it is changed inside an interrupt function
  6. volatile int sleep_count = 0; // Keep track of how many sleep cycles have been completed.
  7. const int interval = 720; // Interval in minutes between waking and doing tasks.
  8. const int sleep_total = (interval*60)/8; // Approximate number of sleep cycles
  9. // needed before the interval defined above elapses. Not that this does integer math.
  10.  
  11. void setup(void) {
  12. watchdogOn(); // Turn on the watch dog timer.
  13. // Disable the ADC by setting the ADEN bit (bit 7) to zero.
  14. ADCSRA = ADCSRA & B01111111;
  15. // Disable the analog comparator by setting the ACD bit (bit 7) to one.
  16. ACSR = B10000000;
  17. // Disable digital input buffers on all analog input pins by setting bits 0-5 to one.
  18. DIDR0 = DIDR0 | B00111111;
  19. }
  20.  
  21. void loop(void) {
  22. goToSleep(); // ATmega328 goes to sleep for about 8 seconds
  23. // and continues to execute code when it wakes up
  24. if (sleep_count == sleep_total) {
  25. // CODE TO BE EXECUTED PERIODICALLY
  26. }
  27. }
  28.  
  29. void goToSleep() {
  30. set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode.
  31. sleep_enable(); // Enable sleep mode.
  32. sleep_mode(); // Enter sleep mode.
  33. // After waking from watchdog interrupt the code continues
  34. // to execute from this point.
  35. sleep_disable(); // Disable sleep mode after waking.
  36. }
  37.  
  38. void watchdogOn() {
  39. // Clear the reset flag, the WDRF bit (bit 3) of MCUSR.
  40. MCUSR = MCUSR & B11110111;
  41. // Set the WDCE bit (bit 4) and the WDE bit (bit 3) of WDTCSR.
  42. WDTCSR = WDTCSR | B00011000;
  43. // Set the watchdog timeout prescaler value to 1024 K
  44. // which will yeild a time-out interval of about 8.0 s.
  45. WDTCSR = B00100001;
  46. // Enable the watchdog timer interupt.
  47. WDTCSR = WDTCSR | B01000000;
  48. MCUSR = MCUSR & B11110111;
  49. }
  50.  
  51. ISR(WDT_vect)
  52. {
  53. sleep_count ++; // keep track of how many sleep cycles have been completed.
  54. }
  55.  
  56. for (unsigned int bigloop=0; bigloop<65535; bigloop++)
  57. {
  58. for (unsigned int smallloop=0; smallloop<65535; smallloop++)
  59. {
  60. for (unsigned int tinyloop=0; tinyloop<65535; tinyloop++)
  61. {
  62. delay(65535);
  63. }
  64. }
  65. }
  66.  
  67. longDelayInSeconds = 120; //two minutes;
  68. while (p < longDelayInSeconds) {
  69.  
  70. delay(1000);
  71. p++;
  72.  
  73. }
  74.  
  75. for (int Hours = 0; Hours < 12; Hours++) { //Creates 12 hours
  76. for (int Minutes = 0; Minutes < 60; Minutes++) { //Creates 1 hour
  77. for (int Seconds = 0; Seconds < 60; Seconds++) { //Creates 1 minute
  78. delay(1000); //Creates 1 second
  79. }
  80. }
  81. }
Add Comment
Please, Sign In to add comment