programming problems
Johnnyt0
Posts: 2
Hi, I'm new for basic stamp... [noparse];)[/noparse] I'm creating small robot as my school project... but I have a problem... As I see in many places in forum, everything have to work fine, but it don't ... for example... if I write some subrotines... and it starts not to work properly... for example... one for , one do/loop everything is fine... but when some subrotines are written... then it starts to loop from the begining everytime... I don't know what is going ... for example... I'm trying to do (using ping sensor) robot looks left then measure the distance, then look in front of the robot, then measure the distance, then look right... etc... and it stop working... :S If you want I could post some fragments but... as I said everything have to be ok, but it is not ... I'm using BS2e and Super Carrier board [noparse]:)[/noparse]
Comments
Have you read "What's a Microcontroller?"? This is a good introduction to programming the Stamps. Also important is the "BASIC Stamp Syntax and Reference Manual". When you forget how a particular statement works, you can look it up in the Manual and this will explain that and give examples of its use. Both of these should be included in the Stamp Editor's help files, but you can also download them from Parallax (look in Downloads). They've also been translated into a number of common languages.
' {$STAMP BS2e}
' {$PBASIC 2.5}
counter VAR Word
i VAR Word
time VAR Word
dist VAR Word
' or do/loop
main:
counter=counter+1
IF counter<20 then
PULSOUT 4, 700
GOSUB search
IF dist>40 then
GOSUB foreward
else
DEBUG HOME, "Wall"
endif
ELSEIF counter<40 then
PULSOUT 4, 600
GOSUB search
IF dist>40 then
GOSUB foreward
else
DEBUG HOME, "Wall"
endif
ELSEIF counter<60 then
PULSOUT 4, 800
GOSUB search
IF dist>40 then
GOSUB foreward
else
DEBUG HOME, "Wall"
endif
else
counter=0
ENDif
GOTO main
search:
PULSOUT 5, 1
PULSIN 5, 1, time
dist = time ** 2260
return
foreward:
FOR i=1 TO 10
PULSOUT 1, 730
PULSOUT 2, 670
PAUSE 30
next
return