Need help with code, Is this right? What am i doing wrong?
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.
' {$STAMP BS2} ' {$PBASIC 2.5} ' plays sequences to LEDs on p0 to p7, ' pushbutton on p8 to move from pattern to pattern pntr VAR WORD idx VAR BYTE N VAR BYTE demo: DIRL = $FF ' make p0 to p7 outputs to LEDs pntr=wigwag ' choose a sequence GOSUB player ' play it DO : LOOP UNTIL IN8 pntr=wumpus ' next sequence GOSUB player DO : LOOP UNTIL IN8 GOTO demo ' or play more sequences! player: ' enter with pntr to the DATA sequence to play READ pntr, N ' each sequence starts with the number of states to be played FOR idx=1 TO N READ pntr+idx,OUTL PAUSE 1000 ' RCTIIME delay would go here IF IN8 THEN EXIT ' if user presses button, time to move on NEXT RETURN wigwag DATA 4, %00001111, %00000000, %11110000, %00000000 wumpus DATA 6,%10001000,%00010001,%01100110,%01000010,%00100100,%10011001As 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.