SX/B random led sequencer
![Spragmatic](https://forums.parallax.com/uploads/userpics/667/nGXST42NL48C7.jpg)
Built·a circuit/project with 4 different colored led's and would like them to fade in and out randomly(at·random speeds if possible)·when one of my
switches·is tripped.· Not quite sure how to write the program.· I'm using the SX28 protoboard.··Thanks!!·
switches·is tripped.· Not quite sure how to write the program.· I'm using the SX28 protoboard.··Thanks!!·
Comments
What is your level of programming experience? Have you ever written any code, or is this your first project?
Your specifications already tell you what you need to do. Look at what you wrote:
1 - LEDs that fade in and out. Okay, you need to write some PWM code to control the brightness of the LEDs and let you fade them in and out.
2 - Randomly. You need a random number generator. Have you looked in the help file to see if SX/B has a random number generator? IF so, then use it. IF not, then search the forums for anyone who has written a random number generator.
3 - Do this when switches are tripped. That's a switch, a pullup resistor, and reading an input.
If you have no experience, then start with reading a switch. If you already know how to do that, then start on the random number issue followed by the PWM code. Both should be located on the forum in other postings.
Thanks,
PeterM
·
This program is a bit sophisticated and doesn't do random things, but it has all the framework components to ultimately get you where you want to go. What this program does do is cross-fade between LED channels. It starts with channel 1 on. When you press a button, if that channel's LED is off then there is a cross-fade between the channel presently on and the newly-selected channel. If you press multiple buttons then it resets directly to channel 1.
I whipped this up of a couple cups of Starbucks but have tested it on a PDB and know that it works. Have fun.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Paul
You can then check myButtons.0 instead of RA.0, etc.
http://i77.photobucket.com/player.swf?file=http://vid77.photobucket.com/albums/j72/spragmatic/MOV04895.flv"
The only special cases are no buttons or the fourth button -- after than you're simply moving the button status to an LED so this version is cleaner. You could actually reduce the final section to these two lines:
...but this is not as easy to understand.