Ultra Sonic Sensor Script

 
#1

Hello,

i need help for a script for the Ultrasonic Sensor.

How i can make a script for diffrent commands on diffent distances?

My exampel Script


Code:



:loop

$proxclose = 30

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZB("You are to near")

EndIf

$proxclose = 100

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZB("Still to near")

EndIf

Sleep( 2000 )

goto(loop)




Has somebody an idea?

#2

It looks like you are on the right path. Does it not work for you?

#3

Hi JustinRatliff,

no,

The EZB only say the last one for "100"

$proxclose = 100

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZB("Still to near"Winky


For the "30" it never comes!

How i can make a command "between"?


It must be :

IF($proxsense is between 70 and 100)

but how to write it correct?

Boris

#4

I can't test this but I think you need to define 2 $proxclose variables. Try this script hopefully more seasoned script writers will jump in and help you out if this doesn't work

Code:


:loop

$proxclose = 30
$proxclose2 = 100
$proxsense = GetPing(D21,D22)


IF($proxsense < $proxclose)

SayEZB("You are to near")

EndIf

sleep(2000)

$proxsense = GetPing(D21,D22)

IF($proxsense > $proxclose and $proxsense< $proxclose2)

SayEZB("Still to near")

EndIf

Sleep( 2000 )

goto(loop)

#5

@Boris You need to use SayEZBWait on at least the first SayEZB command or the second one will cancel out the first before it has a chance to speak...

Code:


:loop

$proxclose = 30

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZBWait("You are to near") #changed this line
sleep(1000) #put a pause in too

EndIf

$proxclose = 100

$proxsense = GetPing(D21,D22)

IF($proxsense < $proxclose)

SayEZB("Still to near")

EndIf

Sleep( 2000 )

goto(loop)

#6

My Ping Roam script (which either it's a huge coincidence you chose the same variables I did or you have seen already) should walk you through making adjustments. My notes on Ping Roam should also be a huge help too. Check this topic, I included all of my notes and hand scribbled changes.

Rather than give you the fish I want you to learn to fish. So no code examples here! But you are looking at the IF statement command

Code:

IF($x > $y)



And the ElseIf and Else commands.

Code:

IF($x = 1)
Say("1")
ElseIF($x = 2)
Say("2")
ElseIF($x = 3)
Say("3")
Else
Say("x is not between 1 and 3")
EndIF



Use different distance values and either the =, < or > for different actions. Use ControlCommand() to start other scripts, controls, autopositions etc.

And for between values, use the AND or the OR operator

Code:

if($x > 50 AND $x < 90)