Shop OBEX P1 Docs P2 Docs Learn Events
need help with program "modes" for leds — Parallax Forums

need help with program "modes" for leds

aaz707aaz707 Posts: 8
edited 2011-03-04 23:24 in BASIC Stamp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-04 22:11
    The problem is that, when the Stamp is doing the PAUSE, that's all it's doing. You have to put an IF IN0=1 THEN statement inside every loop that GOTOs a label that follows the loop.
    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.
  • aaz707aaz707 Posts: 8
    edited 2011-03-04 22:13
    will this also work for the fade mode i have with the pulsout command
  • aaz707aaz707 Posts: 8
    edited 2011-03-04 23:24
    disregard that last post just tested it out and everything is working great. thanks very much
Sign In or Register to comment.