This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

attachIntDio()

Function to register a DIO interrupt handler
    Registers a DIO interrupt handler.
    void attachIntDio(uint8_t u8pin, E_PIN_INT_MODE mode)

    For a pin configured as input beforehand, the first parameter is the pin number for which you want to enable the interrupt, and the second parameter specifies the interrupt direction (rising edge, falling edge).

    Example

    Sets up an interrupt that triggers when the DIO5 pin changes from HIGH to LOW.

    void setup() {
      the_twelite.app.use<myAppClass>();
    
      pinMode(PIN_DIGITAL::DIO5, PIN_MODE::INPUT_PULLUP);
      attachIntDio(PIN_DIGITAL::DIO5, PIN_INT_MODE::FALLING);
    }
    
    void loop() {
      ;
    }

    myAppClass.hpp

    class myAppClass: public mwx::BrdPal, MWX_APPDEFS_CRTP(myAppClasslMot)
    {
    
    };

    Basic definition of the behavior myAppClass. Details are omitted.

    myAppClass.cpp

    /*****************************************************************/
    // MUST DEFINE CLASS NAME HERE
    ##define __MWX_APP_CLASS_NAME myAppClass
    ##include "_mwx_cbs_cpphead.hpp"
    /*****************************************************************/
    
    MWX_DIO_INT(PIN_DIGITAL::DIO5, uint32_t arg, uint8_t& handled) {
      static uint8_t ct;
      digitalWrite(PIN_DIGITAL::DIO12, (++ct & 1) ? HIGH : LOW);
    	handled = false; // if true, no further event.
    }
    
    MWX_DIO_EVENT(PIN_DIGITAL::DIO5, uint32_t arg) {
      Serial << '*';
    }
    
    /*****************************************************************/
    // common procedure (DO NOT REMOVE)
    ##include "_mwx_cbs_cpptail.cpp"
    // MUST UNDEF CLASS NAME HERE
    ##undef __MWX_APP_CLASS_NAME
    } // mwx
    /*****************************************************************/

    Interrupt handler description for the behavior myAppClass. When an interrupt occurs on DIO5, it toggles the output setting of DIO12, and after the interrupt handler finishes, an event occurs that prints * to the serial port Serial.