
Cameron
USA
Asked
— Edited
Hey Everyone!
I am currently stuck on how to code these 2 sound sensors (1 on left, 1 on the right)(picture below) on the head of my robot. I have a servo (D18) that goes up to 180 degrees and I want the head to turn towards the loudest noise level. I have looked at some examples and I still dont have any progress.
Any help would be appreciated
Thanks,
Cameron
Very straight forward... This sensor plugs into an analog port... sample code would be...
Thank you very much Richard!
How would I fit the servo in there?
Using if statements... Here's a simple (in english wording) way to look at it. Once you get the logic worked out you can use script commands to achieve what you want
if sound level on left side great than a certain level move servo left else if sound level on right side greater than a certain level move servo right end if statement
Now just convert this to ARC script... I can do it for you but you won't learn anything... Take my example from my previous code post and take a shot at adding if/else statements to move your servos... You will need another variable for the right side as follows...
Yeah I'm someone who doesnt always just wants answers. I want to learn so I'm on the same page with that. Thank you Richard I will play around with it.
@Richard R So I think i'm missing something here...Servo seems to move but only the the left right away back and forth not picking up values...
:top $LevelLeft = GetADC(adc0) $LevelRight = GetADC(adc1)
if($LevelLeft > $LevelRight) Servo(D18,180) else if($LevelRight > $LevelLeft) Servo(D18,1)
endif
sleep(100)
goto(top)
Pretty good, but you may need a bit more...
If you dont have it yet, under Scripting in the controls, add a variable watcher. This will let you see what the $LevelLeft and $LevelRight variables are being set to.
Also, the sleep command is probably to short. This is 1/10 of a second. Try increasing the sleep command to something longer like 1000 (a second) and see if that helps you out.