User Defined Function Example icon User Defined Function Example — Add custom EZ-Script functions in C# or JS; intercept unknown calls, parse parameters and return values via AdditionalFunctionEvent. Try it →
Robot Showcase

Counting Rotations Of A Parallax Feedback 360 Degree Servo

2,505 views 0 comments

About this robot

I thought this script might be useful for someone wanting to specify the number of rotations for a Parallax Feedback 360 degree servo. The servo is connected to port D0 and the 4th wire to ADC0.

#Rotate anti-clockwise for 5 rotations Servo(D0,80) $rotations = 0 $ADC = 999 $PreviousADC = 999 repeatwhile($rotations < 6) $ADC = GetADC(adc0) #Determine if value of ADC has increased significantly - If so, one rotation has occurred if ($ADC > $PreviousADC + 100) $rotations = $rotations + 1 endif print("Previous ADC " + $PreviousADC + " - Current ADC " + $ADC + " - Rotations: " + $rotations) $PreviousADC = $ADC sleep(10) endrepeatwhile Servo(D0,105) sleep(1000)

#Rotate clockwise for 5 rotations Servo(D0,130) $rotations = 0 $ADC = -1 $PreviousADC = -1 repeatwhile($rotations < 6) $ADC = GetADC(adc0) #Determine if value of ADC has decreased significantly - If so, one rotation has occurred if ($ADC < $PreviousADC - 100) $rotations = $rotations + 1 endif

print("Previous ADC " + $PreviousADC + " - Current ADC " + $ADC)

$PreviousADC = $ADC sleep(10) endrepeatwhile #ADC_Wait_Between(adc0,0,4,5) Servo(D0,105) sleep(1000)

By

Discover more robots

Robots the community built with Synthiam ARC. Get ideas for your next build.


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.