Hi guys
I'm having problems with my project.
There are two main parts of this code:
-
While in "programming mode" the Arduino waits for someone to send a text string via Serial connection, the Arduino then saves the text string to an EEPROM Address 1, through an array.
When the next serial string arrives it gets sent to EEPROM Address 2 (also through array). -
The Arduino is then switched to the "play mode" where it shows the text strings on an LCD.
The String from Address 1 is displaying perfectly, but the second address' string is showing bunch of garbage characters.
Im stuck, please help.
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
LiquidCrystal lcd(35, 34, 33, 32, 31, 30);
int modeSelect = 4;
long timeoutOver;
char data[40];
int songcounter = 1;
int partcount = 1;
void setup()
{
pinMode(INPUT, modeSelect);
lcd.begin(40, 2);
Serial.begin(9600);
}
void loop()
{
while(digitalRead(modeSelect) == LOW)
{
PlayMode();
}
while(digitalRead(modeSelect) == HIGH)
{
ProgrammingMode();
}
}
int ProgrammingMode()
{
if(partcount == 1 && digitalRead(modeSelect) == HIGH)
{
Programming1();
}
if(partcount == 2 && digitalRead(modeSelect) == HIGH)
{
Programming2();
}
}
int Programming1()
{
boolean somethingReceived = false;
int pos = 1;
if(Serial.available())
{
somethingReceived = true;
do
{
while(Serial.available())
{
data[min(pos,40-1)] = Serial.read();
timeoutOver = millis()+10;
pos++;
}
}
while(millis()<timeoutOver);
//data[pos] = ' ';
}
if(somethingReceived)
{
int eepromcounter1 = 1;//(1 + (30 * (songcounter - 1)));
int eepromcounter2 = 40;//(30 * songcounter);
int i;
for (i = eepromcounter1; i <= eepromcounter2; i = i + 1)
{
int a=(data[i]);
EEPROM.write(i, a);
delay(2);
}
lcd.clear();
lcd.print("Programming 1 done... ");
delay(500);
partcount = 2;
}
}
int Programming2()
{
boolean somethingReceived = false;
int pos = 1;
if(Serial.available())
{
somethingReceived = true;
do
{
while(Serial.available())
{
data[min(pos,40-1)] = Serial.read();
timeoutOver = millis()+10;
pos++;
}
}
while(millis()<timeoutOver);
//data[pos] = ' ';
}
if(somethingReceived)
{
int eepromcounter1 = 41;//(331 + (30 * (songcounter - 1)));
int eepromcounter2 = 72;//((30 * songcounter) + 331);
int i;
for (i = eepromcounter1; i <= eepromcounter2; i = i + 1)
{
int a=(data[i]);
EEPROM.write(i, a);
delay(2);
}
lcd.clear();
lcd.print("Programming 2 done... ");
delay(500);
partcount = 1;
}
}
int PlayMode()
{
int eepromcounter1 = 1;//(331 + (30 * (songcounter - 1)));
int eepromcounter2 = 33;//((30 * songcounter) + 331);
int i;
char a;
lcd.clear();
lcd.print("Song: ");
lcd.setCursor(0, 1);
lcd.print("Verse: ");
lcd.setCursor(6, 0);
for (i = eepromcounter1; i <= eepromcounter2; i = i + 1)
{
a = EEPROM.read(i);
a = char(a);
lcd.print(a);
}
eepromcounter1 = 41;//(331 + (30 * (songcounter - 1)));
eepromcounter2 = 72;//((30 * songcounter) + 331);
lcd.setCursor(7, 1);
for (i = eepromcounter1; i <= eepromcounter2; i = i + 1)
{
a = EEPROM.read(i);
a = char(a);
lcd.print(a);
}
delay(600);
}