'{$STAMP BS2} ' Flasher3.bs2 - a program to Flash 3 LEDs WITHOUT an FSM LED1 CON 0 ' LED 1 is on port 0 LED2 CON 1 ' LED 2 is on port 1 LED3 CON 5 ' LED 3 is on port 5 Control1 VAR BIT ' IF set, causes LED 1 to flash Control2 VAR BIT ' IF set, causes LED 2 to flash Control3 VAR BIT ' IF set, causes LED 3 to flash ' If the following errors are set, the operator needs to see the ' appropriate LED flash Error1 VAR BIT ' IF set, causes LED 1 to flash ' Error1 could be unit needs routine maintenance Error2 VAR BIT ' IF set, causes LED 2 to flash ' Error2 could be overtemp Error3 VAR BIT ' IF set, causes LED 3 to flash ' Error3 could be dangerous vibration ' While it is important to know about needing routine maintenance, ' it is much more important to be warned about overtemp and ' vibration. ' ----------------------------------------------------------- ' Initialization ' ----------------------------------------------------------- Control1 = 1 ' Make it flash Control2 = 1 ' Make it flash Control3 = 1 ' Make it flash Error1 = 1 ' Have that error Error2 = 1 ' Have that error Error3 = 1 ' Have that error ' ----------------------------------------------------------- ' Main Program ' ----------------------------------------------------------- main: GOSUB Behavior1 ' lowest priority behavior done first GOSUB Behavior2 ' highest priority behavior done last GOSUB LightLEDs ' Actually execute what was decided ' by behaviors wait4it: PAUSE 500 ' Wait for 1/2 second LOW LED1 ' turn them all off LOW LED2 LOW LED3 PAUSE 500 ' Wait for 1/2 second GOTO main ' Keep doing it ' ----------------------------------------------------------- ' Subroutines ' ----------------------------------------------------------- Behavior1: ' This is the lowest priority behavior Control1 = Error1 ' enable the LED if we have that error RETURN Behavior2: ' This is the highest priority behavior Control2 = Error2 ' enable the LED if we have that error Control3 = Error3 ' enable the LED if we have that error IF Error3 = 0 THEN done2 ' no conflict Control1 = 0 ' When Error3, we can't have LED1 on. ' We have a serious problem, Don't ' confuse operator with non-critical ' warnings - Note Behavior2 "subsumed" ' Behavior1 done2: RETURN LightLEDs: ' this is the subroutine that performs the action IF (Control1 = 0) THEN chk2 ' See if it should be on HIGH LED1 chk2: IF (Control2 = 0) THEN chk3 ' See if it should be on HIGH LED2 chk3: IF (Control3 = 0) THEN wait4it ' See if it should be on HIGH LED3 RETURN