• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
czujnik odbiciowy TCRT5000 miernik obrotów sie nie zeruje
#1
Witam

Chciałbym zrobić miernik obrotów na podstawie czujnika odbiciowego TCRT5000.
Działam na podstawie przykładu:
Kod:
const int dataIN = 7; //IR sensor INPUT

unsigned long prevmillis; // To store time
unsigned long duration; // To store time difference
unsigned long refresh; // To store time for refresh of reading

int rpm; // RPM value

boolean currentstate; // Current state of IR input scan
boolean prevstate; // State of IR sensor in previous scan

void setup()
{
 pinMode(dataIN,INPUT);      
 prevmillis = 0;
 prevstate = LOW;  
 Serial.begin(9600);
}

void loop()
{
// RPM Measurement
 currentstate = digitalRead(dataIN); // Read IR sensor state
if( prevstate != currentstate) // If there is change in input
  {
    if( currentstate == HIGH ) // If input only changes from LOW to HIGH
      {
        duration = ( micros() - prevmillis ); // Time difference between revolution in microsecond
        rpm = (60000000/duration); // rpm = (1/ time millis)*1000*1000*60;
        prevmillis = micros(); // store time for nect revolution calculation
      }
     
  }
 
 prevstate = currentstate; // store this scan (prev scan) data for next scan
 
 // LCD Display
 if( ( millis()-refresh ) >= 1000 )
   {  
       Serial.println(rpm);  
   }  

}
Działa ok, niestety jak odsunę obracający się przedmiot od czujnika zapamiętuje ostatnią wartość.

Jak zrobić żeby po upływie np 1s bez obracania się przedmiotu, wyświetlało 0 RPM?
 
Odpowiedź
  


Wiadomości w tym wątku
czujnik odbiciowy TCRT5000 miernik obrotów sie nie zeruje - przez jack1987 - 23-07-2018, 16:51

Skocz do:


Przeglądający: 1 gości