Table of Contents

IdigitalRead()

IdigitalRead() reads the input several times consecutively and updates the state only when all values match. If HIGH and LOW are mixed, it retains the previous stable state.

IdigitalRead command operation flow

bool IdigitalRead(uint8_t pin, uint8_t samples)

Commands

Command Arguments Return Value Operation
IdigitalRead(pin, samples) uint8_t pin — Digital input pin number
uint8_t samples — Consecutive read count. Values of 1 or less read once; supports up to 255 reads
bool Reads the input several times consecutively and updates the state only when all values match. If HIGH and LOW are mixed, it retains the previous stable state.

How It Works

Example

This example reads MPAINO-8A8R(T) input 0 and displays the result on output 64.

void setup() {}
 
void loop() {
  bool input = IdigitalRead(0, 5);  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state.
 
  if (input) {
    digitalWrite(64, HIGH);
  } else {
    digitalWrite(64, LOW);
  }
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List