Need help with code, Is this right? What am i doing wrong?
motosk8er2
Posts: 6
This is for a basic stamp 2 homework board. It is a project for homemade emergency lights, with different patterns and adjustable flash rate. pin 0 has the switch on it, changes modes when high, pins 1-8 are LED outs, they will go to transistors, which will turn on and off 8 3w LED drivers, which will go to the actual LED's. 4 red and 4 blue, and pin 15 is the input for the RCTIME POT circuit to control flash rate. I need a lot more flahs patterns if anyone has any ideas, and also im having problems. When i press the button it will not change pattern until the full pattern cycles, also same with the pot, when i adjust the speed it doesnt actually change until the pattern fully cycles. Here is the code i have so far.
' {$STAMP BS2} ' {$PBASIC 2.5} time VAR Word DO 'Wig wag HIGH 15 PAUSE 10 RCTIME 15, 1, time time = time */ 185 ' scale by 0.724 (x 256 for */). time = time + 50 ' Offset by 50. HIGH 1 HIGH 2 HIGH 3 HIGH 4 PAUSE time LOW 1 LOW 2 LOW 3 LOW 4 PAUSE time HIGH 5 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 5 LOW 6 LOW 7 LOW 8 PAUSE time LOOP UNTIL IN0=1 DO 'left3x-right3x HIGH 15 PAUSE 10 RCTIME 15, 1, time time = time */ 185 ' scale by 0.724 (x 256 for */). time = time + 50 ' Offset by 50. HIGH 1 HIGH 2 HIGH 3 HIGH 4 PAUSE time LOW 1 LOW 2 LOW 3 LOW 4 PAUSE time HIGH 1 HIGH 2 HIGH 3 HIGH 4 PAUSE time LOW 1 LOW 2 LOW 3 LOW 4 PAUSE time HIGH 1 HIGH 2 HIGH 3 HIGH 4 PAUSE time LOW 1 LOW 2 LOW 3 LOW 4 PAUSE time HIGH 5 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 5 LOW 6 LOW 7 LOW 8 PAUSE time HIGH 5 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 5 LOW 6 LOW 7 LOW 8 PAUSE time HIGH 5 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 5 LOW 6 LOW 7 LOW 8 PAUSE time LOOP UNTIL IN0=1 DO 'Inner, outer, flash HIGH 15 PAUSE 10 RCTIME 15, 1, time time = time */ 185 ' scale by 0.724 (x 256 for */). time = time + 50 ' Offset by 50. HIGH 1 HIGH 2 HIGH 3 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 1 LOW 2 LOW 3 LOW 6 LOW 7 LOW 8 PAUSE time HIGH 1 HIGH 2 HIGH 3 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 1 LOW 2 LOW 3 LOW 6 LOW 7 LOW 8 PAUSE time HIGH 1 HIGH 2 HIGH 3 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 1 LOW 2 LOW 3 LOW 6 LOW 7 LOW 8 PAUSE time HIGH 4 HIGH 5 PAUSE time LOW 4 LOW 5 PAUSE time HIGH 4 HIGH 5 PAUSE time LOW 4 LOW 5 PAUSE time HIGH 4 HIGH 5 PAUSE time LOW 4 LOW 5 PAUSE time LOOP UNTIL IN0=1 DO 'shifting HIGH 15 PAUSE 10 RCTIME 15, 1, time time = time */ 185 ' scale by 0.724 (x 256 for */). time = time + 50 ' Offset by 50. HIGH 1 HIGH 3 HIGH 5 HIGH 7 PAUSE time LOW 1 LOW 3 LOW 5 LOW 7 PAUSE time HIGH 2 HIGH 4 HIGH 6 HIGH 8 PAUSE time LOW 2 LOW 4 LOW 6 LOW 8 PAUSE time LOOP UNTIL IN0=1 DO '4-3-2-1 HIGH 15 PAUSE 10 RCTIME 15, 1, time time = time */ 185 ' scale by 0.724 (x 256 for */). time = time + 50 ' Offset by 50. HIGH 7 HIGH 8 PAUSE time LOW 7 LOW 8 PAUSE time HIGH 7 HIGH 8 PAUSE time LOW 7 LOW 8 PAUSE time HIGH 3 HIGH 4 PAUSE time LOW 3 LOW 4 PAUSE time HIGH 3 HIGH 4 PAUSE time LOW 3 LOW 4 PAUSE time HIGH 5 HIGH 6 PAUSE time LOW 5 LOW 6 PAUSE time HIGH 5 HIGH 6 PAUSE time LOW 5 LOW 6 PAUSE time HIGH 1 HIGH 2 PAUSE time LOW 1 LOW 2 PAUSE time HIGH 1 HIGH 2 PAUSE time LOW 1 LOW 2 LOOP UNTIL IN0=1 RETURN DO 'knightrider HIGH 15 PAUSE 10 RCTIME 15, 1, time time = time */ 185 ' scale by 0.724 (x 256 for */). time = time + 50 ' Offset by 50. HIGH 1 PAUSE time LOW 1 PAUSE time HIGH 2 PAUSE time LOW 2 PAUSE time HIGH 3 PAUSE time LOW 3 PAUSE time HIGH 4 PAUSE time LOW 4 PAUSE time HIGH 5 PAUSE time LOW 5 PAUSE time HIGH 6 PAUSE time LOW 6 PAUSE time HIGH 7 PAUSE time LOW 7 PAUSE time HIGH 8 PAUSE time LOW 8 PAUSE time HIGH 7 PAUSE time LOW 7 PAUSE time HIGH 6 PAUSE time LOW 6 PAUSE time HIGH 5 PAUSE time LOW 5 PAUSE time HIGH 4 PAUSE time LOW 4 PAUSE time HIGH 3 PAUSE time LOW 3 PAUSE time HIGH 2 PAUSE time LOW 2 PAUSE time LOOP UNTIL IN0=1 DO 'Flash all HIGH 15 PAUSE 10 RCTIME 15, 1, time time = time */ 185 ' scale by 0.724 (x 256 for */). time = time + 50 ' Offset by 50. HIGH 1 HIGH 2 HIGH 3 HIGH 4 HIGH 5 HIGH 6 HIGH 7 HIGH 8 PAUSE time LOW 1 LOW 2 LOW 3 LOW 4 LOW 5 LOW 6 LOW 7 LOW 8 PAUSE time LOOP UNTIL IN0=1
Comments
In your program, a lot of time is spent in PAUSE and when the processor is doing that, it can't do anything else.
There are numerous techniques to program around the issue. One is to use an external clock which the stamp can check to see how long its been doing a particular thing. When not checking the clock, it can do other things like watch the RCTIME loop or watch for another input.
A second method is to use a subroutine to be a short pause, maybe PAUSE 10 or PAUSE 15. Your main program will keep a count of how many times the subroutine is called and add up the time until its time to do something else. Also, every time the program comes back from the subroutine, you can check for a switch or RCTIME or whatever else must be updated while the rest of the program runs.
Keep at it.
Thanks a lot, that helps but i dont quite understand how the binary code works and how to write it to make each pattern work. Ive tried before but couldnt quite get it.
As I promised in your other thread, you won't find a more helpful group of people than in this forum. They're smart.
Some of us are just smart alecs.