need help with program "modes" for leds
aaz707
Posts: 8
I am wanting to use the bs2 to make 15 leds (5 red, 5 blue, and 5 green) light up in different modes using a push button on pin 0 to cycle through the modes. so far i have been using DO-LOOP UNTIL IN0 = 1 and it has been working great but when i get to certain codes where I want the leds to strobe through the seven colors i hit the push button they start to strobe it takes the bs2 about 4 secs with the pauses im using and when i hit the push button it wont go to the next DO-LOOP UNTIL code unless i hit it exactly after the bs2 goes through all the code i have for the strobe. it also does the same thing for the code i have written to fade the led on and off with a pulsout and a FOR-NEXT, it wont let me go to the next DO-LOOP UNTIL until the for next is done counting. my question is, is there any way to write the program so when in0 is pressed no matter where its at in its current mode or where the counter is it will stop and go to the next DO-LOOP UNTIL.
here is some of the code I have so you can see what I mean
' {$STAMP BS2}
' {$PBASIC 2.5}
counterup VAR Word
counterdown VAR Word
DIRS = %1111111111111110 'pins 15-11 are red leds, pins 10-6 are green, and pins 5-1 are blue
OUTS = %0000000000000000
DO
DO
OUTS =%0000000000000000 'begining mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%1111100000000000 'red mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'green mode
OUTS =%0000011111000000
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%0000000000111110 'blue mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%1111111111000000 'yellow mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'purple mode
OUTS =%1111100000111110
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%0000011111111110 'teal mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%1111111111111110 'white mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'all seven colors mode
OUTS =%1111100000000000
PAUSE 3000
OUTS =%0000011111000000
PAUSE 3000
OUTS =%0000000000111110
PAUSE 3000
OUTS =%0000011111111110
PAUSE 3000
OUTS =%1111100000111110
PAUSE 3000
OUTS =%1111111111000000
PAUSE 3000
OUTS =%1111111111111110
PAUSE 3000
LOOP UNTIL IN0=1
PAUSE 100
DO 'strobe mode
OUTS =%1111100000000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111100000000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000000000111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000000000111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111111110
PAUSE 50
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'red led starts to fade
OUTS =%0000000000000000
FOR counterup = 1 TO 3000 STEP 10
PAUSE 4
PULSOUT 15,counterup
PAUSE 4
NEXT
FOR counterdown = 3000 TO 1 STEP 10
PAUSE 4
PULSOUT 15,counterdown
PAUSE 4
NEXT
LOOP UNTIL IN0 = 1
PAUSE 100
LOOP
here is some of the code I have so you can see what I mean
' {$STAMP BS2}
' {$PBASIC 2.5}
counterup VAR Word
counterdown VAR Word
DIRS = %1111111111111110 'pins 15-11 are red leds, pins 10-6 are green, and pins 5-1 are blue
OUTS = %0000000000000000
DO
DO
OUTS =%0000000000000000 'begining mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%1111100000000000 'red mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'green mode
OUTS =%0000011111000000
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%0000000000111110 'blue mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%1111111111000000 'yellow mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'purple mode
OUTS =%1111100000111110
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%0000011111111110 'teal mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO
OUTS =%1111111111111110 'white mode
PAUSE 100
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'all seven colors mode
OUTS =%1111100000000000
PAUSE 3000
OUTS =%0000011111000000
PAUSE 3000
OUTS =%0000000000111110
PAUSE 3000
OUTS =%0000011111111110
PAUSE 3000
OUTS =%1111100000111110
PAUSE 3000
OUTS =%1111111111000000
PAUSE 3000
OUTS =%1111111111111110
PAUSE 3000
LOOP UNTIL IN0=1
PAUSE 100
DO 'strobe mode
OUTS =%1111100000000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111100000000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000000000111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000000000111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111000000
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%0000011111111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111111110
PAUSE 50
OUTS =%0000000000000000
PAUSE 50
OUTS =%1111111111111110
PAUSE 50
LOOP UNTIL IN0 = 1
PAUSE 100
DO 'red led starts to fade
OUTS =%0000000000000000
FOR counterup = 1 TO 3000 STEP 10
PAUSE 4
PULSOUT 15,counterup
PAUSE 4
NEXT
FOR counterdown = 3000 TO 1 STEP 10
PAUSE 4
PULSOUT 15,counterdown
PAUSE 4
NEXT
LOOP UNTIL IN0 = 1
PAUSE 100
LOOP
Comments
You also have to split up the long PAUSEs so a PAUSE 3000 is actually a loop like
FOR i=1 to 30
PAUSE 100
IF IN0=1 THEN GOTO pause1Exit
next i
pause1Exit: IF IN0=1 THEN GOTO pause1Exit[/code]
Note that the last IF statement ensures that the pushbutton is released before the code continues.