Is there a way to loop through the code with a keypad?

I have the code working to where if the # 1 key is pressed on the keypad, then an LCD screen will display the distance from 2 ultrasonic sensors. I had it working without the keypad and the screen updated on 150 ms intervals, but now with the keypad the code does not loop. Is there a way to have the code loop on the LCD after the key is pressed?

The_Real_One.ino (2.74 KB)

        case '1':
          {
            loop;

Can you explain what you are trying to do here ?

I want the LCD screen to auto update the distance read by sensors. I put a loop in there to see if that would make the code update, but it did not do anything. So right now the LCD will only update if the key is pressed another time.

Maybe have a look at the demo Several Things at a Time

...R

amblerlt18:
I want the LCD screen to auto update the distance read by sensors. I put a loop in there to see if that would make the code update, but it did not do anything. So right now the LCD will only update if the key is pressed another time.

You can't invent your own syntax

I see what you are trying to do but there are fatal flaws with how you have gone about it.
The value of key will be that returned by the latest call to getKey(). It will return '1' whist that key is being held down. Once you release the key it will no longer return '1' so that case will not be executed.

You could arrange the code such that key is set to '1' if it is not set to anything else but I don't understand why the keypad code is there in the first place because the only other value that you test for is '*' which causes pos to be set to zero but you don't use the value in the program.