#include <LiquidCrystal_I2C.h>
// Instantiate the Objects
LiquidCrystal_I2C lcd(0x27, 16, 2); // 3F the address of the LCD
#define rpmInput 2
int switchPin = 11; // choose the input pin (for a pushbutton)
int rpm = 0;
//int pid;
unsigned long millisBefore;
volatile int objects;
void setup(){
Serial.begin(57600);
Serial.println("Welcome to the Serial Monitor!");
Serial.println("---------------------------------");
attachInterrupt(digitalPinToInterrupt(rpmInput), count, FALLING);
delay(1000);
pinMode(switchPin, INPUT); // declare as input
// Initialize the display
lcd.init();
lcd.init();
lcd.backlight();
lcd.noCursor();
pinMode(rpmInput, INPUT);
}//end setup
void loop() {
analogWrite(11,110);
if (millis() - millisBefore > 1000) {
rpm = (objects / 3.0)*60;
objects = 0;
millisBefore = millis();
}
delay(100);
lcd.setCursor(4, 0);
lcd.print("RPM: ");
lcd.setCursor(9, 0);
lcd.print(rpm);
}
void count() {
objects++;
}