Created
November 3, 2024 15:36
-
-
Save Aleksandr-ru/b67fd4ede4c909795ff0b7e52fa7ab51 to your computer and use it in GitHub Desktop.
Blink with power saving for Arduino and LGT8F328x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
* Classical Blink with power saving (c)2024 aleksandr.ru * | |
* This should work both in Arduino and LGT8F328x * | |
* @see https://github.com/dbuezas/lgt8fx/issues/155 * | |
*******************************************************************************/ | |
#include <PMU.h> | |
//#define DEBUG 115200 | |
void setup() | |
{ | |
pinMode(LED_BUILTIN, OUTPUT); | |
pinMode(A0, INPUT); | |
#ifdef DEBUG | |
Serial.begin(DEBUG); | |
Serial.println("Setup"); delay(100); | |
#endif | |
} | |
void loop() | |
{ | |
#ifdef DEBUG | |
Serial.println("Working"); delay(100); | |
#endif | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(2000); | |
digitalWrite(LED_BUILTIN, LOW); | |
#ifdef DEBUG | |
Serial.println("Go to sleep"); delay(100); | |
#endif | |
// Enter power down state for 2s. | |
bitClear(ADCSRA, ADEN); | |
PMU.sleep(PM_POFFS0, SLEEP_2S); | |
bitSet(ADCSRA, ADEN); | |
// Do something here | |
// Example: Read sensor, data logging, data transmission. | |
#ifdef DEBUG | |
Serial.print("A0 = "); Serial.println(analogRead(A0)); | |
delay(100); | |
#else | |
analogRead(A0); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment