Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int laserPin = 2;
- int laser =0;
- volatile byte counter = 0;
- int COUNT1=0;
- unsigned long elapsed;
- unsigned long previous;
- float velocity;
- void Countfun()
- {
- counter++;
- }
- void setup() {
- Serial.begin (9600);
- previous = millis();
- pinMode (laserPin, INPUT);
- }
- void loop() {
- attachInterrupt(0, Countfun, RISING);
- COUNT1 =COUNT1+1;
- if (COUNT1==counter){
- Serial.println (counter);
- elapsed = millis() - previous;
- previous = millis();
- //Serial.println(elapsed);
- velocity = 30*1000.0/elapsed;
- velocity = velocity /1000.*3600.;
- Serial.print(velocity);
- Serial.println(" km/h");
- }
- COUNT1=counter;
- delay(100);
- }
Add Comment
Please, Sign In to add comment