Help. A better way to Fire my LEDs
I've been working through the Stamp works book and I'm having a bit of trouble understanding how take control of my program.· I'm hoping for some help?
Below I have some code to fire 12 LEDs that are setup ready to go 1 through 12.· I'm looking to define my delays·for after my button push·and run through everything in the body of the code prior ro firing anything.· When I use Pause, of course its going through the code consecutively, so I'll never be able to fire LED 1 & 12 at the same time·500ms after the button push.
Can anyone hook me up with an example of how to this better accompanied by an explanation? [noparse];)[/noparse]
Below I have some code to fire 12 LEDs that are setup ready to go 1 through 12.· I'm looking to define my delays·for after my button push·and run through everything in the body of the code prior ro firing anything.· When I use Pause, of course its going through the code consecutively, so I'll never be able to fire LED 1 & 12 at the same time·500ms after the button push.
Can anyone hook me up with an example of how to this better accompanied by an explanation? [noparse];)[/noparse]
' {$STAMP BS2}
' {$PBASIC 2.5}
' -----[noparse][[/noparse] Program Description ]-----
'
' -----[noparse][[/noparse] I/O Definitions ]-----
'
' Defines the PIN associated with a LED or Button
'
theBtn PIN 0 ' Trigger Button for LEDs
LED1 PIN 1 ' LED 1 on Pin 1
LED2 PIN 2 ' LED 2 on Pin 2
LED3 PIN 3 ' LED 3 on Pin 3
LED4 PIN 4 ' LED 4 on Pin 4
LED5 PIN 5 ' LED 5 on Pin 5
LED6 PIN 6 ' LED 6 on Pin 6
LED7 PIN 7 ' LED 7 on Pin 7
LED8 PIN 8 ' LED 8 on Pin 8
LED9 PIN 9 ' LED 9 on Pin 9
LED10 PIN 10 ' LED 10 on Pin 10
LED11 PIN 11 ' LED 11 on Pin 11
LED12 PIN 12 ' LED 12 on Pin 12
' -----[noparse][[/noparse] Constants ]-----
'
' The LED # Delay Time delays the firing of the LED
'
LED1DelayTm CON 500 ' delay time for LED1
LED2DelayTm CON 400 ' delay time for LED2
LED3DelayTm CON 300 ' delay time for LED3
LED4DelayTm CON 100 ' delay time for LED4
LED5DelayTm CON 100 ' delay time for LED5
LED6DelayTm CON 300 ' delay time for LED6
LED7DelayTm CON 400 ' delay time for LED7
LED8DelayTm CON 500 ' delay time for LED8
LED9DelayTm CON 2000 ' delay time for LED9
LED10DelayTm CON 5000 ' delay time for LED10
LED11DelayTm CON 5000 ' delay time for LED11
LED12DelayTm CON 100 ' delay time for LED12
' -----[noparse][[/noparse] Variables ]-----
'
' Assign Variable to button
'
theBtnWrk VAR Byte ' button type variable
' -----[noparse][[/noparse] Program Code ]-----
'
' basic Stamp manual p.139 - Change the value (200) in BUTTON to effect the delay
' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat;
' 255 = no auto-repeat (only one action per button press)
'
' The BUTTON instruction will cause the program to branch to
' No_Press unless P0 = 0
'
' The body of the program is simply triggering the LED with a delay
' LOW ensures the OUTPUT of the PIN is set TO 0 off
' PAUSE is set under constants and is a way of offsetting the LED response
' HIGH simply fires the LED 1
' LOW sets the LED back to o off
'
Main:
PAUSE 5
BUTTON theBtn, 0, 200, 20, theBtnWrk, 0, No_Press
DEBUG " ButtonPush "
'''' LED 1 Control
LOW LED1 ' ensure LED is off
PAUSE LED1DelayTm ' Delay LED based on constant
HIGH LED1 ' Fire LED
DEBUG " LED1 " ' Send feedback that LED fired
LOW LED1 ' ensure LED is off
'''' LED 2 Control
LOW LED2
PAUSE LED2DelayTm
HIGH LED2
DEBUG " LED2 "
LOW LED2
'''' LED 3 Control
LOW LED3
PAUSE LED3DelayTm
HIGH LED3
DEBUG " LED3 "
LOW LED3
'''' LED 4 Control
LOW LED4
PAUSE LED4DelayTm
HIGH LED4
DEBUG " LED4 "
LOW LED4
'''' LED 5 Control
LOW LED5
PAUSE LED5DelayTm
HIGH LED5
DEBUG " LED5 "
LOW LED5
'''' LED 6 Control
LOW LED6
PAUSE LED6DelayTm
HIGH LED6
DEBUG " LED6 "
LOW LED6
'''' LED 7 Control
LOW LED7
PAUSE LED7DelayTm
HIGH LED7
DEBUG " LED7 "
LOW LED7
'''' LED 8 Control
LOW LED8
PAUSE LED4DelayTm
HIGH LED8
DEBUG " LED8 "
LOW LED8
'''' LED 9 Control
LOW LED9
PAUSE LED9DelayTm
HIGH LED9
DEBUG " LED9 "
LOW LED9
'''' LED 10 Control
LOW LED10
PAUSE LED10DelayTm
HIGH LED10
DEBUG " LED10 "
LOW LED10
'''' LED 11 Control
LOW LED11
PAUSE LED11DelayTm
HIGH LED11
DEBUG " LED11 "
LOW LED11
'''' LED 12 control
LOW LED12
PAUSE LED12DelayTm
HIGH LED12
DEBUG " LED12 "
LOW LED12
GOTO Main
No_Press:
GOTO Main

Comments
The pins P0 through P15 can be controlled simultaneously or independently using these instructions.
Jeff T.