Code:
void loop() {
if (!sleepMode) {
DW1000Ranging.loop();
}
if (Serial.available()) {
int state = Serial.parseInt();
if (state == 1) {
sleepMode = false;
DW1000.spiWakeup();
Serial.println("ON");
//ESP.restart();
//DW1000.reset();
//DW1000.softReset();
}
if (state == 2) {
sleepMode = true;
DW1000.deepSleep();
Serial.println("OFF");
}
}
}
I think something else is needed to sleep or wake up, there is something we are missing. Look at the code sequence:
1st test sleepMode false
- Start the DW1000Ranging.loop();
- I press 2 to turn it off and it goes to sleep.
- If I press 2 nothing happens, in that case it is recorded that it was disconnected from the device before. I press 2 again and nothing happens.
2nd test sleepMode true:
- By default DW1000Ranging.loop(); does not start
- I press 1 and it does start.
- I press 2 to put him to sleep and he does sleep.
- I press 1 to wake it up again and nothing happens.
It tells me that the error is when I press 2. Because at first it did work.
3nd test without DW1000.deepSleep();:
If I remove DW1000.deepSleep(); it works. That is, it turns the loop on and off. My question is: is it actually sleeping or not? Does it still consume 160mAh?
void loop() {
if (!sleepMode) {
DW1000Ranging.loop();
}
if (Serial.available()) {
int state = Serial.parseInt();
if (state == 1) {
sleepMode = false;
Serial.println("ON");
}
if (state == 2) {
sleepMode = true;
Serial.println("OFF");
}
}
}