DO-WHILE loop --- Waiting for pressing of either of 2 buttons

Hi

I am using a DO-WHILE loop in my code to wait for either of 2 buttons to be pressed. To prompt the user to press either button, a blinking LED is placed beside each button.

Here is my code:

do // Wait until the Refresh or Exit button is pressed.
** {**
** digitalWrite(RefreshLED, HIGH); // Blink both LEDs to draw attention to**
** digitalWrite(ExitLED, LOW); // press either Refresh or Exit button.**
** delay(500);**

** RefreshVal = digitalRead(RefreshButton);**
** ExitVal = digitalRead(ExitButton);**

** digitalWrite(RefreshLED, LOW); // Blink both LEDs to draw attention to**
** digitalWrite(ExitLED, HIGH); // press either Refresh or Exit button.**
** delay(500);**

** }**
** while ((RefreshVal == LOW) && (ExitVal == LOW));**
** digitalWrite(RefreshLED, LOW); // Turn off both LEDs when either**
** digitalWrite(ExitLED, LOW); // Refresh or Exit button is pressed.**

I am testing my code on Proteus 8.0,
the LEDs would blink for a short time and
then exit the DO-WHILE loop and
switch off both LEDs; even none of the switch is pressed!

Is that a problem with Proteus or with my code?

Show the schematic.

More likely your wiring. From your description of the problem, your pins could be floating.
Read more here https://www.arduino.cc/en/Tutorial/DigitalReadSerial

With a 1 second delay in that do/while the response to the button presses is not going to be very snappy. You would be better off using millis() for timing which would allow you to test for button presses much more frequently.

Have a look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE

aarg:
Show the schematic.

Here you go…

Now please post your entire sketch using code tags as explained in the sticky posts at the top of the forum.

I see that you have connected switches to pin 0 and 1, they are reserved for serial communications.

aarg:
I see that you have connected switches to pin 0 and 1, they are reserved for serial communications.

I changed the pins to 10 and 11, it solved the problems.

Thanks all of you, especially UKHeliBob for directing me some useful topics.