1) You aren't waiting for the Auto Position Action to finish before checking the ADC and looping again. So you're locking up the system by over and over and over and over and over and over and over and over and over and over and over and over and over again running the Auto Position Action.
Check and wait until the auto position action is completed.
2) Also, there was a GOTO at the beginning which just went to the next line...
3) The GOTO when finding the action is kind of irrelevant because the code can be placed wthin the IF/ENDIF
4) PS, when pasting code, place it within the [ code ] and [/ code ] blocks so it will be easier for others to read
# Bite using IR sensor on ADC port
# Adjust values below for configuration
$iradcport = ADC0 # Change for ADC Port with sensor attached
$maxirdistance = 100 # Change for maximum distance from object before biting in units
$currirdistance = GetADC($iradcport)
IF ($currirdistance >= $maxirdistance)
ControlCommand ( "Auto Position", AutoPositionAction, "Attack")
ControlCommand( "Soundboard V4", Track_4 )
WaitFor($AutoPositionStatus = 0)
Shouldn't that also be a <=? If I am reading this right, it is biting when the target is not near it, instead of when it is in range.
Ah yeah - I don't know which way the sensor returns. Does that sharp sensor return a higher voltage when near and lower voltage when away? I forget - I believe it's the latter. I feel the sensors output voltage is relative to the amount of IR received from the IR Receiver, which would mean higher voltage is closer object. In which case, he would have it correct with a >=
*EDIT: Yes, he has it correct according to the sharp datasheet graph