Hello
I am creating an Arduino sketch that scrolls the sentence "The voltage is > 2.5V" to the left on the first row of the LCD if the voltage level at pin A5 is greater than 2.5 volts. If the voltage level at pin A5 is less than 2.5 volts, the sentence "The voltage is 2.5V" will scroll to the right on the LCD's second row.
Although I am almost done I don't know what is the issue
the first loop stops if it is below 2.5 but if it above it doesn't stop
How to break the loop if I want to transition between them
// C++ code
//
#include <LiquidCrystal.h>
const int rs=8, e=9, d4=10, d5=11, d6=12, d7=13;
LiquidCrystal lcd(rs,e,d4,d5,d6,d7);
int ls; //photoresistor
float voltage;
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
ls = analogRead(A5);
voltage = ls * (5.0 / 679.0); //converting to voltage
Serial.println(voltage); //print voltage
int i=0;
if (voltage < 2.5) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The voltage is < 2.5V");
while (i < 1) {
// scroll one position right:
lcd.scrollDisplayRight();
delay(100);
if (voltage > 2.5){
break;
}
}
}
else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The voltage is > 2.5V");
while (i < 1) {
// scroll one position left:
lcd.scrollDisplayLeft();
delay(100);
if (voltage < 2.5){
break;
}
}
}
}