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

PulseCounter

Sample using pulse counter
    This is an example using the PulseCounter.

    A pulse counter counts the number of rising or falling edges of a signal without involving a microcontroller. It can be used to count irregular pulses and send the count via wireless packet when the count reaches a certain number.

    Act Functions

    • Counts pulses connected to the child device’s DIO8 and sends wireless transmission after a certain time has elapsed or a certain count is detected.
    • The child device operates while sleeping.

    How to Use the Act

    Required TWELITE

    RoleExample
    ParentMONOSTICK BLUE or RED
    Run the act Parent_MONOSTICK.
    Child1. TWELITE DIP
    2. BLUE PAL or RED PAL + Environmental Sensor PAL AMBIENT SENSE PAL

    Explanation of the Act

    setup()

    // Pulse Counter setup
    PulseCounter.setup();

    Initializes the pulse counter.

    begin()

    void begin() {
    	// start the pulse counter capturing
    	PulseCounter.begin(
    		  100 // 100 count to wakeup
    		, PIN_INT_MODE::FALLING // falling edge
    		);
    
    	sleepNow();
    }

    Starts the pulse counter operation and performs the initial sleep. The first parameter of PulseCounter.begin() is the count number 100 to trigger the wakeup interrupt, and the second parameter specifies falling edge detection PIN_INT_MODE::FALLING.

    wakeup()

    void wakeup() {
    	Serial	<< mwx::crlf
    			<< "--- Pulse Counter:" << FOURCHARS << " wake up ---"
    			<< mwx::crlf;
    
    	if (!PulseCounter.available()) {
    		Serial << "..pulse counter does not reach the reference value." << mwx::crlf;
    		sleepNow();
    	}
    }

    Checks PulseCounter.available() on wakeup. If available is true, it means the count has reached or exceeded the specified count. If false, it goes back to sleep.

    If the count is above the specified value, the sending process and waiting for send completion are performed in loop().

    loop()

    uint16_t u16ct = PulseCounter.read();

    Reads the pulse count value. The counter is reset after reading.