From 678dfb7e93f1d613fb9a513d60a685d5e3c1c3b3 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 18 Jul 2015 22:51:24 +0200 Subject: o First round of low power, going low power when sleeping. --- trygvisio_soil_moisture.ino | 21 +++++++++++++++++++-- 1 file 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 #include #include #include #include -#include // 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() { -- cgit v1.2.3