#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int sensorPinRPM = 2; // Dây kÃch kết ná»i vá»i chân sá» 2 cá»§a Arduino
volatile int rpmCount = 0;
unsigned int rpm = 0;
unsigned long previousMillis = 0;
const int sensorPinAFR= A1;
float AFRValue= 0.0;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Äá»a chá» I2C cá»§a LCD
void setup() {
attachInterrupt(digitalPinToInterrupt(sensorPinRPM), countRPM, FALLING);
lcd.begin(16, 2);
lcd.backlight();
lcd.setCursor(5,0);
lcd.print("Hello!");
delay(2500);
lcd.clear();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 1000) {
rpm = 60 * rpmCount / 2; // 2 là sá» lưỡi quạt hoặc từ tÃnh cá»§a Äá»ng cÆ¡
lcd.setCursor(0, 0);
lcd.print("RPM: ");
lcd.print(rpm);
rpmCount = 0;
previousMillis = currentMillis;
}
// Äo AFR
int sensorValueAFR = analogRead(sensorPinAFR);
AFRValue = map(sensorValueAFR, 0, 1023, 10, 20); // Chuyá»n giá trá» analog sang phạm vi AFR
// Hiá»n thá» lên LCD
lcd.setCursor(0, 1);
lcd.print("AFR: ");
lcd.print(AFRValue, 1); // Hiá»n thá» giá trá» AFR vá»i má»t sá» tháºp phân
delay(1000);
// Äá»c giá trá» AFR má»i giây
}
void countRPM() {
rpmCount++;
}