Suppose you want to [sequentially] switch up to seven outputs... how would you do it? The program, below, shows you one method of handling this requirement. P7 is used as an active-high trigger input and will switch from one state to the next on the press-and-release of the button. If you want a machine-gun mode on the outputs you can remove the Force_Release section.
' =========================================================================
'
' File...... Switcher.BS1
' Purpose... Uses button on P7 to sequence through outputs
' Author.... Jon Williams, EFX-TEK
' E-mail.... jwilliams@efx-tek
' Started...
' Updated... 19 JUN 2007
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Trigger = PIN7 ' SETUP = DN
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1
SYMBOL IsOff = 0
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2 ' debounce timer
SYMBOL pointer = B3 ' active pin pointer
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000 ' clear everything
DIRS = %01111111 ' P0..P6 are outputs
pointer = 0
' -----[ Program Code ]----------------------------------------------------
Main:
PAUSE 10 ' scan delay
timer = timer + Trigger * Trigger ' increment or clear
IF timer < 10 THEN Main ' hold 0.1 s (10 ms x 10)
timer = 0
Force_Release:
IF Trigger = IsOn THEN Force_Release
IF pointer = 8 THEN Reset ' done?
PINS = %00000000 ' no; clear last pin
HIGH pointer ' activate current
pointer = pointer + 1 ' point to next
GOTO Main
' -----[ Subroutines ]-----------------------------------------------------
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -----[ EEPROM Data ]-----------------------------------------------------
Here's what the connections look like:
(http://www.efx-tek.com/files/prop-1_switcher.png)