Refreshing LCD

Hi,

I have an LCD that I am using to display the percentage of two different rotary potentiometers and also the difference between the two potentiometers. (for some background info, 1 pot is being used as an input to a linear actuator and the other is the output of the internal pot in the potentiometer)

I have the screen working pretty much as I want it to but I am having the problem that as the value of the pot decreases from 99% to 0% the remaining percentage signs are remaining on the screen. i.e. if I went from 99% to 0% then the screen would actually go from 99% to 0%%.

Is there a way that I can refresh the screen or get rid of the additional percentage signs?

My sketch is below but it has a few other parts in it that’s aren’t related to this problem so I’m sorry if that is confusing:

#include<LiquidCrystal.h>;
void LCD_And_Display ();
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

int Pot_In = A1;
int Pot_Motor = A0;

const int RedLED = 7;
const int GreenLED = 8;

const int Motor_PWM = 6;
const int Arm_In = 9;
const int Arm_Out = 10;
const int Clutch = 13;

const int Calibration_Time = 5000;
const int Accuracy = 5;

const int High_Pass_Filter = 15;

boolean Out_Fast = false;
boolean Out_Slow = false;
boolean In_Fast = false;
boolean In_Slow = false;

boolean LCD_Print = false;

long Previous_Millis = 0;
long Interval = 300;

void setup() {
// put your setup code here, to run once:
pinMode(Pot_In, INPUT);
pinMode(Pot_Motor, INPUT);
pinMode(Motor_PWM, OUTPUT);
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
pinMode(Arm_In, OUTPUT);
pinMode(Arm_Out, OUTPUT);
pinMode(Clutch, OUTPUT);

digitalWrite(Motor_PWM, LOW);
digitalWrite(RedLED, LOW);
digitalWrite(GreenLED, LOW);
digitalWrite(Arm_In, LOW);
digitalWrite(Arm_Out, LOW);
digitalWrite(Clutch, HIGH);

lcd.begin(16, 2);
lcd.print(“Goal=”);
lcd.setCursor(0, 1);
lcd.print(“Valve=”);
lcd.setCursor(10,0);
lcd.print(“Dif”);

}

void loop() {

int sensorValueIn = analogRead(Pot_In);
float PercentageIn = sensorValueIn * (100. / 1023.);
round (PercentageIn);
int PercentageInRound = PercentageIn;

int sensorValueAct = analogRead(Pot_Motor);
float PercentageAct = sensorValueAct * (100. / 1023.);
round (PercentageAct);
int PercentageActRound = PercentageAct;

if (PercentageActRound == PercentageInRound)
{
digitalWrite(Arm_In, LOW);
digitalWrite(Arm_Out, LOW);
digitalWrite(Clutch, HIGH);
}

if (PercentageActRound > PercentageInRound)
{
analogWrite(Motor_PWM, 255);
digitalWrite(Arm_In, HIGH);
digitalWrite(Arm_Out, LOW);
digitalWrite(Clutch, HIGH);
}

if (PercentageActRound < PercentageInRound)
{
analogWrite(Motor_PWM, 255);
digitalWrite(Arm_In, LOW);
digitalWrite(Arm_Out, HIGH);
digitalWrite(Clutch, HIGH);
}

void LCD_And_Display ();
unsigned long Current_Millis = millis();

if (Current_Millis - Previous_Millis > Interval) {
// save the last time you blinked the LED
Previous_Millis = Current_Millis;

lcd.setCursor(6, 0);
lcd.print(PercentageInRound);
lcd.print("%");

lcd.setCursor(7, 1);
lcd.print(PercentageActRound);
lcd.print("%");

lcd.setCursor(13,0);
lcd.print(abs(PercentageActRound - PercentageInRound));
lcd.print("%");

if (((abs(PercentageActRound - PercentageInRound) > Accuracy))) //Rule to say if values are out of Precision to flash red LED or if in tolerance to turn on GreenLED
{
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, HIGH);

}
else {
digitalWrite(RedLED, LOW);
digitalWrite(GreenLED, HIGH);
}
}
else
{
}
}

(deleted)

Thanks for your help Spycatcher2K. That has resolved my problem :slight_smile: