====== 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. {{:en-us_commands:reference:idigitalread.svg?900|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 ===== * Read the input ''samples'' times consecutively. * If all readings are ''HIGH'', update the stable state to ''HIGH''. * If all readings are ''LOW'', update the stable state to ''LOW''. * If ''HIGH'' and ''LOW'' are mixed, treat this as brief noise and retain the previous stable state. * If no previous stable state exists and the readings are mixed, return ''LOW''. ===== 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 ===== * If ''samples'' is ''1'' or less, the input is read only once. * A larger ''samples'' value increases the time taken by each call. ''3'' or ''5'' reads are recommended for typical input noise checks. * This command reads several times immediately. Use ''Ibounce()'' to remove ms-scale chatter such as mechanical switch bounce. ===== Built-in Commands in the Same Category ===== * [[:en-us_commands:ibounce|Ibounce() View detailed description]] * [[:en-us_commands:reference:ibounceon|IbounceOn() View detailed description]] * [[:en-us_commands:reference:ibounceoff|IbounceOff() View detailed description]] [[:en-us_commands:builtin|← Built-in Command List]]