Foufou
3
volatile int impulse=0;
int drehzahl;
unsigned long detektzeit =0;
volatile unsigned long beginnzeit;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
attachInterrupt(0,impulsez,RISING); //reagiere auf steigende Flanken auf PIN 2
}
void loop() {
beginnzeit=millis();
if (beginnzeit-detektzeit>=1000){
drehzahl=(impulse*60);
Serial.print("Drehzahl ="); //print the word "RPM" and tab.
Serial.print(drehzahl); // print the rpm value.
Serial.print("\t Hz=");
Serial.println(impulse);
impulse=0;
detektzeit=beginnzeit;
}
}
void impulsez(){
impulse++;
}