#include #include LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display. ACHTUNG: Adresse kann auch 0x3F sein !!! // Anschlüsse: // GND - GND // VCC - 5V // SDA - ANALOG Pin 4 // SCL - ANALOG pin 5 int sensor = 2; unsigned long currentTime; unsigned long lastTime; //unsigned long pulse_freq; unsigned long period; float pulse_freq; // =========================== // ======= SETUP ========= // =========================== void setup() { pinMode(sensor, INPUT); Serial.begin(9600); attachInterrupt(0, pulse, FALLING); // Setup Interrupt lcd.begin(); // initialize the lcd lcd.backlight(); lcd.setCursor(0,0); lcd.print("Drehzahl-"); lcd.setCursor(0,1); lcd.print("messer"); delay(3000); lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,1); lcd.print(" "); lastTime = micros(); } // ======================== // ======= LOOP ========= // ======================== void loop () { pulse_freq = 1000000.0 / period; lcd.setCursor(0,0); lcd.print("f = "); lcd.print(pulse_freq, 2); lcd.print(" Hz "); lcd.setCursor(0,1); lcd.print(pulse_freq * 60, 0); lcd.print(" RPM "); } // ============================= // ======= INTERRUPT ========= // ============================= void pulse () // Interrupt function { currentTime = micros(); period = currentTime - lastTime; lastTime = currentTime; }