Table of Contents

Ibounce()

Ibounce() returns an input state only after it remains unchanged for the specified time. It returns only stable states, even with brief input fluctuations or mechanical switch chatter.

This function does not pause the program like delay(), so it can be called continuously in loop().

Ibounce input filter operation

Commands

bool Ibounce(uint8_t pin, uint32_t debounceTime)

Command Arguments Return Value Operation
Ibounce(pin, debounceTime) pin: Digital input pin or logical input number
debounceTime: State hold time (ms)
bool Returns the retained value once the input state remains unchanged for the specified time.

Example

This example filters MPAINO digital input 0 for 50 ms, sends the stable state to digital output 64, and logs only state changes to the Serial Monitor.

const uint8_t INPUT_CHANNEL = 0;
const uint8_t OUTPUT_CHANNEL = 64;
 
void setup() {
  Serial.begin(115200);
}
 
void loop() {
  const bool inputState = Ibounce(INPUT_CHANNEL, 50);  // Return the stable ON/OFF value after the input state remains unchanged for 50 ms.
  digitalWrite(OUTPUT_CHANNEL, inputState ? HIGH : LOW);
 
  static bool previousState = false;
  if (inputState != previousState) {
    previousState = inputState;
    Serial.println(inputState ? F("input ON") : F("input OFF"));
  }
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List