LED Flasher

Duane DegnDuane Degn Posts: 10,002
edited January 2012 in Propeller 1 Vote Up0Vote Down
Here's a little program for flashing LEDs.

I'm pretty sure there has got to be a bunch of programs like this already on the forum.

Here's my interpretation of a program to flash multiple LEDs at multiple rates.

This object allows any (and all) Propeller pins to be used to flash LEDs.

The object uses one cog to flash the LEDs.

After the object has been started with a call to the Start method, a LED can be flashed by calling the method "AddLed".

Here's the documentation on the "AddLed" method.
PUB AddLed(pin, onMs_, offMs_, count_)
'' onMs_ is the time the LED is to be on each flash.
'' onMs_ is limited to 26,843ms (over 26 seconds).
'' offMs_ is the time LED will be off between flashes.
'' offMs_ has the same limit as onMs_.
'' count_ is the number of times to flash the LED.
'' If count_ is set to zero then the LED will continue
'' to flash indefinitely.
'' The Start method must be called prior to calling this
'' method.
'' This method returns the active state
'' of the pin prior to calling this method or a -1 if the
'' pin number was out of range.

Each LED can have different values for each of the arguments. All 32 pins can be used to flash the LEDs.

As an example, if you wanted to flash a LED on pin 8, ten times, at 2Hz, you'd call AddLed with these arguments.
Led.AddLed(8, 250, 250, 10)

This will turn the LED on for 250ms and off for 250ms giving it a period of 500ms (2Hz). It wouldn't be hard to add a method to change frequency to on and off times. For example, the firmware for Eddie uses a frequency parameter in units of 0.1Hz. To change from units of tenths of a Hertz to milliseconds on and off use: (milliseconds on or off) = 5000 / (frequency in tenths of a Hertz). So 10Hz would be 5000/100 = 50ms on and 50ms off.

The attached demo takes input from a serial terminal to flash the LEDs on the QuickStart board. When a number 0 through 7 is pressed on the keyboard, a LED on the QuickStart board will flash 20 times at 1Hz.

Edit(3/11/15): Warning, the code attached is an old version. There are likely better options available.
I plan to upload this program or an improved version to my GitHub account
If there isn't code similar to what is attached here on my on GitHub, send me a message and I'll make and check for any improved versions of the code.

Additional note. This object has a severe bug. I encourage anyone interested to look for an updated version in my GitHub account.
Sign In or Register to comment.