Go Down

Topic: Help with Arduino program (Read 1 time) previous topic - next topic

tuxduino

PaulS's code sample is good, although you should put his code in a function and call it once every few tens of ms, otherwise the mode change will be so fast you'll end up with a random selection.

Also, see "blink without delay" example to get rid of those nasty delay()s :P

PaulS

Quote
otherwise the mode change will be so fast you'll end up with a random selection.

In my code, the mode changes only once each time the switch is pressed. The speed at which it changes depends entirely on how fast the user presses and releases the switch.

tuxduino


Quote
otherwise the mode change will be so fast you'll end up with a random selection.

In my code, the mode changes only once each time the switch is pressed. The speed at which it changes depends entirely on how fast the user presses and releases the switch.


Ouch! Your're right. There's the debouncing problem though... Without delay (or timed polling) the digitalRead() call will detect state changes while the button switch bounces.

PaulS

Quote
There's the debouncing problem though...

True, but what OP wanted to do in each mode was going to take time, so debouncing would be handled by that.

tuxduino


Quote
There's the debouncing problem though...

True, but what OP wanted to do in each mode was going to take time, so debouncing would be handled by that.


Yes, but I was thinking about having the led pattern implemented with a state machine, rather than using delay().

Anyway your code was a very good starting point. Let's see what the OP thinks about it.

Go Up