So I'm new to arduino and done very basic things so far, such as blinking leds etc.
I'm trying to progress and want to do a morse code ir tx and ir rx.
So far I have built a morse code that outputs via led when read from the serial monitor. Here i used a book for the code. Here is the code;
int ledPin = 12;
char* letters[] = {
".-", "-...", "-.-", "-..", ".", "..-.", "--.", "....", "..", //Letters A-I
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", //Letters J-R
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." //Letters S-Z
};
char* numbers[] ={
"-----", ".----", "..---", "...--", "....-", ".....", "-....",
"--...", "---..", "----." //Numbers 0-9
};
int dotDelay = 200;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600); //Set the communications speed between the Arduino board and the USB 9600 baud
}
void loop()
{
char ch;
if (Serial.available()) //Constantly checks to see if any letters have been sent over the USB Connection and if the letter needs to be processed
{
ch = Serial.read(); //Reads a single letter
if (ch >= 'a' && ch <= 'z')
{
flashSequence(letters[ch - 'a']); //Flashes the LED to match the string that has been input
}
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 !=NULL)
{
flashDotOrDash(sequence);
i++;
}
delay(dotDelay * 3); //Gap between each letter
}
void flashDotOrDash(char dotOrDash)
{
digitalWrite(ledPin, HIGH);
if (dotOrDash == '.')
{
delay(dotDelay);
}
else //must be a dash
{
delay(dotDelay * 3);
}
digitalWrite(ledPin, LOW);
delay(dotDelay); //Gap between flashes
}
I have now wired up the ir tx and ir rx on the breadboard. See attached.
Can anyone help me implement the code to read input from the serial monitor (using ir tx) and receiving it in the serial monitor as output (using the ir rx). This need to be any text string.
I am a beginner with programming language as well.
Thank you in advance.
Moderator edit: Quote tags changed to code tags. (Nick Gammon)