Sample code needed for LED strobe pattern
I would like some help in designing some code for control of 4 LED's Red Green Blue and White. I would like multiple functions with the push of a button. and flash/strobe speed control with a pot. I would like to choose a single color for strobe/w speed control. A few different defined patterns. Like chase, alternate, fade.·All with only 1 button and 1 pot.·Thanks!!·
Comments
1) 4 LEDs separately controlled (each by one I/O pin). Since the LEDs are of different types, they will need different value resistors for the same level of intensity. How would you figure that part out? Hint: You need to know the voltage drop (forward voltage) of each type of LED and you need to use Ohm's Law.
2) You need a pushbutton switch on another I/O pin and a pullup or pulldown resistor. There are examples of both #1 and #2 in the "What's a Microcontroller?" tutorial and the "BASIC Stamp Syntax and Reference Manual", both downloadable from Parallax and included as part of the help files with the Stamp Editor.
3) You need a pot and code to read it. There are examples in the documentation on the RCTIME statement
4) Next steps are to try to light the LEDs in whatever patterns you want. The details depend on the patterns and how you've hooked everything up. You should end up with subroutines for each pattern that have speed (time delay) information in a variable so the pot can be used for a speed control.
5) Last step is to figure out how you want the push button to behave for selecting the pattern to show. There are many ways to do this. You propose something.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
if pushbutton = 1 then pushbutton = pushbutton + 1 goto police
This is not real code but the idea is valid.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
(By The Way)····· (·BTW )·the two Example can be found in the Basic Stamp Editor in the BS2 folder
You might also read ( What Is A Micro Controller ·)<<<<< ( Click Here )
If I where you I would read and do all of the Example in this book before I would start this project· here is why
First
It will help you understand how to write basic code
Second
It will help you Understand how to hook different thing to the Basic Stamp Pins
These are the most Inportant thing to underdtand in how to use a Basic Stamp
I hope this helps
' BUTTON.BS2 Ths can be found at on[url=http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf] [/url]( [url= http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf]PAGE 76 [/url])<<<<<(click here ) ._____220 ohm Resister >>>>>>>>> PIN 0 ! Vdd >>>>> ^^.^^ Switch ^^.^^ >>>> 10k ohm Resister >>>>>> Vss ' Connect an active-low circuit to pin P0 of the BS2. When you press the ' button, the DEBUG screen will display an asterisk (*). The program, as ' shown below, will print an asterisk at the first button press, then ' delay approximately one second (200 x 5 ms PAUSE) before auto-repeating ' at a rate of approximately 100 ms (5 x 20 ms). Feel free to modify the ' program to see the effects of your changes on the way BUTTON responds. ' {$STAMP BS2} ' {$PBASIC 2.5} Btn PIN 0 btnWrk VAR Byte Main: PAUSE 5 BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press DEBUG "*" No_Press: GOTO Main ' Try changing the Delay value (255) in BUTTON to see the effect of ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat; ' 255 = no auto-repeat (only one action per button press) ' ' The BUTTON instruction will cause the program to branch to ' No_Press unless P0 = 0
' HIGH_LOW.BS2 This can be found on ( [url= http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf]PAGE 48[/url] )<<<<<<<<<(click here) [color=#1f1a17][color=#1f1a17][color=#1f1a17]PIN 1 >>>> [color=#131516]470 ohm Resister [/color] >>>>>> LED Light >>>>>>>>>>> Vss [/color][/color][/color] ' This simple program sets I/O pin 1 high for 1/2 second and low for ' 1/2 second in an endless loop. Connect an LED to P1 for a simple ' blinker. ' {$STAMP BS2} Main: HIGH 1 PAUSE 500 LOW 1 PAUSE 500 GOTO Main END
Try this
' {$STAMP BS2} ' {$PBASIC 2.5} Btn PIN 0 LED_Red PIN 1 btnWrk VAR Byte Main: PAUSE 5 BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press DEBUG "Switch Pushed " HIGH LED_Red PAUSE 500 LOW LED_Red PAUSE 500 No_Press: GOTO Main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 1/23/2010 6:36:47 PM GMT