Loop with two motor and 2 sensors


+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Posts
    23

    Default Loop with two motor and 2 sensors

    I have two motors, dc gear motors, and 2 sensors, (1 switch and 1 momentary switch).

    My code below does not compile, i get alot of errors(see bottom), can anyone help. I want to have the motors run to move robot forward until switch is 1 or until momentary switch is 0 and then reverse one motor and stop the other motor for 2 seconds. Then continue in endless loop.

    ==================

    b0 var byte 'count


    start:

    if(PORTA.1 = 1) then
    'edge detected
    for b0=1 to 2
    gosub backup
    next

    end if

    if (PORTA.2=0) then
    'obstacle detected
    for b0=1 to 2
    gosub backup
    next


    if (PORTA.1=0 && PORTA.2=1) then
    'no edge or obstacle detected
    gosub forward
    endif

    goto start

    '===============
    subroutines
    '===============

    backup:
    PORTB.7=high 'enable pin
    PORTB.6=low 'stop this side
    PORTB.5=low

    PORTB.4=low 'reverse this side
    PORTB.3=high
    PORTB.2=high 'enable pin

    return

    forward:
    PORTB.7=high 'enable pin
    PORTB.6=high
    PORTB.5=low

    PORTB.4=high
    PORTB.3=low
    PORTB.2=high 'enable pin

    return
    ===================
    ===================
    -------
    errors
    -------
    ERROR Line 12: ':' or '=' Expected (Token 'var') (BASIC CODE from book test.bas)
    ERROR Line 17: Variable Expected (Token '(') (BASIC CODE from book test.bas)
    ERROR Line 17: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 23: End of Line or ':' Expected (Token 'if') (BASIC CODE from book test.bas)
    ERROR Line 25: Variable Expected (Token '(') (BASIC CODE from book test.bas)
    ERROR Line 25: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 32: Variable Expected (Token '(') (BASIC CODE from book test.bas)
    ERROR Line 32: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 35: ':' or '=' Expected (BASIC CODE from book test.bas)
    ERROR Line 41: ':' or '=' Expected (BASIC CODE from book test.bas)
    ERROR Line 45: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 45: ':' or '=' Expected (Token '7') (BASIC CODE from book test.bas)
    ERROR Line 46: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 46: ':' or '=' Expected (Token '6') (BASIC CODE from book test.bas)
    ERROR Line 47: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 47: ':' or '=' Expected (Token '5') (BASIC CODE from book test.bas)
    ERROR Line 49: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 49: ':' or '=' Expected (Token '4') (BASIC CODE from book test.bas)
    ERROR Line 50: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 50: ':' or '=' Expected (Token '3') (BASIC CODE from book test.bas)
    ERROR Line 51: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 51: ':' or '=' Expected (Token '2') (BASIC CODE from book test.bas)
    ERROR Line 58: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 58: ':' or '=' Expected (Token '7') (BASIC CODE from book test.bas)
    ERROR Line 59: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 59: ':' or '=' Expected (Token '6') (BASIC CODE from book test.bas)
    ERROR Line 60: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 60: ':' or '=' Expected (Token '5') (BASIC CODE from book test.bas)
    ERROR Line 62: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 62: ':' or '=' Expected (Token '4') (BASIC CODE from book test.bas)
    ERROR Line 63: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 63: ':' or '=' Expected (Token '3') (BASIC CODE from book test.bas)
    ERROR Line 64: Illegal Character '.' (BASIC CODE from book test.bas)
    ERROR Line 64: ':' or '=' Expected (Token '2') (BASIC CODE from book test.bas)
    =======================

  2. #2
    fronkensteen's Avatar
    fronkensteen Guest

    Default

    Quote Originally Posted by MrRoboto View Post
    My code below does not compile, i get alot of errors(see bottom), can anyone help.
    You could help yourself a lot by reading the PBP manual and learn how to assign a value to a variable.

    Assuming this is your exact and complete code ( I know sometimes things don't cut and paste correctly, but I'll assume it did)
    Code:
    end if
    ENDIF is one word, not two.

    Code:
    if (PORTA.2=0) then
    'obstacle detected
    for b0=1 to 2
    gosub backup 
    next
    Where's the ENDIF?

    Code:
      PORTB.7=high  'enable pin
      PORTB.6=low    'stop this side
    Where is HIGH and LOW defined? And what are their defined values?

    Code:
    ERROR Line 12: ':' or '=' Expected (Token 'var') (BASIC CODE from book test.bas)
    I haven't seen an error formatted like that in MeLabs PicBasicPro...unless you added the (BASIC CODE from book test.bas)
    Hmmmm........

  3. #3
    Join Date
    Dec 2008
    Posts
    23

    Default 2 motors and 2 simple sensors

    thanks for the reply.

    I used endif as one word,it didnt show right here though.

    I want the pin to be set to HIGH, 5 volts, how would I tell it that.

    What is the book test.BAS??

    any suggestions how i could accomplish what I am trying to do?

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,817

    Default

    Quote Originally Posted by MrRoboto View Post
    thanks for the reply.

    I used endif as one word,it didnt show right here though.

    I want the pin to be set to HIGH, 5 volts, how would I tell it that.

    What is the book test.BAS??

    any suggestions how i could accomplish what I am trying to do?
    switch them around a bit. . .
    instead of
    Code:
    PORTB.7=high  'enable pin
      PORTB.6=low    'stop this side
    say it with feeling, like so . . .
    Code:
    High PortB.7
    Low  PortB.6
    Still better yet, set the ports to a known state first, set the tris registers to inputs or outputs as desired second, and then in your code control them by making statements like PortB.7 = 1 or PortB.6 = 0
    as far as errors go BASIC CODE from book test.bas must be your file name.
    Last edited by Archangel; - 6th December 2008 at 07:51.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Dec 2008
    Posts
    23

    Default Loop

    So how would I perform the loop then.


    When you say name the file

    BASIC CODE from book.bas

    is that what you mean????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts