PDA

View Full Version : Loop with two motor and 2 sensors



MrRoboto
- 6th December 2008, 02:03
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)
=======================

fronkensteen
- 6th December 2008, 02:33
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)


end if

ENDIF is one word, not two.


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

Where's the ENDIF?



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

Where is HIGH and LOW defined? And what are their defined values?



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........

MrRoboto
- 6th December 2008, 06:06
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?

Archangel
- 6th December 2008, 07:47
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

PORTB.7=high 'enable pin
PORTB.6=low 'stop this side
say it with feeling, like so . . .


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.

MrRoboto
- 8th December 2008, 23:40
So how would I perform the loop then.


When you say name the file

BASIC CODE from book.bas

is that what you mean????