How to combine two programs? For Christmas surprise, please respond sooner rat
emmali55
Posts: 10
I am new to this whole programming thing - basically following the directions in the boe-bot book.· I have two programs that I would like the boe-bot to do simultaneously.· Can anyone help me paste the code together?· It is a scrolling message code and a "follow the light" code.·They are below:
MESSAGE (I don'y know why it is underlined...)
SEROUT 14,84, [noparse][[/noparse]22,12]
DO
PAUSE 250
SEROUT 14, 84, [noparse][[/noparse]12]: PAUSE 5
PAUSE 5
SEROUT 14, 84, [noparse][[/noparse]"MERRY CHRISTMAS"]
SEROUT· 14, 84, [noparse][[/noparse]255,
··············· %00100,
··············· %00100,
··············· %01110,
··············· %01110,
··············· %11111,
··············· %11111,
··············· %00100,
··············· %00100]
SEROUT 14, 84, [noparse][[/noparse]149]
SEROUT 14, 84, [noparse][[/noparse]7]
PAUSE 750
SEROUT 14, 84, [noparse][[/noparse]"· I love YOU!"]
PAUSE 2000
SEROUT 14, 84, [noparse][[/noparse]12]
PAUSE 500
LOOP
FOLLOW LIGHT
DEBUG "Program Running!"·········· 'Roam with Light, Sit when dark.
· leftAmbient··· CON 380
· rightAmbient·· CON 230
· leftBright···· CON 32
· rightBright··· CON 20
· leftThreshold· CON leftBright + leftAmbient / 2· * 5 / 8
· rightThreshold CON rightBright + rightAmbient / 2 * 5 / 8
· darkThreshold· CON 200
· timeLeft······ VAR Word
· timeRight····· VAR Word
FREQOUT 4,2000,3000
DO
· GOSUB test_photoresistors
· GOSUB navigate
LOOP
test_photoresistors:
· HIGH 6
· PAUSE 3
· RCTIME 6, 1, timeLeft
· HIGH 3
· PAUSE 3
· RCTIME 3, 1, timeright
· RETURN
Navigate:
· DO
····· IF timeRight > darkThreshold AND timeLeft > darkThreshold THEN
····· NAP 6····· ' Sleep for about one second, then repeat loop
·· ELSE
····· EXIT········' Continue with rest of program
·· ENDIF
LOOP
· IF (timeLeft < leftthreshold) AND (timeRight < rightthreshold) THEN
··· PULSOUT 13, 850
··· PULSOUT 12, 650
· ELSEIF (timeLeft < leftthreshold) THEN
··· PULSOUT 13, 700
··· PULSOUT 12, 700
· ELSEIF (timeRight < rightthreshold)THEN
··· PULSOUT 13, 800
··· PULSOUT 12, 600
· ELSE
··· PULSOUT 13, 750
··· PULSOUT 12, 750
· ENDIF
· PAUSE 20
·RETURN····························· 'END Light program
·
MESSAGE (I don'y know why it is underlined...)
SEROUT 14,84, [noparse][[/noparse]22,12]
DO
PAUSE 250
SEROUT 14, 84, [noparse][[/noparse]12]: PAUSE 5
PAUSE 5
SEROUT 14, 84, [noparse][[/noparse]"MERRY CHRISTMAS"]
SEROUT· 14, 84, [noparse][[/noparse]255,
··············· %00100,
··············· %00100,
··············· %01110,
··············· %01110,
··············· %11111,
··············· %11111,
··············· %00100,
··············· %00100]
SEROUT 14, 84, [noparse][[/noparse]149]
SEROUT 14, 84, [noparse][[/noparse]7]
PAUSE 750
SEROUT 14, 84, [noparse][[/noparse]"· I love YOU!"]
PAUSE 2000
SEROUT 14, 84, [noparse][[/noparse]12]
PAUSE 500
LOOP
FOLLOW LIGHT
DEBUG "Program Running!"·········· 'Roam with Light, Sit when dark.
· leftAmbient··· CON 380
· rightAmbient·· CON 230
· leftBright···· CON 32
· rightBright··· CON 20
· leftThreshold· CON leftBright + leftAmbient / 2· * 5 / 8
· rightThreshold CON rightBright + rightAmbient / 2 * 5 / 8
· darkThreshold· CON 200
· timeLeft······ VAR Word
· timeRight····· VAR Word
FREQOUT 4,2000,3000
DO
· GOSUB test_photoresistors
· GOSUB navigate
LOOP
test_photoresistors:
· HIGH 6
· PAUSE 3
· RCTIME 6, 1, timeLeft
· HIGH 3
· PAUSE 3
· RCTIME 3, 1, timeright
· RETURN
Navigate:
· DO
····· IF timeRight > darkThreshold AND timeLeft > darkThreshold THEN
····· NAP 6····· ' Sleep for about one second, then repeat loop
·· ELSE
····· EXIT········' Continue with rest of program
·· ENDIF
LOOP
· IF (timeLeft < leftthreshold) AND (timeRight < rightthreshold) THEN
··· PULSOUT 13, 850
··· PULSOUT 12, 650
· ELSEIF (timeLeft < leftthreshold) THEN
··· PULSOUT 13, 700
··· PULSOUT 12, 700
· ELSEIF (timeRight < rightthreshold)THEN
··· PULSOUT 13, 800
··· PULSOUT 12, 600
· ELSE
··· PULSOUT 13, 750
··· PULSOUT 12, 750
· ENDIF
· PAUSE 20
·RETURN····························· 'END Light program
·
Comments
DO
GOSUB message
GOSUB followLight
LOOP
You'll have to get rid of the DO-LOOP pairs in the two programs that you posted, and replace the LOOP part with RETURN. Also, to make them functions you'll want to add a : (colon) after the 'title' (and make follow light one word).
You may want to get rid of some of your long pauses (just to make things happen faster)
The variable and constant declarations should be moved out if the follow light function and placed at the top of the program.
DO
GOSUB follow_light
GOSUB scroll_message
LOOP
etc.
But it only runs the first one. i.e. if set up like above, will only run follow_light. If I switch their positions, it will only run the scroll_message. It loads the program OK and doesn't find anything wrong with it. Do you know what is going on?
And I think we are in business! I like it flashing better but if this is what it takes to make it work, I will live with it. Thanks for your help.
By doing it this way, you can break it down into more logical blocks. Of course, this necessitates changing some code, namely the navigate routine and message routine. The problem occurs when the servos need to be refreshed every 20 ms, while your message routine takes several seconds.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
When all else fails.....procrastinate!