Mauritius
Asked — Edited
Resolved Resolved by ptp!

Distance And Souns

Hello Community,

I would like a script that will allow ultrasonic to sense a close distance and play a music file.

Can anyone help me to create such script?

Br,

Nyyir


ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

#1  

This is very simple to do. All you have to do is use an If statement. Example:


if getping() < #distance

Controlcommand("soundboard", Track_1)

Endif

This will run once and play a sound if the distance if at the set number. change #distance to the output of the ping sensor that is the distance you want.

PRO
USA
#2  

assuming you have a Soundboard control added to your project

try this:


#Ping/HC-SCR04 sensor configuration:
#     D1 = trigger port
#     D2 = echo port

#safe distance in centimeters
$safe_distance = 50

:loop

        #wait for a distance lower than the safe_distance
	Ping_Wait( D1, D2, lower, $safe_distance)
	
	#play soundboard control track 0
	ControlCommand("Soundboard", Track_0)
	
	#wait for distance greater than the safe_distance
	#this will avoid multiple play sounds  
	Ping_Wait( D1, D2, higher, $safe_distance) 
	
Goto(loop)
PRO
USA
#3  

@MazeHorizonTech you beat me in 6 seconds... not fair you are around the corner (Canada):)

PRO
USA
#4  

@MazeHorizonTech

Missing:

  1. if parentheses
  2. Ping Ports

Something like this:


if (GetPing(D1, D2)<50)
   ControlCommand("Soundboard", Track_0)
endif
#5  

The easiest way...


Ping_Wait(D1,D2,LOWER, 15)
ControlCommand("Soundboard", Track_0)
Mauritius
#6  

Thank you very much guys for helping:)

#7  

@ptp My bad. ARC didn't complain when I wrote it out in full interestingly.

If @nyyirsS uses Richards, all he has to do is add a loop if he wants it to repeatedly happen.

Mauritius
#8  

@MazeHorizonTech

All answers is good. I give credit to ptp bkoz he usues comments which makes me understand as I have no previous knowledge in ez script..

Still Thank you everyone for your help