Pages

Monday, October 28, 2013

Arduino Example using two simple user-defined functions

The sketch below is used to alternately flash a pair of green and red LEDs whenever a potentiometer is turned pass a threshold position. The "trick" to this type of action is to only call the flash lights function once. The idea here is to flash the lights once - in order to flash them again, the user needs to "reset" the system by turning the potentiometer down pass a second lower threshold value and then again turning it up pas the upper threshold setting.

There a many different ways to accomplish this. The method shown below sets a "flag" whenever the pot value goes high. The flag is then reset when the pot goes low.

The flash lights() function is only called when the potValue goes above the threshold and the flag is set. Once the lights() function is called the flag is changed and needs to be reset before the function can be called again.

Here is a video of the circuit and the sketch is below...

VIDEO


SKETCH