Hi, shopefully I did the code tags right this time. I have a 16x2 display on an UNO. Ive started making an AFR display. So far it is starting to work, but I have two problems:
1- I am having trouble getting it to refres or “read realtime”. when I start it, it shows the current voltage but does not change with the pot. Ive tried writing the code to write blank spaced between readings, and have tried spacing in the " ". Im sure its just me lack of knowledge as I am very new at this.
2- Regardless of where I set the cursor at, the AFR reading always starts at block #2 on line 1. Any help would be greatly appreciated.
#include <LiquidCrystal.h>
//LiquidCrystal lcd (8,9,4,5,6,7);
// const byte backLED = 3;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int lastAfr = 0;
int currentAfr = 0;
void setup() {
Serial.begin(9600);
pinMode(A1, INPUT); // Set pin A8 as input for boost input
pinMode(7, OUTPUT); // Red LED
pinMode(8, OUTPUT); // Green LED
//digitalWrite(backLED, LOW);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("AFR module loading");
delay(100);
lcd.clear();
delay(500);
}
void loop() {
float afrValue = analogRead(A1); //Read input from LC1 Wideband voltage
//float afroutput = (afrValue-0)*(20-10)/(1023-0);
float afroutput = (afrValue-0) * (20-10) / (1023-0)+7;
lcd.setCursor(1,4);
lcd.print(afroutput);
delay(100);
lcd.setCursor(1,4);
lcd.print(" ");
delay(100);
lcd.setCursor(1,4);
lcd.print(afroutput);
// lcd.print("AFR ");
if (afroutput < 11) {
digitalWrite(8, HIGH); // Red LED for warmup
lcd.setCursor(0,0);
lcd.print("02 Sensor warmup");
}
else {
digitalWrite(8, LOW);
}
while(float(afroutput)) {
digitalWrite(7, HIGH);
delay(5);
digitalWrite(7, LOW);
if (afroutput > 14.7){
lcd.setCursor(0,0);
lcd.print("**Warning Lean**");
delay(100);
lcd.setCursor(0,0);
lcd.print(" ");
delay(100);
lcd.setCursor(0,0);
lcd.print("**Warning Lean**");
delay(5);
}
}
}