PulseCounter
pulse counter is an example of an ACT.
The pulse counter counts the number of rising or falling pulses of a signal without intervening microcontroller. It can be used to count irregular pulses and send wireless packets when the count reaches a certain number of times.
Function of ACT
Counts the pulses connected to DIO8 on the Child Node side and transmits them wirelessly after a certain period of time or when a certain number of counts are detected.
The Child Node side operates while sleeping.
How to use ACT
Required TWELITE
Parent Node
MONOSTICK BLUE or RED ACT Parent_MONOSTICK in action.。
Child Node
Explanation of 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 first sleep. The first parameter of PulseCounter.begin()
is the count number 100
to generate a wake-up interrupt, and the second is the falling 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()
when waking up. available, that is, true
, indicates that the count is greater than or equal to the specified count. If it is false
, it resleeps.
If the count is more than the specified number, loop()
processes the transmission and waits for the completion of the transmission.
loop()
uint16_t u16ct = PulseCounter.read();
Reads the pulse count value. The counter is reset after the readout.
最終更新