Programming question. should be easy for you guys i think :)

hello there everybody. i'm really new at robotics but i made the starter kit from LMR and it worked perfectly :) now i'm just fooling around trying to make program myself. i wanted my servo to react to how close my hand is to the Sharp IR sensor. first i made 2 symbols (far and close) and said, that if variable "b0" is greater than the first symbol and less than the second. turn servo if not, return to main. and it worked just fine. now i want to make 3 symbols, for the robot to relate to.

here is what i'm trying:

 

 symbol far = 30
symbol medium = 60
symbol close = 90

main:
readadc 1, b0
debug
if b0 > far and b0 < medium then
gosub turn1 else
gosub nothing
if b0 > medium < close then
gosub turn2 else
gosub nothing
end if
goto main


turn1:
servo 0,300
wait 2
servo 0,150
wait 2
goto main

turn2:
servo 0,100
wait 2
servo 0,150
wait 2
goto main


nothing:
goto main

try this

the problem is that your main function will never get to the second “if”, try this (not sure about the syntax):

main:
readadc 1, b0
debug
if b0 > far and b0 < medium then
gosub turn1 else
if b0 > medium < close then
gosub turn2 else
gosub nothing
end if
goto main

thanks i will try, but it

thanks i will try, but it was exactly there, it complained :slight_smile:

nope, it says:" if b0 >

nope, it says:" if b0 > medium < close then

 

Error: Syntax error in this line!"

 

it’s the same as before :frowning:

i think it should beif b0 >

i think you forgot an "and"

if b0 > medium and b0 < close , if i got what you’re saying.

Correct syntax

Correct syntax for line
if b0 > medium < close then
would be this:
if b0 > medium and b0 < close then

(Like CaptainTuna said)

You are also missing on endif in your program. Add it before the line giving syntax error like this:
endif
if b0 > medium and b0 < close then

That should give you correct syntax. Also, you should use return instead of goto main in subroutines turn1, turn2 and nothing.

 

Even easier. --select case.

Find select case in the manual.

select case b0

case < close

do whatever

case close to medium

do whatever

case medium to far

do whatever

case >far

do whatever

endselect

 

That should work just fine for you.