#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int ledPin = 2;
int warningled = 9;
int gau1 = 0;
int gau2 = 1;
int gau3 = A3;
int gau4 = A4;
const float BETA = 3950;
// define the switch pins
int switch1 = 7;
int switch2 = 8;
int switch3 = 12;
int switch4 = 13;
int switch5 = 4;
int irPin = 11;
IRrecv irrecv(irPin);
decode_results results;
// define the delay time for each mode
int delayTime1 = 600;
int delayTime2 = 250;
int delayTime3 = 100;
int delayTime4 = 75;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
// set the LED pin as an output
pinMode(ledPin, OUTPUT);
irrecv.enableIRIn();
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
pinMode(switch4, INPUT_PULLUP);
pinMode(switch5, INPUT_PULLUP);
pinMode(warningled, OUTPUT);
pinMode(gau1, OUTPUT);
}
void loop() {
// check the state of each switch
int mode1 = digitalRead(switch1);
int mode2 = digitalRead(switch2);
int mode3 = digitalRead(switch3);
int mode4 = digitalRead(switch4);
int mode5 = digitalRead(switch5);
// blink the LED according to the mode
if (mode1 == LOW) {
lcd.setCursor(0,0);
lcd.print("Idle Rumbble ");
lcd.setCursor(0,1);
lcd.println("Mode: 1 500 m/s");
analogWrite(gau1, HIGH);
digitalWrite(ledPin, HIGH);
delay(delayTime1);
digitalWrite(ledPin, LOW);
delay(delayTime1);
Serial.println("Idle Rumble 500 m/s");
} else if (mode2 == LOW) {
lcd.setCursor(0,0);
lcd.print("Idle Rumbble ");
lcd.setCursor(0,1);
lcd.println("Mode: 2 250 m/s");
digitalWrite(ledPin, HIGH);
delay(delayTime2);
digitalWrite(ledPin, LOW);
delay(delayTime2);
Serial.println("Idle Rumble 250 m/s");
} else if (mode3 == LOW) {
lcd.setCursor(0,0);
lcd.print("Idle Rumbble ");
lcd.setCursor(0,1);
lcd.println("Mode: 3 100 m/s");
digitalWrite(ledPin, HIGH);
delay(delayTime3);
digitalWrite(ledPin, LOW);
delay(delayTime3);
Serial.println("Idle Rumble 100 m/s");
} else if (mode4 == LOW) {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
lcd.setCursor(0,0);
lcd.print("RapidBackfire ");
lcd.setCursor(0,1);
lcd.println(celsius);
lcd.println("C Temp");
digitalWrite(ledPin, HIGH);
delay(delayTime4);
digitalWrite(ledPin, LOW);
delay(delayTime4);
Serial.println("Rapid Backfire 75 m/s");
Serial.print("Temperature: ");
Serial.println(" ℃");
}
else if (mode5 == LOW) {
lcd.setCursor(0,0);
lcd.print("Please Standby ");
lcd.setCursor(0,1);
lcd.println("ConnectBluetooth");
Serial.println("Turn ON Please");
digitalWrite(warningled, HIGH);
delay(250);
digitalWrite(warningled, LOW);
delay(500);
}
else if (mode1,mode2,mode3,mode4,mode5 == HIGH) {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
lcd.setCursor(0,0);
lcd.print("ENGINE TEMP ");
lcd.setCursor(0,1);
lcd.print(celsius);
lcd.println(" WARN!");
delay(500);
Serial.println("select Switch");
}
}