New to Programming, and need help
J^3
Posts: 121
Hello everyone, I am currently working through the "What's a Microcontroller" book and have a question.· At the end of chp 4 the project requests you to add a kill switch to the program.· An example is given, but if I am not mistaken the kill switch will not interupt the DEBUGIN commands, and stop the machine.· This brings me to my question.· Is there an instruction that will interupt a program based on conditions being true or false.·
Thank you , any help would be appreciated.
·
Thank you , any help would be appreciated.
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--DFaust
During the journey from top to bottom you can place commands that will skip lines·or redirect program execution to elsewhere based on decisions you specify in your code.
The ability to make decisions is the power of programming, look in the help file for IF....THEN , BRANCH , SELECT..CASE , GOSUB , DO..WHILE.
Jeff T.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--DFaust
I am not sure if while in the command if the keyboard input would finish for example if the timeout was 1000mS and the input started at 999 mS if the byte received would be a valid character. You can arrange your interface for the user to hit a button or press a special key like enter to begin input aswell, that way you can set a timeout of a few mS and background process while waiting for keyboard input. When you receive the special character you then use a 65 second timeout or something. Not sure if there would be a timeout extension as characters are typed either. If you set it for 5 seconds and started receiving at least one character per 5 seconds if it would stay in the command and continue receiving data. You will have to experiment with those things.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
Main:
IF (IN1 = 1) Then "place name of Sub routine here":
"Sub routine":
code
GOTO Main
with this that portion of the code you are writing will only execute if that input is made.· help?
You might be interested in the following link...
Interrupt programming with BS2
http://forums.parallax.com/showthread.php?p=467380
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
' Send messages to the BASIC Stamp to control a servo using
' the Debug terminal. Also added start and stop buttons.
' {$STAMP BS2}
' {$PBASIC 2.5}
Estop VAR Bit
counter VAR Word
pulses CON 100
duration VAR Word
DO
IF IN3 = 1 AND IN4 = 1 THEN 'IN3 is normally high and IN4 is normally low
Estop = 1
ELSEIF IN3 = 0 AND IN4 = 0 THEN 'IN3 (stop button) has been pushed
Estop = 0
ENDIF
IF Estop = 1 THEN 'Start/Stop logic is true
DO
DEBUG CLS
DEBUG "Enter PULSOUT duration:", CR
DEBUGIN DEC duration
IF duration < 500 THEN
DEBUG "Value of duration must be above 499", CR
PAUSE 1000
ENDIF
IF duration > 1000 THEN
DEBUG "Value of duration must be less than 1001", CR
PAUSE 1000
ENDIF
LOOP UNTIL duration > 499 AND duration < 1001
DEBUG "Servo is running...", CR
FOR counter = 1 TO pulses
PULSOUT 14, duration
PAUSE 20
NEXT
FOR counter = 1 TO pulses
PULSOUT 14, 750
PAUSE 20
NEXT
DEBUG "Done", CR
ELSEIF Estop = 0 THEN 'Start/Stop logic is false
DEBUG "Press start switch to start machinery"
DEBUG HOME
ENDIF
LOOP
'Problem is, once IF Estop = 1 is true, I haven't been able
' to get the BS2 to back out of the code block when Estop = 0.
Also when posting code use the # button to insert code tags or type:
opensquarebracket code closedsquarebracket
.your code here
opensquarebracket /code closesquarebracket
You may not be able to use the debug output to show the viewbar or reduce the pause 20 to allow for the output.
If user inputs a duration and the stop is pushed it will go back to main as well as if during servo output the stop is pressed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
Post Edited (metron9) : 10/21/2007 11:29:21 PM GMT