Help - Simple program with a button changing the value of a variable

Hello,

I'd like to create the following program: each time I press a button, a variable takes the next value among these values: 3, 11, 19, 49, 68, 75, and then it goes back to 3 and so on...

I tried many options but I can't make it work...

Any idea?

Thank you.

Put the values in an array and use the count to access the value.

Weedpharma

What he ^ said. Plus make sure you debounce the button press to avoid skipping values.

Also make sure you look at the state change detection example, and increment the counter ONLY when the switch BECOMES pressed (not IS pressed).

PaulS:
Also make sure you look at the state change detection example, and increment the counter ONLY when the switch BECOMES pressed (not IS pressed).

That's pretty much what I meant, Paul, but worded it very poorly. :frowning:

OldSteve:
That's pretty much what I meant, Paul, but worded it very poorly. :frowning:

You need to do more to debounce the input than just detect the state change because, by definition, if/when the switch bounces it will produce several state changes.

That's pretty much what I meant, Paul, but worded it very poorly.

But debouncing is important to, even when using the state change detection philosophy.

UKHeliBob:
You need to do more to debounce the input than just detect the state change because, by definition, if/when the switch bounces it will produce several state changes.

When I said I worded it poorly, I meant that I should have used more words to describe the situation better - debounce the actual press and detect the state changes.
Depending on the program, a simple delay can even do the job, without further code. (And you get auto-repeat for free.)