I am trying to display a Name to an Lcd display, made up of an array of character letters to make the name.
Button 1= increments a letter in the character array.
Button2 = selects the array letter and moves the cursor forward into the next position for the next letter to make up a name, and puts it into a new word array.
Button 3 = Saves the new Name to the new word array.
here is my problem!
Button 4 = moves the cursor backward in order to edit any of the selected letters.
it does this, but it also deletes the letters in the Name when changing positions.
What I want it to do is to move the cursor backward to the position that needs the selected letter changed so I can edit the letter without changing the rest of the Name.
Any help would be great.
#include <LiquidCrystal.h>
// Button assignment and definitions
const int button[] = { 11, 12, 2, 3, A1, A0, A2 };
const int numButtons = sizeof(button) / sizeof(button[0]);
enum { B_SEL, B_INC, B_DEC, B_SAVE, B_READ, B_ENTER, R_back };
int lastButtonState[numButtons];
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const char* Editchars = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890,.!?&@#$%^*_-+=(){}[]<>|\\/'\"~";
char prgn[] = " progr";
int selectIdx = 0;
int columnIdx = 0;
int wordIdx = 0;
int Sync = 0;
int wordct = 0;
void setup()
{
lcd.begin(16, 2);
//lcd.print (output);
Serial.begin(9600);
for ( int i = 0; i < numButtons; ++i ) {
pinMode (button[i], INPUT_PULLUP);
}
}
void loop()
{
int buttonState;
//*******************Savetoarray,and move cursor***************
buttonState = digitalRead(button[B_INC]);
// compare the buttonState to its previous state
if (buttonState != lastButtonState[B_INC]) {
if (buttonState == LOW) {
wordIdx++;
prgn[wordIdx] = Editchars[selectIdx];
columnIdx++;
lcd.setCursor(columnIdx + 7, 0);
lcd.cursor();
Serial.println("scroll");
Serial.println(prgn);
selectIdx = 0;
if (columnIdx > 5) columnIdx = 0;
}
}
lastButtonState[B_INC] = buttonState;
//************** Char select***************************
if (digitalRead(button[B_SEL]) == LOW) {
selectIdx++;
lcd.setCursor(columnIdx + 7, 0);
lcd.print(Editchars[selectIdx]);
lcd.setCursor(columnIdx + 7, 0);
lcd.cursor();
delay(50);
}
// *****************Increment character back*************************************
buttonState = digitalRead(button[B_DEC]);
if (buttonState != lastButtonState[B_DEC]) {
if (buttonState == LOW) {
selectIdx--;
if (selectIdx < 1) selectIdx = 1;
//lcd.cursor();
lcd.setCursor(columnIdx + 7, 0);
lcd.print(Editchars[selectIdx]);
}
}
lastButtonState[B_DEC] = buttonState;
//************************************
buttonState = digitalRead(button[B_SAVE]);
// compare the buttonState to its previous state
if (buttonState != lastButtonState[B_SAVE]) {
if (buttonState == LOW) {
// selectIdx--;
wordIdx--;
columnIdx--;
lcd.setCursor(columnIdx + 7 , 0);
lcd.cursor();
Serial.println("scroll");
Serial.println(prgn);
selectIdx = 0;
if (columnIdx < 1) columnIdx = 0;
}
}
lastButtonState[B_SAVE] = buttonState;
//************************reading from
buttonState = digitalRead(button[R_back]);
if (buttonState != lastButtonState[R_back]) {
if (buttonState == LOW) {
prgn[wordIdx + 1] = '\0';
Serial.print(prgn);
}
}
lastButtonState[R_back] = buttonState;
}