# PulseCounter

[pulse counter](/latest_en/api-reference/predefined_objs/pulsecounter.md) 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

| Role        | Example                                                                                                                                                                                                                                                                                                                                    |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Parent Node | <p><a href="https://mono-wireless.com/jp/products/MoNoStick/">MONOSTICK BLUE or RED</a><br>ACT <a href="/pages/-Lvtl_DIu32MgNvsUahk">Parent\_MONOSTICK</a> in action.。</p>                                                                                                                                                                 |
| Child Node  | <p>1. <a href="https://mono-wireless.com/jp/products/TWE-Lite-DIP/index.html">TWELITE DIP</a><br>2. <a href="https://mono-wireless.com/jp/products/twelite-pal/BnR/index.html">BLUE PAL or RED PAL</a> +<a href=" https://mono-wireless.com/jp/products/twelite-pal/sense/amb-pal.html">environmental sensor pal AMBIENT SENSE PAL</a></p> |

## Explanation of ACT

### setup()

```cpp
// Pulse Counter setup
PulseCounter.setup();
```

Initializes the pulse counter.

### begin()

```cpp
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()

```cpp
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()

```cpp
uint16_t u16ct = PulseCounter.read();
```

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwx.twelite.info/latest_en/act_samples/pulsecounter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
