Open BoldizarF opened 5 years ago
This is not a good way to read the odometers. To begin with, you will be losing many pulses. Instead you should read the odometer asynchronously using interrupts. In any case, I would very strongly suggest against using such savage ways (:laughing:) to read data from Odometers and instead use the DirectionlessOdometer from the Smartcar library. An example of how to use it can be found here.
double rps, rpm, raduisOfRcWheels = 10.0, linearSpeed ; // linearSpeed in speed in cm/secs int "everythingelse"; { val=analogRead(0);
if(val<sens) stat=LOW; else stat=HIGH; digitalWrite(13,stat);
if(stat2!=stat){ //counts when the state change, thats from (dark to light) or //from (light to dark), remmember that IR light is invisible for us. contar++; stat2=stat; } if(millis()-last>=milisegundos){ rps=((double)contar/nPalas)/2.01000.0/milisegundos; rpm=((double)contar/nPalas)/2.060000.0/(milisegundos); linearSpeed = 2 3.142 raduisOfRcWheels * rps; contar=0; last=millis(); }