I’ve been wondering as to how I could obtain the velocity of a potentiometers rotational speed. I thought it would be as simple as obtaining the potentiometers resistance followed by the time for an initial and a final values. But I’m not getting any change in speed when I adjust the pot.
Here’s my code:
long t1 = 0;
long t2 = 0;
int v1 = 0;
int v2, pot, cal, speed, start, potval;
void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
}
void loop()
{
potval = analogRead(A0);
pot = map(potval, 0, 1023, 0, 200);
if(t1 = 0){
t1 = micros();
v1 = pot;
t2 = 0;
}
if(t2<t1){
t2 = micros();
v2 = pot;
}
cal = (v2-v1)/(t2-t1);
speed = abs(cal);
t1 = 0;
v1 = 0;
Serial.println(speed);
}