The LCD seems to glitch on the word "station" (see accompanying code & pic). If I try to step through the word letter-by-letter, I get to "ation" and things get screwy. Is there something about my code causing this or is it something else?
These new toys sure take a lot of time off my hands...
#include <LiquidCrystal.h>
/*
The circuit:
* pushbutton attached to pins 6,7,8 from +5V with pullup resistors (10k) & GND
* LCD attached to digital pins 12(reset), 11(enable), 5(DB4), 4(DB5), 3(DB6), 2(DB7), +5V & GND
* LCD read/write pin to GND
* LCD pin for brightness to 1k pot
* LCD pin for backlight(+) to 1k pot wired to +5V
* LCD pin for backlight(-) to GND
created 22 Dec 2009
by Will Rogers
cribbed from http://arduino.cc/en/Tutorial/ButtonStateChange & /./LiquidCrystal
*/
// Constants won't change:
LiquidCrystal lcd (12,11,5,4,3,2);
const int terminalPin = 6; // the pin that the pushbutton is attached to
const int tenPin = 7;
const int onePin = 8;
const int numRows = 2;
const int numCols = 16;
// Variables will change:
char terminalPush [] = {'A', 'B', 'C', 'D'}; //list of available terminal posts
int terminalPushCounter = 4; // counter for the number of button presses
int terminalState = 0; // current state of the button
int lastTerminalState = 0; // previous state of the button
int tenPush = 0;
int tenPushCounter = 9;
int tenState = 0;
int lastTenState = 0;
int onePush = 0;
int onePushCounter = 9;
int oneState = 0;
int lastOneState = 0;
void setup() {
// initialize the button pins as inputs
pinMode(terminalPin, INPUT);
pinMode (tenPin, INPUT);
pinMode (onePin, INPUT);
// initialize serial communication for troubleshooting
Serial.begin(9600);
//initialize lcd
lcd.begin (numRows, numCols);
}
void loop() {
// read the pushbutton input pins
terminalState = digitalRead(terminalPin);
tenState = digitalRead(tenPin);
oneState = digitalRead(onePin);
delay (50);
// compare the buttonStates to their previous state
if (terminalState != lastTerminalState) {
// if the state has changed, increment the counter
if (terminalState == HIGH) {
delay (10);
if (terminalPushCounter < 4) {
terminalPushCounter++;
}
else {
terminalPushCounter = 0;
}
Serial.println(terminalPush);
}
else {
}
lastTerminalState = terminalState;
}
if (tenState != lastTenState) {
if (tenState == HIGH) {
delay (10);
if (tenPushCounter < 9) {
tenPushCounter++;
}
else {
tenPushCounter = 0;
}
Serial.println(tenPushCounter);
}
else {
}
lastTenState = tenState;
}
if (oneState != lastOneState) {
if (oneState == HIGH) {
delay (10);
if (onePushCounter < 9) {
onePushCounter++;
}
else {
onePushCounter = 0;
}
Serial.println(onePushCounter);
}
else {
}
lastOneState = oneState;
}
lcd.setCursor (0,0);
lcd.print ("TERMINAL");
lcd.setCursor (14,0);
lcd.print (terminalPush [terminalPushCounter]);
delay (50);
lcd.setCursor (0,1);
lcd.print ("STATION");
delay (100);
lcd.setCursor (14,1);
lcd.print (tenPushCounter);
delay (50);
lcd.setCursor (15,1);
lcd.print (onePushCounter);
delay (50);
}