29 lines
678 B
C++
29 lines
678 B
C++
// Define the analog input pin
|
|
const int analogInputPin = A0;
|
|
|
|
// Declare the global variable to store the AFR value
|
|
float AFR;
|
|
|
|
void setup() {
|
|
// Initialize the serial communication
|
|
Serial.begin(9600);
|
|
}
|
|
|
|
void loop() {
|
|
// Read the analog input value (0-1023)
|
|
int analogValue = analogRead(analogInputPin);
|
|
|
|
// Convert the analog value to a voltage (0-5V)
|
|
float voltage = analogValue * (5.0 / 1023.0);
|
|
|
|
// Calculate the AFR value
|
|
AFR = 2 * voltage + 9.6;
|
|
|
|
// Output the AFR value to the serial monitor with one decimal place
|
|
Serial.print("AFR: ");
|
|
Serial.println(AFR, 1);
|
|
|
|
// Add a small delay to avoid spamming the serial monitor
|
|
delay(500);
|
|
}
|