Advertisement
Guest User

most ez valami

a guest
May 25th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. float start, finished;
  2. float elapsed, time;
  3. float circMetric=2.093;
  4. float circImperial;
  5. float speedk, speedm;    
  6.  
  7. void setup()
  8. {
  9.   circImperial=circMetric*.62137;
  10.  
  11.   attachInterrupt(digitalPinToInterrupt(2), speedCalc, RISING);
  12.   start=millis();
  13.  
  14.   Serial.begin(115200);
  15. }
  16.  
  17. void speedCalc()
  18. {
  19.   if((millis()-start)>100) // 100 millisec debounce
  20.     {
  21.     elapsed=millis()-start;
  22.  
  23.     start=millis();
  24.  
  25.     speedk=(3600*circMetric)/elapsed;
  26.  
  27.     speedm=(3600*circImperial)/elapsed;
  28.     }
  29. }
  30.  
  31. void loop()
  32. {
  33.   Serial.print(int(speedk));
  34.   Serial.print(" km/h ");
  35.   Serial.print(int(speedm));
  36.   Serial.print(" MPH ");
  37.   Serial.println();
  38.  
  39.   Serial.print("                ");
  40.   Serial.print(int(elapsed));
  41.   Serial.print(" ms/rev      ");
  42.   Serial.println();
  43. delay(100);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement