using stamp program to fade leds question
aaz707
Posts: 8
I have a program written to fade red green and blue leds to create all the colors. my question is, is there any way to program a push button to pause the program on a color I like and have it stay that color until the push button is pressed again
here is the part of the program i would like the second push button to pause the program so i can have any color i want
mode4: IF IN0 = 1 THEN GOTO mode4
HIGH 15 'red led on
PAUSE 500
FOR i = 0 TO 255
IF IN0 = 1 THEN GOTO mode5 'push button one used to switch to different modes
PWM 9,i,20 'blue led starts to fade in
NEXT
HIGH 9 'blue staying high
PAUSE 1000
FOR i = 255 TO 0
IF IN0 = 1 THEN GOTO mode5
PWM 15,i,20 'red fading out
NEXT
PAUSE 1000
FOR i = 0 TO 255
IF IN0 = 1 THEN GOTO mode5
PWM 5,i,20 'green fading on
NEXT
HIGH 5 'green staying high
PAUSE 1000
FOR i =255 TO 0
IF IN0 = 1 THEN GOTO mode5
PWM 9,i,20 'blue fading out
NEXT
PAUSE 1000
FOR i = 0 TO 255
IF IN0 = 1 THEN GOTO mode5
PWM 15,i,20 'red fading in
NEXT
HIGH 15 'red staying high
PAUSE 1000
FOR i = 255 TO 0
IF IN0 = 1 THEN GOTO mode5
PWM 5,i,20 'green fading out
NEXT
PAUSE 500
i just dont know how or where to write it in at.
if any one can help it would help me out a lot. thanks
here is the part of the program i would like the second push button to pause the program so i can have any color i want
mode4: IF IN0 = 1 THEN GOTO mode4
HIGH 15 'red led on
PAUSE 500
FOR i = 0 TO 255
IF IN0 = 1 THEN GOTO mode5 'push button one used to switch to different modes
PWM 9,i,20 'blue led starts to fade in
NEXT
HIGH 9 'blue staying high
PAUSE 1000
FOR i = 255 TO 0
IF IN0 = 1 THEN GOTO mode5
PWM 15,i,20 'red fading out
NEXT
PAUSE 1000
FOR i = 0 TO 255
IF IN0 = 1 THEN GOTO mode5
PWM 5,i,20 'green fading on
NEXT
HIGH 5 'green staying high
PAUSE 1000
FOR i =255 TO 0
IF IN0 = 1 THEN GOTO mode5
PWM 9,i,20 'blue fading out
NEXT
PAUSE 1000
FOR i = 0 TO 255
IF IN0 = 1 THEN GOTO mode5
PWM 15,i,20 'red fading in
NEXT
HIGH 15 'red staying high
PAUSE 1000
FOR i = 255 TO 0
IF IN0 = 1 THEN GOTO mode5
PWM 5,i,20 'green fading out
NEXT
PAUSE 500
i just dont know how or where to write it in at.
if any one can help it would help me out a lot. thanks
Comments
It will change color until the SelectColor reaches 12.
Just replace the variable with your stop color pin and delete the SelectColor counter.
Will this do for starters?
Now you need to figure out how to keep selected color PWM running.
You will need to rebuild your program flow to output the PWM to each LED in sequece with correct/ selected
values.Maybe a subroutine like this:
.
...
Subroutine:
PWM pin_red, value_red, duration_red
PWM pin_blue,value_blue,duration_blue
...
RETURN
Addendum
Actually there is a easier way to do this:Put all varaibles in an array and DO/LOOP.
Colors CON 5
pin_ VAR Nib(Colors) ' pin array
value_ VAR Nib(Colors)' value array
duration_ VAR Byte(Colors) ' duration array
index VAR Nib
index = Colors ' number of colors
DO
PWM pin_(index),value_(index),duration_(index)
index = index -1
LOOP WHILE index
Stop at selected color - test snippet
i = 0
SelectColor = 0
DO
DEBUG ? i
DEBUG ? SelectColor
i = i + 1
PWM 9,i,20 'blue led starts to fade in
DEBUG ? i
SelectColor = SelectColor + 1
' STOP
LOOP WHILE I AND SelectColor < 12