#include <LiquidCrystal.h>
int val = 0;
int Deg = 0;
int lastDeg = -1; // Store the previous degree value
int Demand = 0;
int lastDemand = -1; // Store the previous demand (if it ever changes)
int analogPin = A0;
LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
void setup() {
lcd_1.begin(16, 2);
lcd_1.setCursor(0, 0);
lcd_1.print("Cur.Dir: Demand:");
}
void loop() {
val = analogRead(analogPin);
Deg = (360.0 / 1023) * val;
// Update display only if the value has changed
if (Deg != lastDeg || Demand != lastDemand) {
lcd_1.setCursor(0, 1);
lcd_1.print(" "); // Clear the second line
lcd_1.setCursor(0, 1);
lcd_1.print(Deg);
lcd_1.print(" Deg ");
lcd_1.print(Demand);
lcd_1.print(" Deg");
// Store the current values
lastDeg = Deg;
lastDemand = Demand;
}
delay(100); // Shorter delay for more responsiveness
}