Disable the cycle mode, and after touching the CoreS3, immediately turn off the power and restore the power after the off-time ends.
#include "M5Unified.h"
#include "Wire.h"
#include "m5_unit_timerpwr.hpp"
M5UnitTimerPWR timer_pwr;
void setup()
{
M5.begin();
Serial.begin(115200);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::lgfxJapanMinchoP_24);
while (!timer_pwr.begin(&Wire, TIMERPWR_ADDR, 2, 1, 400000U)) {
M5.Display.drawString("Unit TimerPWR init Fail!", M5.Display.width() / 2, M5.Display.height() / 2);
delay(1000);
};
M5.Display.clear();
M5.Display.drawString("Unit TimerPWR init OK", M5.Display.width() / 2, M5.Display.height() / 2 - 20);
M5.Display.drawString("Touch To Sleep 10S", M5.Display.width() / 2, M5.Display.height() / 2 + 20);
// do something before sleep...
// disable cycle sleep mode
timer_pwr.set_cycle_sleep(false);
}
void loop()
{
M5.update();
auto t = M5.Touch.getDetail();
if (t.wasClicked() || M5.BtnA.wasClicked()) {
M5.Display.clear();
M5.Display.drawString("Sleep 10S!", M5.Display.width() / 2, M5.Display.height() / 2);
delay(1000);
timer_pwr.set_power_on_time(0, 0, 0);
timer_pwr.set_power_off_time(0, 0, 10);
timer_pwr.set_sleep();
}
}
Enable the cycle mode, configure the on/off time, and once the cycle starts, it will begin counting. After the on-time runs out, it will immediately turn off the power and restore power after the off-time ends. The cycle will repeat until new configuration is written or the battery is fully drained.
#include "M5Unified.h"
#include "Wire.h"
#include "m5_unit_timerpwr.hpp"
M5UnitTimerPWR timer_pwr;
void setup()
{
M5.begin();
Serial.begin(115200);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::lgfxJapanMinchoP_24);
while (!timer_pwr.begin(&Wire, TIMERPWR_ADDR, 2, 1, 400000U)) {
M5.Display.drawString("Unit TimerPWR init Fail!", M5.Display.width() / 2, M5.Display.height() / 2);
delay(1000);
};
M5.Display.clear();
M5.Display.drawString("Unit TimerPWR init OK", M5.Display.width() / 2, M5.Display.height() / 2 - 20);
M5.Display.drawString("ON 10S / OFF 5S", M5.Display.width() / 2, M5.Display.height() / 2 + 20);
}
void loop()
{
M5.update();
auto t = M5.Touch.getDetail();
if (t.wasClicked() || M5.BtnA.wasClicked()) {
M5.Display.clear();
M5.Display.drawString("Start Cycle ON/OFF!", M5.Display.width() / 2, M5.Display.height() / 2);
delay(1000);
// enable cycle sleep mode
timer_pwr.set_cycle_sleep(false);
timer_pwr.set_power_on_time(0, 0, 10);
timer_pwr.set_power_off_time(0, 0, 20);
timer_pwr.save_flash();
timer_pwr.set_cycle_sleep(true);
}
if (t.wasHold() || M5.BtnA.wasHold()) {
// disable cycle sleep mode
timer_pwr.set_cycle_sleep(false);
M5.Display.clear();
M5.Display.drawString("Stop Cycle ON/OFF!", M5.Display.width() / 2, M5.Display.height() / 2);
delay(1000);
}
}
For CoreS3, press and hold the reset button (for about 2 seconds) until the internal green LED lights up, and then release it. This indicates the device is in download mode and ready for programming.
Use the Unit TimerPWR to provide periodic wake-up for the CoreS3. (Note: The effect can be achieved by disconnecting the CoreS3 base battery power connection).
Touch the CoreS3 screen to control the single sleep-wake operation.
Entering sleep mode.