#define signal 3
long debutPeriode;
long timestamp;
long check;
long oldtime = 0;
long time = 0;
int count = 0;
long Efreq = 200;
int nb_palier = 10;
int diametre_roue = 250;
float speed;
float frequency;
String datamessage;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(signal),timeSinceFallingEdge, FALLING);
}
void loop() {
timestamp = millis();
if (timestamp - debutPeriode >= Efreq){
frequency = (count*(1000/Efreq));
speed = diametre_roue/2 * 3.14 * frequency / 10000;
datamessage = String(count) + " " + String(frequency/nb_palier,4) + " " + "rpm" + " " + String(speed,4)+ " m/s" + " " + String(speed * 3.6 ,4)+ " km/h";
count = 0;
debutPeriode = millis();
Serial.println(datamessage);
}
}
void timeSinceFallingEdge() {
check = micros();
if (check - oldtime > 200){
count += 1;
oldtime = check;
}
}