Hi All, I have a sketch with 5 buttons to control and lcd, the first button on a push increments through an array of characters abc ect and displays them on the lcd. the next button on a press saves the selected increment in an array and moves the cursor into the next position ready to select the next character untill a word is formed and saved into the array on the lcd . the next button on a push, saves the array to a desiginated eeprom address. i have another button that reads the eeprom address and the array saved at that address the next press of the button moves to the next eeprom address and displays it to the lcd. I have tried to put another button called enter and on a press clears the current selected array ready for it to be rewritten.
What i cant figure out is how to reset and change the char array so a new word can be edited so it can be saved to the next selected eeprom address.
#include <LiquidCrystal.h>
#include <EEPROM.h>
byte f;
int eeAddress = 0;
const int button3 = 2;
const int button1 = 11;
const int button2 = 12;
const int button4 = 3;
const int readbut = A1;
int enterbut = A0;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int counter = 0;
int sizeofprgn = 6;
int pos = 0;
int cpos1 = 0;
int cpos2 = 0;
int buttonState = 0;
int lastButtonState = 0;
int t =0;
int j=0;
int z;
int i =0;
boolean edit;
byte prgsize = 7;
byte EEPROMStartAdress = 0;
byte EEPROMAdress = 0;
int minusstate;
int lastminusstate = HIGH;
int lastenter;
byte memsave;
//int eeAddress = 0;
int butt = 5;
char prgn[] = " ram ";
//char rebuilt[] = " @sG7ujn >:e[|zwwqFRET"; // initial garbage
//char output[] = {'a','l','c','d','e','f','\0'};
const char* Editchars = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890,.!?&@#$%^*_-+=(){}[]<>|\\/'\"~";
void setup()
{
lcd.begin(16,2);
//lcd.print (output);
Serial.begin(9600);
//Setup some buttons
pinMode (button1, INPUT);
pinMode (button2, INPUT);
pinMode (button3, INPUT);
pinMode (button4, INPUT);
pinMode (readbut, INPUT);
pinMode (enterbut, INPUT);
//Turn the internal resistors on so the thing does go kaput
digitalWrite(button1, HIGH);
digitalWrite(button2, HIGH);
digitalWrite(button3, HIGH);
digitalWrite(button4, HIGH);
digitalWrite(readbut, HIGH);
digitalWrite(enterbut, HIGH);
}
void loop()
{
//*******************Savetoarray,and move cursor***************
buttonState = digitalRead(button2);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == LOW) {
// if the current state is HIGH then the button
// wend from off to on: for
i++;
prgn[i] = Editchars[t];
prgn[i +1] = '\0';
j++;
lcd.cursor();
lcd.setCursor(j+7,cpos2);
Serial.println("scroll");
Serial.println(prgn);
if (j >5)j=0;
t=0;
}
}
lastButtonState = buttonState;
//************** Char select***************************
if(digitalRead(button1)==LOW){
t++;
lcd.setCursor(j+7,cpos1);
lcd.print(Editchars[t]);
delay(50);
}
// *****************Increment character back*************************************
int minbut = digitalRead(button3);
if(minbut!=lastminusstate){
if(minbut == LOW) {
t--;
if(t<1) t=1;
lcd.setCursor(j+7,cpos1);
lcd.print(Editchars[t]);
}
}
lastminusstate = minbut;
//***************saving to memory*********************
if(digitalRead(button4)==LOW){
lcd.cursor();
lcd.setCursor(j+7,cpos1);
Serial.print(prgn);
Serial.print(" put");
EEPROMStartAdress=EEPROMStartAdress+1;
memsave = EEPROMStartAdress * prgsize;
EEPROM.put(memsave, prgn);
if(EEPROMStartAdress > 5) EEPROMStartAdress = 0;
Serial.print(memsave );
Serial.println("\t");
lcd.clear();
j =0;
t=0;
i=0;
lcd.setCursor (j+7,cpos2);
lcd.print(Editchars[t]);
lcd.print("Save");
delay(100);
lcd.clear();
lcd.setCursor (j+7,cpos1);
}
//************************reading from memory************
if(digitalRead(readbut)==LOW){
EEPROMAdress=EEPROMAdress+1;
byte memcall = EEPROMAdress * prgsize;
EEPROM.get(memcall, prgn);
if(EEPROMAdress > 5) EEPROMAdress = 0;
Serial.println(" ");
Serial.print(" get ");
Serial.print( memcall );
Serial.print(prgn);
lcd.clear();
delay(100);
lcd.setCursor (j+7,cpos2);
lcd.print(prgn);
}
//**********************entermode**********************
int enter = digitalRead(enterbut);
// compare the buttonState to its previous state
if (enter != lastenter) {
// if the state has changed, increment the counter
if (enter == LOW) {
// if the current state is HIGH then the button
// wend from off to on: for
// for(i=0; i<sizeofprgn;i++){
// prgn[i] = Editchars[i];
memset(prgn, 0, sizeof prgn);
// prgn[i] = 0;
//}
Serial.print("Enter");
Serial.print(prgn);
}
}
lastenter = enter;
}