#include #include class Interrupt { public: void ICACHE_RAM_ATTR isr_iram() { schedule_function([]() { Serial.println("isr_iram"); }); } void ICACHE_FLASH_ATTR isr_flash() { schedule_function([]() { Serial.println("isr_flash"); }); } static void ICACHE_RAM_ATTR isr_static(void* self) { if (self) static_cast(self)->isr_flash(); } }; Interrupt intr; bool d6State = false; void ICACHE_RAM_ATTR isr_single_iram() { intr.isr_iram(); } void ICACHE_RAM_ATTR isr_single_flash() { intr.isr_flash(); } void ICACHE_RAM_ATTR isr_single_with_functional() { auto fn = [](Interrupt& self) { self.isr_flash(); }; fn(intr); } void setup() { Serial.begin(9600); delay(1000); pinMode(D5, INPUT); pinMode(D6, OUTPUT); attachInterrupt(D5, isr_single_flash, CHANGE); // hides bad use of ICACHE_FLASH_ATTR function //attachInterrupt(D5, isr_single_with_functional, CHANGE); // hides bad use of lambda and ICACHE_FLASH_ATTR function //attachInterrupt(D5, []() { isr_single_iram(); }, CHANGE); // Doesn't compile if include FunctionalInterrupt.h, otherwise: ISR not in IRAM! //attachInterrupt(D5, []() { intr.isr_iram(); }, CHANGE); // Doesn't compile if include FunctionalInterrupt.h, otherwise: ISR not in IRAM! //std::function fn = isr_single_flash; //attachInterrupt(D5, fn, CHANGE); // hides bad use of std::function wrapping ICACHE_FLASH_ATTR function //detachInterrupt(D5); // uncomment for testing #6049 schedule_function([]() { Serial.println("Hello"); }); } // Add the main program code into the continuous loop() function void loop() { digitalWrite(D6, d6State); d6State ^= true; }