I put your code into sleep mode that works well.
Question is seems that the sleep mode just execute simple action? how about if I have buttons selection like below, never got good result, how?
//......................................................Rui_ESP32_Timer_Wake_Up_from_Deep_Sleep_gd
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 8 /* Time ESP32 will go to sleep (in seconds) */
RTC_DATA_ATTR int bootCount = 0;
//......................................................Rui_ESP32_Timer_Wake_Up_from_Deep_Sleep_gd
#define buttonSelectA 13
int buttonSelectAMarker = 0;
#define buttonSelectB 33
int buttonSelectBMarker = 0;
void a_setup();
void b_setup();
void c_setup();
void d_setup();
void (*setups[4])(void) = {
a_setup,
b_setup,
c_setup,
d_setup
};
void a_loop();
void b_loop();
void c_loop();
void d_loop();
void (*loops[4])(void) = {
a_loop,
b_loop,
c_loop,
d_loop
};
///char aaa, bbb, ccc, ddd;
int ta = 1, tb = 2, tc = 3, td = 4;
void setup() {
// put your setup code here, to run once:
SerialSetting();
for (int i = 0; i < 4; i++) {
(*setups[i])();
}
//......................................................Rui_ESP32_Timer_Wake_Up_from_Deep_Sleep_gd
for (int i = 0; i < 4; i++) {
(*loops[i])();
}
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
/*
First we configure the wake up source
We set our ESP32 to wake up every 5 seconds
*/
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
" Seconds");
/*
Now that we have setup a wake cause and if needed setup the
peripherals state in deep sleep, we can now start going to
deep sleep.
In the case that no wake up sources were provided but deep
sleep was started, it will sleep forever unless hardware
reset occurs.
*/
Serial.println("Going to sleep now");
delay(1000);
Serial.flush();
esp_deep_sleep_start();
Serial.println("This will never be printed");
//......................................................Rui_ESP32_Timer_Wake_Up_from_Deep_Sleep_gd
}
void loop() {
// put your main code here, to run repeatedly:
//executeAPP();
// for (int i = 0; i < 4; i++) {
// (*loops[i])();
// }
// delay(1000);
}
void executeAPP() {
for (int i = 0; i < 4; i++) {
(*setups[i])();
(*loops[i])();
}
}
/*
void SerialSetting()
{
Serial.begin(115200);
while (!Serial && millis() < 5000);
Serial.print("File : ");
Serial.println(__FILE__);
const char compile_date[] = __DATE__ " " __TIME__;
Serial.print("Compile timestamp: ");
Serial.println(compile_date);
} */
void a_setup() {
ta = 11;
}
void a_loop() {
if (!digitalRead(buttonSelectA)) {
buttonSelectAMarker = 1;
}
if (buttonSelectAMarker == 1) {
ta += 1;
Serial.print("aaa = ");
Serial.println(ta);
buttonSelectBMarker = 0;
}
if (!digitalRead(buttonSelectB)) {
buttonSelectBMarker = 1;
}
if (buttonSelectBMarker == 1) {
ta += 9;
Serial.print("aaa = ");
Serial.println(ta);
buttonSelectBMarker = 0;
}
}
/*
void a_loop() {
Serial.print("aaa = ");
Serial.println(ta);
} */
void b_setup() {
tb = 22;
}
void b_loop() {
Serial.print("bbb = ");
Serial.println(tb);
}
void c_setup() {
tc = 33;
}
void c_loop() {
Serial.print("ccc = ");
Serial.println(tc);
}
void SerialSetting()
{
Serial.begin(115200);
// while (!Serial) ; // Needed for Leonardo only
Serial.print("File : "), Serial.println(__FILE__);
const char compile_date[] = __DATE__ " " __TIME__;
Serial.print("Compile timestamp: ");
Serial.println(compile_date);
}
//..............
void d_setup() {
td = 44;
}
void d_loop() {
Serial.print("ddd = ");
Serial.println(td);
}