# Problem in Number counting in LCD

Hello Friends,

I am working with Arduino Uno. I am writing codes for counter with push buttons. I am using 16X2 lcd. In ascending order, whenever it writes greater than 10, it shows ," B= 10. (B is a variable). but when I run for descending order it counts like…

B= 10 (for 10)
B= 19 (for 09)
B= 18 (for 08) and so on.

The problem is, it shows some parts of previous values. I need to remove this error
Plz help me out…

Digital_Pulse_timer_2.ino (2.15 KB)

First, learn how to post your code using the code tags with the # button above the smiley faces. More people will look at it than if they have to download a .ino file.

``````// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int Assend = 6;
const int Desend = 7;
const int Next = 8;
const int Go = 9;
const int Up = 0;
const int S = 0;
int A = 0;
int B = 0;

void setup() {

pinMode(Assend,INPUT);
pinMode(Desend,INPUT);

//*************** set up the LCD's number of columns and rows:***************************
lcd.begin(16, 2);

lcd.setCursor(3, 0);
lcd.print("RTA FURNACE");
delay(2000);
// clear screen
lcd.clear();
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
// print the number of seconds since reset:
// Set temperature in Degree Celcius
lcd.print("Set Temperature");
lcd.setCursor(0, 1);
lcd.print("Ts = ");

lcd.setCursor(6, 1);

//***************************************************

Serial.begin(9600);
}

void loop() {

lcd.setCursor(6, 1);
// For Temperature SET
if(Up == HIGH) {
Upcount();

}
else {
if(Down == HIGH) {
Downcount();
}
}

}

void Upcount() {
++B;
if(B > 9) {
lcd.setCursor(5, 1);
}

lcd.print(B);
//Serial.println(B);
delay(500);
}

void Downcount() {
--B;
if(B < 10) {

lcd.setCursor(4, 1);

}

lcd.print(B);
//Serial.println(B);
delay(500);
}
``````

You are a little off in your cursor positioning. Change the Downcount function to

``````void Downcount() {
--B;
if(B < 10) {

lcd.setCursor(5, 1);
lcd.print(" ");

}
else
lcd.setCursor (5,1);

lcd.print(B);
//Serial.println(B);
delay(500);
}
``````