How to Detect Which Way a Potentiometer is Rotating?
hi all,
i'm wondering if there way figure out direction potentiometer rotating (counterclockwise vs clockwise) , print serial monitor.
here how find angle if helps @ all:
the background story is: i'm trying use potentiometer control servo move r/c quadcopter controller stick.
if pot rotates 1 degrees clockwise, must move servo preset distance clockwise delay equal potentiometer degree value, , spring center.
if pot rotates counterclockwise, must move servo preset distance counterclockwise delay equal pot degree value, spring center. tell quadcopter rotate same amount of degrees potentiometer.
i'm wondering if there way figure out direction potentiometer rotating (counterclockwise vs clockwise) , print serial monitor.
here how find angle if helps @ all:
code: [select]
float maxreading=170;
float minreading=30;
int anglepin = 2;
void setup()
{
serial.begin(9600);
}
void loop()
{
float multvalue = ((maxreading-minreading)/180);
float input = analogread(anglepin);
//uncomment line below when finding maximum , minimum readings turning potentiometer 180 degrees.
//serial.println(analogread(anglepin));
float anglereading = (input - minreading) / multvalue;
//uncomment line below angle reading.
//serial.println(anglereading);
delay(500);
}
the background story is: i'm trying use potentiometer control servo move r/c quadcopter controller stick.
if pot rotates 1 degrees clockwise, must move servo preset distance clockwise delay equal potentiometer degree value, , spring center.
if pot rotates counterclockwise, must move servo preset distance counterclockwise delay equal pot degree value, spring center. tell quadcopter rotate same amount of degrees potentiometer.
quote
i'm wondering if there way figure out direction potentiometer rotatingread pot each time through loop() , save value. when read again next time through loop() if value has increased pot turning 1 way , if has decreased moving other way.
in practice need allow amount change of value before making decision due instability of input voltage.
Arduino Forum > Using Arduino > Programming Questions > How to Detect Which Way a Potentiometer is Rotating?
arduino
Comments
Post a Comment