I'm using the Arduino software to create a Morse code decoder using the serial monitor.
I enter a Morse code such as .- as a text string and it's displayed in the LCD as a alphanumeric text. So if I enter .- into the serial Monitor, A is displayed on the LCD. But it only works for single symbols, not the dot and dash together.
Is there a way to make the if statement as seen below accept both the dots and dashes together?
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
char schar;
if (Serial.available())
{
schar = Serial.read();
Serial.write(schar);
if (schar== '.-' ){
Serial.write('A');
lcd.print('a');
}
}
}
string(lowercase) on arduino, sometimes called a "c style string". It can work, but using the functions built in to arduino'sStringclass might be easier. that would beString schar;– BrettFolkins Dec 14 '14 at 17:52if(data[0] == '.' && data[1] == '-')would be more efficient) – Anonymous Penguin Dec 15 '14 at 00:06