Shop OBEX P1 Docs P2 Docs Learn Events
programming problems — Parallax Forums

programming problems

Johnnyt0Johnnyt0 Posts: 2
edited 2009-12-14 07:10 in BASIC Stamp
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

  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-14 00:01
    It is really impossible to help you very much without seeing your program. Use the Attachment Manager to include it in your next message. Use the Post Reply button to get the Attachment Manager.

    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.
  • Johnnyt0Johnnyt0 Posts: 2
    edited 2009-12-14 07:10
    Let see. for example this small program. pins 1 adn 2 contol moving servos, 5 is ping sensor, and 4 is servo that rotates ping sensor... and it have to "look foreward" for 20 steps, then look left for 20 steps then look right for 20 steps... but in fact, when I put debug after counter in the begining it shows .... "1" so it look only foreward ... I tried to put end at many places but no effect.
    ' {$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
Sign In or Register to comment.