I am working on an Arduino sketch and I see a weird problem.
This is my code:
Code: Select all
pinMode(21, INPUT_PULLUP);
X = digitalRead(21);
Y = digitalRead(21);
X is being assigned 0.
Y is being assigned 1.
X & Y, should, in theory, be both 1.
If i change the code to:
Code: Select all
pinMode(21, INPUT_PULLUP);
delay(1);
X = digitalRead(21);
Y = digitalRead(21);
My question is, does anyone else see this? I have tried it on two boards with the same result. I have tried it on other pins, with the same result. It seems strange to have to insert a dummy read, or wait 1 millisecond before the pin state is what it should be.
Steven