loading
 
How can I put two codes in basic stamp?
Edward from Spain  [10 posts]
16 year
Hello, I'm doing a tracking color object with boe bot and Roborealm but I would like to put another code. I explain you, I have a code of a light sensor with a LDR and on the other hand I have the code for servo. How can I insert the two codes that they are independents?

The codes are:

' {$STAMP BS2}
' {$PBASIC 2.5}

RC PIN 1

result VAR Word

Led PIN 10


Main:
HIGH RC
PAUSE 50
RCTIME RC,1, result
IF (result<200) THEN Ledoff
IF (result>200) THEN Ledon
Ledoff:
LOW Led
GOTO Main
Ledon:
HIGH Led
GOTO Main

......................................

' {$STAMP BS2}
' {$PBASIC 2.5}

x VAR Word
y VAR Word
tilt VAR Word

main:
SERIN 0,84,[WAIT ("!"),DEC4 x,DEC4 y,DEC4 tilt]
PULSOUT 14, x
PULSOUT 15, y
PULSOUT 13, tilt
PAUSE 5
GOTO main

Thank you
Justin Ratliff from United States  [8 posts] 16 year
Edward,

This sounds a little bit more like a Basic Stamp question than a RoboRealm question.  Did you Parallax.com had a forum sections for the Basic Stamp and robotics questions?  With a question about your Boe-Bot code the folks on the Parallax.com forum can probably provide a wider range of feedback for your question.

I have worked with the Basic Stamps for many years and I think I can help answer your questions.  It sounds like you want to create 1 program that does the function of both your seperate programs, is that correct?  If so, I don't see anything with your code that would prevent you from doing that with the samples you listed here.  This is how I would combine the programs:

________________________
{$STAMP BS2}
' {$PBASIC 2.5}

RC       PIN 1
result  VAR Word
Led     PIN 10

'servo variables
x        VAR Word
y        VAR Word
tilt      VAR Word


Main:
HIGH RC
PAUSE 50
RCTIME RC,1, result
IF (result<200) THEN Ledoff
IF (result>200) THEN Ledon
Ledoff:
LOW Led
GOTO Main
Ledon:
HIGH Led
GOTO Servo


Servo:
SERIN 0,84,[WAIT ("!"),DEC4 x,DEC4 y,DEC4 tilt]
PULSOUT 14, x
PULSOUT 15, y
PULSOUT 13, tilt
PAUSE 5
GOTO main

_________________________________

Do you see what I did there?  I combined your variables at the top and renamed the second "main:" to "Servo:".  When it runs it should do the Main section, then the Servo section the loop back to Main and keep repeating.

If you have other Basic Stamp questions you can e-mail me off the forum at Weyoun7@aol.com

Very Best Regards and Happy Roboting,
-Justin Ratliff

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index