en-us_commands:ibounce
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().
Commands
bool Ibounce(uint8_t pin, uint32_t debounceTime)
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
Ibounce(pin, debounceTime) | pin: Digital input pin or logical input numberdebounceTime: 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
Ibounce()applies the same stable time in both the ON and OFF directions.- Keep calling it at short intervals in
loop(). Longer call intervals delay input-state updates. - Increasing
debounceTimeimproves noise rejection but also slows the response to valid inputs by the same amount. pinmust follow the input numbering of the product. MPINO uses product-specific Arduino digital input pin numbers; supported MPAINO products use logical input numbers starting at0.- An invalid pin number returns
false.
Built-in Commands in the Same Category
en-us_commands/ibounce.txt · Last modified: by 127.0.0.1
