int interrupt = 2;
volatile unsigned int teller, teller_copy;
volatile unsigned long current_micros;
volatile unsigned long old_micros;
volatile unsigned long current_millis;
volatile unsigned long old_millis;
volatile bool state;
unsigned long time1;
unsigned long rpm;
unsigned long frequentie;
float periode;
void setup() {
analogWrite(3, 225);
pinMode(interrupt, INPUT);
attachInterrupt(digitalPinToInterrupt(interrupt), toerental, FALLING);
Serial.begin(115200);
}
void loop() {
current_millis = millis();
if (current_millis - old_millis >= 1000) {
cli(); //stop interrupts
teller_copy = teller;
teller = 0;
sei(); //allow interrupts
frequentie = teller_copy / 2;
rpm = frequentie * 60ul;
Serial.print(teller_copy);
Serial.print(" ");
Serial.print(frequentie);
Serial.print(" ");
Serial.println(rpm);
old_millis = current_millis;
}
}
void toerental() {
if (micros() - old_micros > 500) {
old_micros = micros();
teller++;
}
}←Falling Bounce
←Clean Falling Signal