search
[last updated: 2022-02-28]
go to: ...
-----
void setup () {
Serial.begin .. why??
pinMode (13, OUTPUT); // onboard LED to indicate sleep mode
pinMode (interruptPin, INPUT_PULLUP);
digitalWrite (13, HIGH); // awake at start, will be turned off when asleep
// this is first line that will be executed when it wakes up
digitalWrite(13, HIGH); // turn on "awake" led
There is a method to re-start the USB, but it only works if the USB has been properly stopped - and the method that is supposed to do that is empty.
This is a little sketch that works on my Leonardo:
#include
void setup() {
}
void loop() {
USBCON = 0;
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
USBDevice.attach();
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
delay(10000);
digitalWrite(13, LOW);
}
-----
It disables the USB (USBCON = 0;), sleeps for 8 seconds, then starts the USB up again from scratch (USBDevice.attach();). 10 seconds later it sleeps again.
---------------------------------------------------------------
.
.
.
eof