diff options
-rw-r--r-- | trygvisio_soil_moisture.ino | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index e524f71..8185754 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -1,8 +1,8 @@ +#include <LowPower.h> #include <EEPROM.h> #include <SPI.h> #include <lib_aci.h> #include <aci_setup.h> -#include <avr/sleep.h> // See config.h on how to configure the sketch #include "config.h" @@ -34,6 +34,16 @@ void __ble_assert(const char *file, uint16_t line) while(1); } +#if defined(__AVR_ATmega32U4__) +static void go_to_sleep() { + LowPower.idle(SLEEP_1S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF); +} +#else +#warning No sleep support for current CPU architecture. +static void go_to_sleep() { +} +#endif + void setup() { #if defined(BLEND_MICRO_8MHZ) // As the F_CPU = 8000000UL, the USB core make the PLLCSR = 0x02 @@ -96,7 +106,7 @@ static void setup_rf() { aci_state.aci_pins.active_pin = UNUSED; aci_state.aci_pins.optional_chip_sel_pin = UNUSED; - aci_state.aci_pins.interface_is_interrupt = false; //Interrupts still not available in Chipkit + aci_state.aci_pins.interface_is_interrupt = false; aci_state.aci_pins.interrupt_number = 4; // We reset the nRF8001 here by toggling the RESET line connected to the nRF8001 @@ -341,6 +351,13 @@ void loop() { } sm_loop(); + +#ifdef SM_DEBUG + Serial.println(F("Sleeping...")); + Serial.flush(); +#endif // SM_DEBUG + + go_to_sleep(); } static void show_pipes() { |