Coding Problem probably an endless loop (Morse Code converter using arrays)
im working on morse code converter using arrays school project. cant seem coding right may stuck on endless loop cant seem fix it. please help.
im using mega2560
im using mega2560
code: [select]
string morse=" abcdefghijklmnopqrstuvwxyz";
string morsecode[]={",", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
string words[] = "sos";
#define ledpin 10
#define dotl 200
const int dashl = dotl * 3, inletpause = dotl, spacel = dotl * 3, wordpausel = dotl * 7;
void dot()
{
digitalwrite(ledpin, high);
delay(dotl);
lightoff(inletpause);
}
void dash()
{
digitalwrite(ledpin, high);
delay(dashl);
lightoff(inletpause);
}
void lightoff(int off)
{
digitalwrite(ledpin, low);
delay(off);
}
void setup()
{
pinmode(ledpin, output);
}
void loop()
{
int counter=0,counter1=0;
do
{
string letter = words[counter];
int location=morse.indexof(letter);
string code=morsecode[location];
int counter1=0;
do
{
char morsechar=code[counter1];
if (morsechar='.')
{
dot();
}
else if (morsechar='-')
{
dash();
}
else
{
lightoff(wordpausel);
}
counter1++;
}
while(counter1!=code.length()-1);
counter++;
}
while (counter!=sizeof(words)-1);
lightoff(8000);
}
quote
please help.first, ditch string class.
second, rid of do/while loops. use while loops, instead. if don't understand difference, time do. i'm relatively confident when do, problem go away.
Arduino Forum > Using Arduino > Project Guidance > Coding Problem probably an endless loop (Morse Code converter using arrays)
arduino
Comments
Post a Comment