Table of Contents

Ictu()

Ictu() counts input rising edges and returns true when the preset value is reached.

Ictu command operation flow

bool Ictu(uint8_t counter_id, bool CU, bool RESET, int32_t PV)

Commands

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 task
bool CU — Count input. Increments by 1 when it changes from LOW to HIGH
bool RESET — When true, reset the current count to 0
int32_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.

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.

Example

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;
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List