So I've read multiple tutorials, and the arduino lcd reference, but have not seen this seemingly simple problem addressed anywhere.
This is my first time using an LCD, I'm using one of the common 16x2 lcd's. I'm wanting to display angle of a servo, which is controlled by a potentiometer (right now I have the servo left out). The problem is the way it is displaying the values. Originally using lcd.print(val), when displaying something like 51 for example, it would display 51515151515151515151, anything over 2 digits would end up a garbled mess.
I tried almost every type of code from the arduino reference, and found that adding lcd.home(), did help a little, but not completely. Once I get up to a triple digit number, the 3rd digit never goes away, so something like 150 would be correct, but 67 becomes 670, 1 becomes 100, etc.
How can I get this value to display correctly? Here is the code I'm using.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179);
lcd.home();
lcd.print(val);
}