hello
#define NUMCHARS 253
const char string_0[] PROGMEM = "HELLO"; // "HELLO" etc are strings to store no more than 252 characters long - change to suit.
const char string_1[] PROGMEM = "This space available for advertising";
const char string_2[] PROGMEM = "Single male seeks single female (30 -40) for LTR";
const char string_3[] PROGMEM = "Don't stay a stranger my Lady! xxxxxxxxxx@yahoo.com";
const char string_4[] PROGMEM = "Bye Bye";
const char string_5[] PROGMEM = "Hi!";
const char string_6[] PROGMEM = "Thank You ";
const char string_7[] PROGMEM = "What do you think of my message board? xxxxxxxxxxx@yahoo.com ";
const char string_8[] PROGMEM = "Did you base your career choice on Star Trek? ";
const char string_9[] PROGMEM = "Are you a fan of Dr. Who, Stargate SG-1, Stargate Alantis, Bybalon 5 ";
const char string_10[] PROGMEM = "Dr. Who, Stargate SG-1, Stargate Alantis, Bybalon 5 ";
const char string_11[] PROGMEM = " ";
const char string_12[] PROGMEM = " Right turn ";
const char string_13[] PROGMEM = " left turn ";
const char string_14[] PROGMEM = " heavy traffic ";
const char string_15[] PROGMEM = " slip N slide ";
const char string_16[] PROGMEM = " Please back off you're making me nervous ";
const char string_17[] PROGMEM = " honk if you are single :) ";
// Then set up a table to refer to your strings.
const char * const string_table[] PROGMEM = {string_0, string_1, string_2, string_3, string_4, string_5,
string_6, string_7, string_8, string_9, string_10, string_11};
char Message[NUMCHARS] = "Hello world! how are you? ";
char phrase[NUMCHARS-210];
int messlen = 0; // lenght of message
boolean multiflag; // preset message flag
boolean MessageAvailable = false; // displayable message
boolean pad_Spaces ; // fill in rest with empty spaces
boolean newMess = true;
boolean ProcCmd = false;
boolean InProc = false;
char ch; // character recieved
byte rstime = 10; // recycle time
byte scrolltime = 5; // scroll speed
byte color = 0; // select one of 6 colors
unsigned int i = 0; // misc counter 0 - 64000
byte j = 0; // misc count 0 - 255
uint8_t* p = Message; // pointer to message to be displayed
void setup()
{
// serial setup
Serial.begin(9600);
}
void loop()
{
while (ProcCmd == false)
{
while(multiflag == true) // multi pretored phrases
{
p = phrase;
Serial.println(phrase);
delay(500);
while( *p != '/0')
{
buildmess(); // build message that char points too
display1(); // display message
p++; // move to next selection
// cmdck();
delay(rstime *100); // recycle time
cmdck();
}
}
if(ProcCmd == false && multiflag == false)
{
display1(); // display message
delay(rstime * 100); // resttime in milliseconds 1000 = 1 sec
cmdck();
}
}
ProCmd1();
ProcCmd = false;
clrScrn();
}
void display1()
{
j = 0;
clrScrn1();
j= strlen(Message);
Serial.print(scrolltime);
Serial.print(" ");
for (i=0; i<=j; i++)
{
Serial.print(Message[i]);
delay(scrolltime * 10);
}
Serial.println(F(" "));
i = 0;
}
void cmdck() // check for cmd request
{
selct(8);
ch = 'Z';
if(Serial.available())
{
ch = (char)Serial.read();
Serial.println(ch);
delay(100);
if( ch == '/')
{
ProcCmd = true;
multiflag = false;
}
else
ProcCmd = false;
while(Serial.available()) Serial.read(); // clear serial input buffer
}
}
void ProCmd1() // process cmd
{
InProc = true;
while(InProc == true)
{
selct(3) ; //display menu
ch = 'Z' ;
while(Serial.available()<1){} // wait for input
ch = (char)Serial.read(); // reads first byte
while(Serial.available()) Serial.read(); // clear rest of serial input buffer
Serial.print(ch);
delay(200);
switch(ch)
{
case 'c' :
// getcolor();
break;
case 's' :
// getspeed();
break;
case 'r' :
// getreset();
break;
case 'n' :
getMess();
break;
case 'i' :
// getinten();
break;
case 'p' :
multiflag = false; // only one phrase
p = phrase; // point to phrase string
getphrase();
buildmess(); // load in prestored message
break;
case 'm' :
multiflag = true; // multiple phrases
p = phrase; // point to phrase string
getphrase(); // get string of prestored message selections
break;
case '/' :
InProc = false;
ProcCmd = false;
break;
default :
break;
} // end of switch()
} // end of while InProc == true
while(Serial.available()) Serial.read(); // clear serial input buffer
}
/*********************************************************** message getting ***************************************/
void getMess()
{
newMess = true;
selct(2); // display menu
while(Serial.available()) Serial.read(); // clear serial input buffer
i=0; // set counter to zero
while(newMess == true) // get message
{
while (Serial.available()<1){} // wait for input
i = Serial.readBytesUntil('\r' , Message , NUMCHARS-1); // function to receive new message from Serial and store in message array
Serial.read();
Message[i] = '\0'; // add null to end of string
newMess = false;
}
Serial.print(Message); //confirm message
delay(500);
ProcCmd = false; // Cmd request done
while(Serial.available()) Serial.read(); // clear serial input buffer
}
void getphrase()
{
MessageAvailable = true;
selct(11); // display menu
while(Serial.available()) Serial.read(); // clear serial input buffer
i=0; // set counter to zero
while (MessageAvailable == true) // get message
{
while (Serial.available()<1){} // wait for input
if (multiflag == false)
{
*p = (char)Serial.read();
*(++p) ='\0';
p--;
}
else
{
i = Serial.readBytesUntil('\r' ,phrase ,(NUMCHARS-125)-2); // function to receive new message from Serial and store in message array
Serial.read();
phrase[i] = '\0'; // add null to end of string
}
MessageAvailable = false;
}
Serial.print(phrase); //confirm message
delay(500);
ProcCmd = false; // Cmd request done
while(Serial.available()) Serial.read(); // clear serial input buffer
}
/***************************************************** ****************************************************************/
void buildmess()
{
switch(*p)
{
case 'a' :
j=0;
break;
case 'b' :
j=1;
break;
case 'c' :
j=2;
break;
case 'd' :
j=3;
break;
case 'e' :
j=4;
break;
case 'f' :
j=5;
break;
case 'g':
j=6;
break;
case 'h' :
j=7;
break;
case 'i' :
j=8;
break;
case 'j':
j=9;
break;
case 'k' :
j=10;
break;
case 'l' :
j=11;
break;
case 'm':
j=12;
break;
case 'n' :
j=13;
break;
case 'o' :
j=14;
break;
case 'p':
j=15;
break;
case 'q' :
j=16;
break;
case 'r' :
j=17;
break;
} // decode phrase
assemblemess(); // build phrase that j points to
}
void assemblemess() // build messzge from prestored phrase
{
if ( strlen(Message) + strlen_P(pgm_read_ptr(&string_table[j] ) ) < NUMCHARS- 1)
{
addProgStr( (const char *) pgm_read_ptr(&string_table[j] ) );
}
}
void addProgStr (const char * str)
{
if (!str)
return;
while ( Message[i++] = pgm_read_byte(str++)){}
Message[i] = '\0';
} // end of printProgStr
/************************************************** Serial screeen ***********************************************/
void clrScrn1()
{
for(j=0;j<=20;j++)
{
Serial.println(F(" "));
}
}
void clrScrn()
{
for(j=0;j<=20;j++)
{
Serial.println(F(" "));
}
}
void selct(byte s) // input screen
{
switch(s)
{
case 1 :
clrScrn();
Serial.print(F(" Diags pass? y/n: "));
break;
case 2 :
clrScrn();
Serial.println(F("\n MD_MAX72XX scrolling message"));
Serial.println(F(" enter message: "));
break;
case 3 :
clrScrn(); // main menu
Serial.println(F(" message color c"));
Serial.println(F(" scroll speed s"));
Serial.println(F(" reset time r"));
Serial.println(F(" new message n"));
Serial.println(F(" intensity i"));
Serial.println(F(" prestored phrases p"));
Serial.println(F(" multi phrases m"));
Serial.println(F(" exit /"));
Serial.println(F(" "));
Serial.print(F(" enter selection: "));
break;
case 4 :
clrScrn();
break;
case 5 :
clrScrn(); // set scroll speed
Serial.println(F(" set scroll speed (number is mulitplied by 10 = scroll delay in milliseconds) "));
Serial.print(F(" enter number 1 - 16: "));
break;
case 6 :
clrScrn(); // set reset time
Serial.println(F(" set reset time (number is multiplied by 100 = delay in milliseconds) "));
Serial.print(F(" enter time 1 - 20: "));
break;
case 7 :
clrScrn(); // choose color of text
Serial.println(F(" (r)ed "));
Serial.println(F(" (b)lue "));
Serial.println(F(" (g)reen "));
Serial.println(F(" (v)iolet "));
Serial.println(F(" (y)ellow "));
Serial.println(F(" (a)qua "));
Serial.println(F(" (/) exit "));
Serial.println(F(" "));
Serial.print(F(" select message color: "));
break;
case 8 :
clrScrn();
Serial.println(F(" enter / for Primary Cmd mode "));
// Serial.print(F(" enter ? for stored phrase mode: "));
break;
case 9 :
clrScrn();
Serial.print(F(" run Diags (y/n): "));
break;
case 10:
clrScrn(); // set intensity level
Serial.println(F(" "));
Serial.println(F(" set intensity level"));
Serial.println(F(" (1) full")); // 90
Serial.println(F(" (2) 3/4")); // 74
Serial.println(F(" (3) half")); // 45
Serial.println(F(" (4) 1/4")); // 40
Serial.println(F(" (5) Min")); // 15
Serial.println(F(" (/) exit"));
Serial.println(F(" "));
Serial.print(F(" enter number: "));
break;
case 11 :
clrScrn();
Serial.println(F(" a. Hello"));
Serial.println(F(" b. This space available for advertising"));
Serial.println(F(" c. Single male seeks single female"));
Serial.println(F(" (30 -40) for LTR \n"));
Serial.println(F(" d. Don't stay a stranger my Lady!"));
Serial.println(F(" xxxxxxxx@yahoo.com \n"));
Serial.println(F(" e. Bye Bye"));
Serial.println(F(" f. Hi!"));
Serial.println(F(" g. Thank You"));
Serial.println(F(" h. What do you think of my message "));
Serial.println(F(" board? xxxxxxxxx@yahoo.com /n"));
Serial.println(F(" i. Did you base your career choice based on Star TRek ?"));
Serial.println(F(" j. Are you a fan of "));
Serial.println(F(" Dr. Who, Stargate SG-1, Stargate Alantis, Bybalon 5 /n"));
Serial.println(F(" k. Dr. Who, Stargate SG-1, Stargate Alantis, Bybalon 5 "));
Serial.println(F(" "));
Serial.println(F(" select letter(s) of message(s) to display"));
Serial.print(F(" multi selections will be displayed sequentially: "));
break;
default : break;
}
j = 0; // set counter to 0
}
/*************************************************************************************************/
first you can load the program in as is and upload to an Arduino Uno type and open serial monitor. You will be able to display the default message over and over or type in the '/' character in the serial monitor and get to the menu screen. The options that are actually available are input new message 'n' or pick a single phrase 'p' or pick multiple phrases 'm'.
When you pick one of theses options you will end up back at the menu after you make your selection.
'n' enter your new message of less than 253 characters
'p' pick a phrase by typing in letter beside phrase
'm' type in up to five letters of the phrases you want to display
in the order you wish to display them
when you get back to the menu enter '/' character then the main program will run until you want to do something different by entering '/' character.
Now everything works according to plan except the 'm' option.
With that option the main runs once thru the selections and then gets stuck at the first entry in the selections just displays that one over and over until I intervene with the '/' character. What is suppose to happen is while in multi phrase mode the sequence of phrases should be displayed one after another continuously until intervened with a '/' character.
I'm scratching my head now trying to get this option to work.
Anybody got any ideas here???
This program is a stand alone one here. the ultimate project is a scrolling message board that is controlled by phone. That is the reason for weird print
statements here.