PLS help i was trying to make a morse code translator but it went wrong pls help
here is the code
const int dotdelay = 200;
const int ledpin = 13;
char* letters[] = {
".-", "-... ", " -.-.", " -..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
};
char* numbers[] = {
"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."};
void setup()
{
pinMode(ledpin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
char ch;
if (Serial.available() > 0);
{
ch = Serial.read();
if (ch >= 'a' && ch <= 'z')
{
flashSequence (letters [ch - 'a']);
}
else if (ch >= 'A' && ch >= 'Z')
{
flashSequence(letters [ch - 'A']);
}
else if (ch >= '0' && ch <= '9');
{
flashSequence(numbers [ch - '0']);
}
else //if (ch == ' ')
{
delay(dotDelay * 4) ;
}
}
}
void flashSequence (char*sequence)
{
int i = 0;
while (sequence[i]);
{
flashDotOrDash(sequence[i]);
i++;
}
delay(dotDelay*3);
}
void flashDotOrDash(char dotOrDash)
{
digitalWrite(lepin, HIGH);
if (dotOrDash == '.')
{
delay(dotDelay);
}
else
{
delay(dotDelay * 3)
}
digitalWrite(ledpin, LOW);
delay(dotDelay);
}
J-M-L
3
you have an extra semi colon that should not be there at the end of that line
edit: jfjlaros was faster
thks soo much. ur bth legends and also it says 'dotDelay' was not declared in this scope. pls help with that too, but thanks sooo much
as per @jfjlaros and @J-M-L , plus...
extra ";" here too.
... and here
1 Like
is not equal to
if compared letter by letter the words "dotdelay" and "dotDelay" one may find a difference.
1 Like
ffur
7
dotdelay isn't the same as dotDelay.
/regs. ffur
If you use Auto Format in the IDE the problem will be more obvious.
Auto Formatted code
void loop()
{
char ch;
if (Serial.available() > 0);
{ //where is the end of this code block ?
ch = Serial.read();
if (ch >= 'a' && ch <= 'z')
{
flashSequence (letters [ch - 'a']);
}
else if (ch >= 'A' && ch >= 'Z')
{
flashSequence(letters [ch - 'A']);
}
else if (ch >= '0' && ch <= '9');
{
flashSequence(numbers [ch - '0']);
}
else //if (ch == ' ')
{
delay(dotDelay * 4) ;
}
}
}
J-M-L
10
Please don't double post?
do yourself a favour and please read How to get the best out of this forum
(I merged both posts)
What... Is it Ground Hog day?
Did you try using this thing,
and words like "morse code" to view the many many solutions that others have come up with?
For the benefit of others please post your fixed code and explain what you changed
system
Closed
16
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.