Understanding Loops

Hi All,

New to this fun stuff as part of my college work and am a bit lost as I'm able to make longer strings of code but need to use loops for it.

Say I want text to display on an LCD with input from the Keypad. The text needs to become more noticeable over time if a key to stop it is not pressed. How do I set it up so that the person only need press the pad once and the text comes up and then flashes quicker without any more input?

I understand if and while loops but just cant get my head around the second part regarding the change without input. I believe I require a type of loop or code within the loop but am uncertain :confused:

Many thanks to anyone with suggestions.

cheezyfeet:
How do I set it up so that the person only need press the pad once and the text comes up and then flashes quicker without any more input?

I didn't understand this part,

But I'm pretty sure that a for loop (or a while loop, or a do while loop) is your answer.

You can look up "for loop" online and you'll find many tutorials.

I don't think for's or do's are an elegant solution; perhaps not even feasible.

First though, have you got the text blinking at all? (that is, forgetting for now the need to change the blink rate.)

If I were you, I'd get that working first; or have you?

I do that delay()-lessly on my lcd clock, where the hour:minute colon blinks as proof of life. I use blink without delay to toggle a flag (which if memory serves I called "colon"), and if the flag is true I print a colon, else I print a space. You could do the same except instead of a : or a space you have a bunch of characters "foobar" or spaces " ".

Then have a separate blink without delay running until the stop button is pressed, to change the interval of the text blink to say 0.9 of its previous value, every second say.

cheezyfeet:
I understand if and while loops

Well not really because if statements do NOT loop.

I don't completely understand what you're asking for but it sounds like for loops are probably going to be what you need. If you look at the top of the page Resources then Reference you'll find information on all the main commands including for, while and do while.

Steve

Hi,

thanks for the reply. Apologies if my question was a little confusing. Essentially what needs to happen is a key to be pressed, and text displayed informing the user of this; and perhaps a timer for time elapsed since the key press.

If another key is not pressed to clear the LCD after a given time, the text should begin to flash and become more noticeable until someone does notice and press the key to stop it.

Thanks for the help so far :slight_smile: I will give the suggestions a go.

Have a look at how the code is organized in Several Things at a Time

Note how each function runs very briefly and returns to loop() so the next one can be called. None of the functions tries to complete a task in one call. And there may be dozens of calls to a function before it is actually time for it to do anything.

This allows many different things to repeat just using loop().

...R

It also struck me on waking, that there are the LCD functions display() and noDisplay(). Provided you want to blink everything, not just a few characters, you could use those to hide and restore the lcd contents instead of my previous suggestion to cycle between displaying "sometext" or " ".

cheezyfeet:
I will give the suggestions a go.

I'm curious to know if you made / are making any headway?