int hits = 0;
float wheel_radius = 1;
volatile unsigned int current_time;
long time_interval = 1000; //how
often do you want to know velocity (milliseconds)
float velocity; //this is the velocity in length units
/ time_interval
void setup ()
{
Serial.begin(9600);
attachInterrupt(0, count, CHANGE);
current_time = millis();
}
void loop ()
{
if ( millis() >= current_time + time_interval)
{
velocity = (hits*(wheel_radius * 392.7))/time_interval;//the
constant is 2*pi*1000/16
Serial.println(velocity);
hits = 0;
current_time = millis();
}
}
void count()
{
hits++;
}
No comments:
Post a Comment