Normally, I put SPRESENSE in a sleep state and try to get up with a tap switch (buttonPower).
In the sketch setup, there are the following steps, and if the button changes, you will reach a routine (read_button) that determines whether you want to click or press long.
attachInterrupt (buttonPower, read_button, CHANGE);
Read_Button is trying to create logic that changes the environment variable by clicking/pressing long, and that if you press long in the loop of the sketch, you sleep, and if you click, you wake up.
LowPower.coldSleep();
They will do cold sleep for now, but the reason for reboot is that buttonPower is pressed.I tried many things, such as trying Serial.flush() or attachInterrupt again, but I couldn't put them to sleep well.
LowPower.disableBootCause (buttonPower);
If you do something like that, it will be ruined.
Can someone give me some advice?
spresense
I don't know how to detect button clicks/push and press/release, but
Since the mode of attachInterrupt() is CHANGE
, is it possible to enter Cold Sleep by pressing long press and wake up after detecting the change when released?If the source code is attached, I may be able to give you more specific advice.
This is a simple implementation, but if the press time is more than 3 seconds, I think it will be possible to enter Cold Sleep and wait until Button is released before entering Cold Sleep.For your information.
#include<LowPower.h>
uint8_t buttonPower=PIN_D33;
unsigned long long pressTime = 0;
void read_button()
{
if(LOW==digitalRead(buttonPower)){
pressTime=millis();//pushed
} else{
pressTime = 0;// released
}
}
void setup()
{
Serial.begin (115200);
Serial.println("Power ON";
ledOn (LED 0);
LowPower.begin();
pinMode (buttonPower, INPUT_PULLUP);
attachInterrupt(buttonPower, read_button, CHANGE);
}
void loop()
{
unsigned long long currentTime;
unsigned long diffTime;
currentTime = millis();
if(LOW==digitalRead(buttonPower)){
diffTime = currentTime-pressTime;//pushed
} else{
diffTime = 0;// released
}
if((pressTime!=0)&(diffTime>3000)){
Serial.println("Power Off";
ledOff (LED 0);
while (LOW==digitalRead (buttonPower));
LowPower.coldSleep();
}
}
709 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
549 PHP ssh2_scp_send fails to send files as intended
537 Uncaught (inpromise) Error on Electron: An object could not be cloned
548 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.