목차

IgetCount()

IgetCount()는 지정한 카운터의 현재값을 반환합니다.

IgetCount 명령어 동작 흐름

int32_t IgetCount(uint8_t counter_id)

명령어

명령어 인수 반환값 동작
IgetCount(counter_id) uint8_t counter_id — 카운터 번호. uint8_t 범위이므로 0 ~ 255 사용 가능 int32_t 지정한 카운터의 현재값을 반환합니다.

예제

MPINO-8A4R(T)-S의 P0·P1 입력을 사용하는 예제입니다.

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);  // 입력의 상승 횟수를 세고 설정값에 도달하면 true를 반환합니다.
 
  const int32_t current = IgetCount(COUNTER_ID);  // 지정한 카운터의 현재값을 반환합니다.
  static int32_t previous = -1;
  if (current != previous) {
    previous = current;
    Serial.print(F("count="));
    Serial.println(current);
  }
}

주의사항

같은 카테고리의 내장 명령어

← 내장 명령어 리스트