Tim,
I bought an LCD/keypad shield at TRW yesterday. This is phase II of my stepper motor project that I have been working on. I am trying to write 2 int variables to the LCD in positions 7,0 and 15,0. The variable is an int that is incremented each time a button is pressed. The numbers are displayed correctly when stepping up from position 0 to 9 and from 9 to 0. When I go to 10 or> the number is displayed correctly until stepping down from 10 to 9 which leaves the 0 and changes the 1 to a 9 for a display of 90. This pattern is repeated all the way down to 0 which displays 00. (80, 70, 60...) I tried to print a " " (double space) before printing the variable to try to clear the display but I got strange behavior. ie printed a second variable next to the cursor position called. Didn't understand that at all.
code here:
#include <LiquidCrystal.h>
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
int upbutton = A3;
int dwnbutton = A5;
int upbuttonState = 0;
int dwnbuttonState = 0;
int count = 0;
void setup()
{
pinMode(upbutton, INPUT); //assign upbutton to an input
pinMode(dwnbutton, INPUT); //assign dwnbutton to an input
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Front=");
lcd.setCursor(9,0);
lcd.print("Rear=");
lcd.setCursor(0,1);
lcd.print("1_");
lcd.setCursor(6,1);
lcd.print("2_");
lcd.setCursor(12,1);
lcd.print("3_");
}
void loop()
{
upbuttonState = digitalRead(upbutton);
delay(50);
if (upbuttonState ==HIGH) {
++count;
lcd.setCursor(6,0);
lcd.print(count);
}
else {
lcd.setCursor(6,0);
lcd.print (count);
}
dwnbuttonState = digitalRead(dwnbutton);
delay(50);
if (dwnbuttonState ==HIGH) {
--count;
lcd.setCursor(6,0);
lcd.print (count);
}
else {
lcd.setCursor(6,0);
lcd.print (count);
}
// your main loop code here...
}
---The above is only for the variable displayed after the characters "Front="
I need a way of either creating a leading null character for the single digit numbers or some other way to account for the missing character when decrementing from a 2 digit to a 1 digit variable.
Hope you can help. I am new to mcu's and feel totally lost.
Dave E.