How to change main program to sub program?
Chris Georgiadis
Posts: 5
How to change main program to sub program (not subroutine) by pressing a pushbutton?
Is that possible?
Is that possible?
Comments
That's not possible... but other things are.
Please clarify.
x VAR byte
main:
DEBUG "Program 1", CR
x=x+1
IF x> 50 THEN x=0:GOTO main2
PAUSE 100
GOTO main
main2:
DEBUG "Program 2", CR
x=x+1
IF x> 50 THEN x=0:GOTO main
PAUSE 100
GOTO main2
Jeff T.
how to change its value so to change the routine from main to main2?
Normally, the variable "X" (or whatever variable is similar in some given program) can have its value assigned as follows (examples only):
1. In the beginning of the program as a user-supplied constant
2. As the result of a computation done within the program
3. From some external source
a. A rotary knob encoder (0-9)
b. A program on a PC which transmits the value to the Stamp
c. A program on another Stamp which transmits the value to this one
d. A keypad or other input device
e. The DEBUGIN command (see the PBASIC Reference Manual)
f. As data read from a EEPROM or other memory related device
That should give you some understanding of how "X" can be derived. I'm sure there are other means which I've neglected to include, merely due to my oversight.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Genius is one percent inspiration and ninety-nine percent perspiration."
Thomas Alva Edison
example: If i push the button then the "x" must be 1 and if not 0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
This is against my better judgement to provide such a routine, only because it doesn't represent a complete or practical program. However, here is an example.
In this example a PBASIC Stamp BS-2 is presumed to be the target processor, and the switch is presumed to be momentary contact, and wired to Pin Port one of the Stamp.
' {$STAMP BS2}
' {$PBASIC 2.5}
' Assign Pin Port to external switch
Switch PIN 1
'Assign RAM Variables
X VAR BYTE
Main:
X = 0
Fetch_Input:
'X will be 0 if the button is NOT pressed or 1 if it IS pressed
X = Switch
IF X = 1 THEN GOTO Switch_Pressed
IF X = 0 THEN GOTO Fetch_Input
Switch_Pressed:
'Do something here when the switch is pressed
GOTO Fetch_Input
END
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Genius is one percent inspiration and ninety-nine percent perspiration."
Thomas Alva Edison