//Standby sleep example for MoteinoM0 with external interrupt wakeup//expected current in standby sleep: 7.5uAconst int pin = 0; //pin to use as interrupt (can be any digital pin)//#define WITHRFM69 //comment this out if you don't have a radio installed on your MoteinoM0#ifdef WITHRFM69 #include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69 #define NODEID 2 //must be unique for each node on same network (range up to 254, 255 is used for broadcast) #define NETWORKID 100 //the same on all nodes that talk to each other (range up to 255) #define GATEWAYID 1 #define FREQUENCY RF69_915MHZ #define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W! RFM69 radio;#endif#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflashSPIFlash flash(SS_FLASHMEM, 0xEF30); //EF30 for 4mbit Windbond chip (W25X40CL)//replace Serial with SerialUSB#if defined (MOTEINO_M0) #if defined(SERIAL_PORT_USBVIRTUAL) #define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards #endif#endifvoid setup(){ Serial.begin(115200); delay(5000); pinMode(LED_BUILTIN, OUTPUT); pinMode(0, INPUT_PULLUP); //using internal pullup, makes pin 0 active low //Uses internal pullup eliminates the need for external resistor and makes interupt pin active low //If you need active high, then attach to HIGH and declare pin as INPUT without PULLUP, then use external resistor from GND to pin to keep it from floating attachInterrupt(pin, wakeupISR, LOW); //note: RISING and FALLING do not seem to work, use LOW or HIGH instead if (flash.initialize()) { Serial.println("flash.init() OK, sleeping it..."); flash.sleep(); } else Serial.println("flash.init() FAIL");#ifdef WITHRFM69 if (!radio.initialize(FREQUENCY,NODEID,NETWORKID)) Serial.println("radio.init() FAIL"); else Serial.println("radio.init() SUCCESS"); #ifdef IS_RFM69HW radio.setHighPower(); //uncomment only for RFM69HW! #endif radio.sleep();#endif for (byte count=0; count < 3; count++) { Serial.print("."); blink(500); } Serial.println("Entering standby sleep mode..."); delay(100);}void loop() { standbySleep(); //interrupt happened: WAKE UP and blink the LED! blink(50);}void blink(int ms) { digitalWrite(LED_BUILTIN, HIGH); delay(ms); digitalWrite(LED_BUILTIN, LOW); delay(ms);}byte toggle=true;void wakeupISR(void){ //nothing here, just a placeholder}void standbySleep() { //Disable USB (optional) USBDevice.detach(); //Standby - lowest power sleep mode SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; __DSB(); __WFI(); // Wait For Interrupt call //Sleep until woken by interrupt... //Enable USB USBDevice.attach();}