Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float start, finished;
- float elapsed, time;
- float circMetric=2.093;
- float circImperial;
- float speedk, speedm;
- void setup()
- {
- circImperial=circMetric*.62137;
- attachInterrupt(digitalPinToInterrupt(2), speedCalc, RISING);
- start=millis();
- Serial.begin(115200);
- }
- void speedCalc()
- {
- if((millis()-start)>100) // 100 millisec debounce
- {
- elapsed=millis()-start;
- start=millis();
- speedk=(3600*circMetric)/elapsed;
- speedm=(3600*circImperial)/elapsed;
- }
- }
- void loop()
- {
- Serial.print(int(speedk));
- Serial.print(" km/h ");
- Serial.print(int(speedm));
- Serial.print(" MPH ");
- Serial.println();
- Serial.print(" ");
- Serial.print(int(elapsed));
- Serial.print(" ms/rev ");
- Serial.println();
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement