Hello, I am trying to take a variable that reads a word and breaks it up into individual letters.
If the variable is hello, then it would break up into h e l l o.
Or if the variable reads "Turn on motor" it would break it up into multiple variables where 1 reads "Turn" the other "on" and the other "motor".
i'm using a string function called voice
and getting variable values from a blue tooth device. Where when I speak a sentence it makes that 1 variable instead of different variables for each word in the sentence.
You can directly access the bytes of the received string array, but you can do this too:
#define MAX_SIZE 20
char
BrokenUp[MAX_SIZE];
char
*Source = "Your mother was a hamster and your father smelled of elderberries.";
void setup()
{
Serial.begin(9600);
while(!Serial);
}//setup
void loop()
{
int
i;
Serial.println(Source);
Breakup( Source, BrokenUp, MAX_SIZE-1 );
i=0;
do
{
Serial.println(BrokenUp[i++]);
}while( BrokenUp[i] );
delay(500);
}//loop
void Breakup( char *srcString, char *destArray, int maxSize )
{
int
i=0;
char
chr;
do
{
chr = *srcString;
*destArray = chr;
*destArray++;
*srcString++;
*destArray = 0x00;
i++;
}while( chr && (i < maxSize) );
}//Breakup