#include <LiquidCrystal_I2C.h>
// Instantiate the counts
LiquidCrystal_I2C lcd(0x27, 16, 2); // 3F the address of the LCD
#define rpmInput1 2
#define rpmInput2 3
#define rpmInput3 18
/* REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE */
int switchPin1 = 11; // choose the input pin (for a pushbutton)
int switchPin2 = 12; // choose the input pin (for a pushbutton)
int switchPin3 = 13; // choose the input pin (for a pushbutton)
/* REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE */
int rpm1 = 0;
int rpm2 = 0;
int rpm3 = 0;
double pulsesPerRev1 = 1.0;
double pulsesPerRev2 = 2.0;
double pulsesPerRev3 = 3.0;
unsigned long millisBefore;
volatile int counts1;
volatile int counts2;
volatile int counts3;
void setup(){
Serial.begin(57600);
Serial.println("Welcome to the Serial Monitor!");
Serial.println("---------------------------------");
attachInterrupt(digitalPinToInterrupt(rpmInput1), count1, FALLING);
delay(1000);
attachInterrupt(digitalPinToInterrupt(rpmInput2), count2, FALLING);
delay(1000);
attachInterrupt(digitalPinToInterrupt(rpmInput3), count3, FALLING);
delay(1000);
/* REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE */
pinMode(switchPin1, INPUT); // declare as input
pinMode(switchPin2, INPUT); // declare as input
pinMode(switchPin3, INPUT); // declare as input
/* REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE */
// Initialize the display
lcd.init();
lcd.init();
lcd.backlight();
lcd.noCursor();
pinMode(rpmInput1, INPUT);
pinMode(rpmInput2, INPUT);
pinMode(rpmInput3, INPUT);
}//end setup
void loop() {
/* REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE */
analogWrite(switchPin1,110);
analogWrite(switchPin2,100);
analogWrite(switchPin3,120);
/* REMOVE REMOVE REMOVE REMOVE REMOVE REMOVE */
if (millis() - millisBefore > 1000) {
rpm1 = (counts1 / pulsesPerRev1)*60;
counts1 = 0;
rpm2 = (counts2 / pulsesPerRev2)*60;
counts2 = 0;
rpm3 = (counts3 / pulsesPerRev3)*60;
counts3 = 0;
millisBefore = millis();
}
delay(100);
lcd.setCursor(4, 0);
lcd.print("RPM 1: ");
lcd.setCursor(11, 0);
lcd.print(rpm1);
lcd.setCursor(4, 1);
lcd.print("RPM 2: ");
lcd.setCursor(11, 1);
lcd.print(rpm2);
lcd.setCursor(4, 2);
lcd.print("RPM 3: ");
lcd.setCursor(11, 2);
lcd.print(rpm3);
}
void count1() {
counts1++;
}
void count2() {
counts2++;
}
void count3() {
counts3++;
}