
I have got two EZBv4's connected to my project. As you can see in the code below, I have an Ultrasonic sensor connected to controller #1 and I am trying to get it to move a servo one controller #0. When I run it, the servo does not move. Am I missing something in communicating between the two controllers?Code:
$trigport = 1.D0
$echoport = 1.D1
$proxclose = 50 # Change for minimum distance
:start
:sensor check
$proxsense = GetPing($trigport, $echoport)
IF($proxsense < $proxclose)
servo(0.d2,112)
sleep(2000)
servo(0.d2,130)
sleep(2000)
servo(0.d2,112)
sleep(9000)
elseif($proxsense > $proxclose)
goto(sensor check)
sleep(3000)
endif
Goto(start)
Code:
However, and I know that I am guilty of this but ports shouldn't really be defined by variables. If they aren't going to change in your project you might as well hard code them in.
Also, I'm not sure if it's the forums or if it's the way you intended but it doesn't show the less than sign in the if statement.
Code:
And finally, where's the code to move the servo? It looks like it's missing the line
Code:
Presuming the servo is on board 0 and needs to move to position 90.
note: if board 0 is used you needn't use the preceding 0. as part of the port number, it will always assume the board is board 0 unless otherwise stated.
Code:
It does what it should when I run it on the console.
Also, the elseif isn't needed. If the first argument is false (i.e. ping less than 50) then just using the goto(start) will work fine. The elseif is practically doing the same thing. The sleep after the goto in the elseif is redundant as it'll never get to be executed.
Try this code, it should work;
Code:
If it doesn't work try running just the following piece of code;
Code:
Code: