Guest User

Untitled

a guest
Aug 17th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. const int laserPin = 2;
  2. int laser =0;
  3. volatile byte counter = 0;
  4. int COUNT1=0;
  5. unsigned long elapsed;
  6. unsigned long previous;
  7. float velocity;
  8.  
  9. void Countfun()
  10. {
  11. counter++;
  12.  
  13. }
  14.  
  15. void setup() {
  16.  
  17. Serial.begin (9600);
  18. previous = millis();
  19.  
  20. pinMode (laserPin, INPUT);
  21. }
  22. void loop() {
  23. attachInterrupt(0, Countfun, RISING);
  24. COUNT1 =COUNT1+1;
  25. if (COUNT1==counter){
  26. Serial.println (counter);
  27. elapsed = millis() - previous;
  28. previous = millis();
  29. //Serial.println(elapsed);
  30.  
  31. velocity = 30*1000.0/elapsed;
  32. velocity = velocity /1000.*3600.;
  33. Serial.print(velocity);
  34. Serial.println(" km/h");
  35. }
  36. COUNT1=counter;
  37.  
  38. delay(100);
  39. }
Add Comment
Please, Sign In to add comment