User Tools

Site Tools


en-us_commands:reference:igetcount

This is an old revision of the document!


IgetCount()

IgetCount() returns the current value of the specified counter.

IgetCount command operation flow

int32_t IgetCount(uint8_t counter_id)

Commands

Command Arguments Return Value Operation
IgetCount(counter_id) uint8_t counter_id — Counter number. Supports 0 ~ 255, the uint8_t range int32_t Returns the current value of the specified counter.

Example

const uint8_t COUNTER_ID = 3;
const int32_t BATCH_SIZE = 100;
 
void setup() {
  Serial.begin(115200);
}
 
void loop() {
  const bool itemSensor = digitalRead(0) == HIGH;
  const bool resetButton = digitalRead(1) == HIGH;
  Ictu(COUNTER_ID, itemSensor, resetButton, BATCH_SIZE);  // Count rising input edges and return true when the preset is reached.
 
  const int32_t current = IgetCount(COUNTER_ID);  // Return the current value of the specified counter.
  static int32_t previous = -1;
  if (current != previous) {
    previous = current;
    Serial.print(F("count="));
    Serial.println(current);
  }
}

Precautions

  • The previous fixed 0~31 restriction has been removed. However, the argument type is uint8_t, so the maximum ID is 255.
  • If insufficient memory prevents allocation of counter state, counter commands return false or 0.
  • Once created, counter state is retained while the program runs.

Built-in Commands in the Same Category

en-us_commands/reference/igetcount.1788796399.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki