From bfa80a629e33a1776053e029415835c37957ec17 Mon Sep 17 00:00:00 2001 From: r4 Date: Thu, 14 Apr 2022 20:48:27 +0200 Subject: [PATCH] component switch support to save power when waiting --- spybug/spybug.ino | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spybug/spybug.ino b/spybug/spybug.ino index 5120399..567d732 100644 --- a/spybug/spybug.ino +++ b/spybug/spybug.ino @@ -40,6 +40,9 @@ //#define DEBUG_RECORDING //#define SERIAL_OUTPUT +//#define PIN_COMPONENT_SWITCH 2 /* Use a digital signal to switch on/off the microphone and SD card for less power draw. */ +//#define COMPONENT_SWITCH_ON HIGH + #define SAMPLE_MODE_U8 //#define SAMPLE_MODE_S16 @@ -270,12 +273,24 @@ void setup() { #ifdef SERIAL_OUTPUT Serial.begin(9600); /* Set baud rate. */ setup_serial_in_out(); /* Add printf support. */ +#endif + // Component Switch Setup +#ifdef PIN_COMPONENT_SWITCH + pinMode(PIN_COMPONENT_SWITCH, OUTPUT); #endif // Delay Triggering #if defined(RECORDING_DELAY_IN_MINUTES) && RECORDING_DELAY_IN_MINUTES != 0 +#ifdef PIN_COMPONENT_SWITCH + digitalWrite(PIN_COMPONENT_SWITCH, !COMPONENT_SWITCH_ON); +#endif printf(F("Waiting %u minute%s before starting to record...\n"), RECORDING_DELAY_IN_MINUTES, RECORDING_DELAY_IN_MINUTES == 1 ? "" : "s"); Serial.flush(); low_power_sleep_minutes(RECORDING_DELAY_IN_MINUTES); /* Draws ~12.5mA instead of ~30mA when using delay(). */ +#endif + // Activate Components +#ifdef PIN_COMPONENT_SWITCH + digitalWrite(PIN_COMPONENT_SWITCH, COMPONENT_SWITCH_ON); + delay(500); /* Wait for components to initialize. */ #endif // Start Watchdog (wdt_enable() doesn't fully reset) start_watchdog_with_full_reset();