Ictu() counts input rising edges and returns true when the preset value is reached.
bool Ictu(uint8_t counter_id, bool CU, bool RESET, int32_t PV)
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
Ictu(counter_id, CU, RESET, PV) | uint8_t counter_id — Counter identifier. Use the same number for the same counting taskbool CU — Count input. Increments by 1 when it changes from LOW to HIGHbool RESET — When true, reset the current count to 0int32_t PV — Target count. Returns true when the current count reaches or exceeds this value | bool | Count rising input edges and return true when the preset is reached. |
Beginner-friendly explanation
Ictu() does not measure how long a sensor stays on. It counts how many times the sensor changes from LOW to HIGH. For example, when one item passes the sensor, the input changes LOW → HIGH → LOW and the counter increases by 1. A sensor that remains HIGH is counted only once.
Read the call Ictu(counter_id, CU, RESET, PV) as follows.
counter_id: Identifies one counter among several counters. Always use the same number for the same counting task.CU: The count input. The current count increases by 1 when this input changes from LOW → HIGH.RESET: When true, clears the current count to 0. While RESET is active, CU is not counted even if it turns on.PV: The target count. The return value becomes true when the current count reaches or exceeds this value.
Call it continuously from loop() so it can detect input changes. The example below counts five items with input 0 and turns on the board's status LED when the target is reached. Pressing the reset button on input 1 starts the count again from zero.
const uint8_t COUNTER_ID = 0; const uint8_t ITEM_SENSOR_PIN = 0; const uint8_t RESET_BUTTON_PIN = 1; const uint8_t FULL_LAMP_PIN = LED_BUILTIN; const int32_t BOX_CAPACITY = 5; void setup() { Serial.begin(115200); } void loop() { const bool itemSensor = digitalRead(ITEM_SENSOR_PIN) == HIGH; const bool resetButton = digitalRead(RESET_BUTTON_PIN) == HIGH; const bool boxFull = Ictu(COUNTER_ID, itemSensor, resetButton, BOX_CAPACITY); // Count rising input edges and return true when the preset is reached. digitalWrite(FULL_LAMP_PIN, boxFull ? HIGH : LOW); static bool previousBoxFull = false; if (boxFull && !previousBoxFull) { Serial.println(F("5 items counted: box is full")); } previousBoxFull = boxFull; }
CU counts only LOW → HIGH transitions. If the signal remains HIGH, the count increases only once.RESET is true, the current count is cleared to 0 and CU is not counted during that call.PV to a target count of 1 or greater. If PV is 0 or less, the initial count of 0 is already considered to have reached the target.loop(). Use the product's high-speed counter for fast pulses.counter_id for each counting task. Do not share one number among CTU, CTD, and CTUD.IgetCount() with the same counter_id only when you need the current count.