Programming doubts

Sifty

New Member
Hi!

I am triyng to make a line follower. I am thinking about program to download to picaxe. I have a 28x2 pic.

I think it could be a good idea the use of parallel task (maybe it is the worst :confused:). Anyway, I have a doubt about the use of input/output pins. I don't know how to write it. Because program editor says always: wrong! wrong! wrong!

Code:
symbol cnyIzq = pinA.0
symbol cnyDer = pinA.1
symbol motorDer = pinC.2 
symbol motorIzq = pinC.0
symbol boton = pinB.0

start0:
	if cnyIzq=1 then high motorDer
	if((cnyIzq=0) then low motorDer
	if(boton=1) then goto final
	goto start0
	
	
	
start1:
	if(cnyDer=1) then high motorIzq
	if((cnyDer=0) then low motorIzq
	if(boton=1) then goto final
	goto start1
	
	
	
final: 
	end
I get this message:
if cnyIzq=1 then high motorDer
^

Error: This command requires the pin number in format PORT.PIN!
I am using A0, A1, A2 and A3 for CNY70. But in this version just A0 and A1.
C0 and C1 for left motor(motorIzq) and c2 and c3 for right motor (motorDer)
B0 for a button to start/stop the program. For the moment just stop it...

How do I have to write code for inputs/outputs pins? I am reading manual but I just see outpinsC.3... but it gives me error, or pinA.2... Do I need anything more?
 

westaust55

Moderator
when you use an IF...THEN command structure such as your lines:
if cnyIzq=1 then high motorDer​
the THEN can only be directly followed by a label (and an optional GOTO) or GOSUB and a label.

When you wish to perform some tasks then you must indicate the extent of those tasks with and ENDIF command.

Thus the above line becomes:
Code:
if cnyIzq = 1 then 
    high motorDer
endif
Now this can be done on one line and the PE syntax will allow spaces, but IMHO that is getting lazy and makes the code hard to read at a quick glance, thus I would highly recommend that you use a semicolon as a "line separator" as mentioned in the PICAXE manuals.
So the above line could become:
IF cnyIzq = 1 THEN : high motorDer : ENDIF​
My personal preference and recommendation is to use all capitals for the programming commands and keywords as per my example above which makes identification of the program commands easy at a glance.

EDIT: correction as mentioned below - line separator is a colon (:) and not a semicolon (;) :eek:
 
Last edited:

Sifty

New Member
Oh!... then I have to change my program...

I changed my program as westaust55 said but I stilll get the same message.
SYMBOL cnyIzq = pinA.0
SYMBOL cnyDer = pinA.1
SYMBOL motorDer = outpinC.2
SYMBOL motorIzq = outpinC.0
SYMBOL boton = pinB.0

start0:
IF cnyIzq=1 THEN : high motorDer : ENDIF
IF cnyIzq=0 THEN : low motorDer : ENDIF
IF boton=1 THEN GOTO final
GOTO start0

final:
END
Any idea what do I have to do about pins and ports?
 

hippy

Ex-Staff (retired)
The error is in -

SYMBOL motorDer = outpinC.2
SYMBOL motorIzq = outpinC.0
The Programming Editor is indicating that the HIGH and LOW commands expect a port.pin name and outpinC.2 isn't that format - you probably want C.2 so ...

SYMBOL motorDer = C.2
SYMBOL motorIzq = C.0
 

westaust55

Moderator
Try the following:
Brackets have been removed and for output pins the "pin" part of the SYMBOL assignment has been removed

Code:
; input definitions
symbol cnyIzq  = pinA.0
symbol cnyDer = pinA.1
symbol boton   = pinB.0
; output definitions
symbol motorDer = C.2 
symbol motorIzq = C.0

start0:
	if cnyIzq=1 then : high motorDer : endif
	if cnyIzq=0 then : low motorDer : endif
	if boton=1 then goto final
	goto start0
	
	
	
start1:
	if cnyDer=1 then high motorIzq : endif
	if cnyDer=0 then low motorIzq : endif
	if boton=1 then goto final
	goto start1
	
	
final: 
	end
 

westaust55

Moderator
Yes it should be a "colon" (not a semicolon as I had stated in error).
Semicolons are used for defining the start of a comment.

But don't think that confused Sifty too much as his next code attempt had the right character ( : )
 
Last edited:

Sifty

New Member
thanks all!

I already can check it with simulator. I corrected everything wrong. When I make the robot an check the program I will upload all what I have.
 

Sifty

New Member
one more question... I don't know if I am doing right the reading of cny70. they give 1 or 0 or give another diferent thing?
 

westaust55

Moderator
one more question... I don't know if I am doing right the reading of cny70. they give 1 or 0 or give another diferent thing?
Ahhh, ummm, . . .
Yes in post 1 you mention
I am using A0, A1, A2 and A3 for CNY70. But in this version just A0 and A1.
However, it might help folks if you gave a link to the cny70 rather than folks having to search for it :(

If you are detecting with IF pinX = value THEN or similar commands then the best you will see is a 0 or 1 state.

The Vishay dastsheet indicates a current somewhat proportional to distance. Pass that current through a resistor and you have a voltage.
But you will need to use a READADC command on an ADC enabled input to read a variable value (0 to 255 for READADC).
You may even need some form of amplifier to increase the magnitude of the voltage so that signal covers close to 0 to Vcc (PICAXE Supply voltage)
 

westaust55

Moderator
Did you read the second part of post 11 ?

If you need further help I think you will need to explain what exactly you are expecting or trying to archive when asking if there are values other than o or 1.
 
Top