Arduino Uno Quick Start Manual page 88

Hide thumbs Also See for Arduino Uno:
Table of Contents

Advertisement

If you ve copied the files but made any syntactical errors, you ll also be notified
now. If you have to correct some errors, make sure you change your original
source code files. After you ve fixed the errors, copy the files to the
folder again, and don t forget to restart the IDE.
Turning a static string into Morse code is nice, but wouldn t it be great if our
program could work for arbitrary strings? So, let s add a more sophisticated
example. This time, we ll write code that reads messages from the serial port
and feeds them into a
Create a new sketch named
TelegraphLibrary/examples/MorseCodeGenerator/MorseCodeGenerator.ino
#include "telegraph.h"
const unsigned int
OUTPUT_PIN = 13;
const unsigned int
DIT_LENGTH = 200;
const unsigned int
MAX_MESSAGE_LEN = 128;
const unsigned int
BAUD_RATE = 9600;
const char
NEWLINE = '\n';
char
message_text[MAX_MESSAGE_LEN];
int
index = 0;
Telegraph telegraph(OUTPUT_PIN, DIT_LENGTH);
void
setup() {
Serial.begin(BAUD_RATE);
}
void
loop() {
if
(Serial.available() > 0) {
int
current_char = Serial.read();
if
(current_char == NEWLINE || index == MAX_MESSAGE_LEN - 1) {
message_text[index] = 0;
index = 0;
telegraph.send_message(message_text);
}
else
{
message_text[index++] = current_char;
}
}
}
Again, we include the header file of the
some constants:
OUTPUT_PIN
DIT_LENGTH
contains the length of a dit measured in milliseconds.
set to the ASCII code of the newline character. We need it to determine the
instance.
Telegraph
MorseCodeGenerator
Telegraph
defines the pin our LED is connected to, and
www.it-ebooks.info
Installing and Using the Telegraph Class
and enter the following code:
class, and as usual we define
69
libraries
NEWLINE
is
report erratum
discuss

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Arduino Uno and is the answer not in the manual?

Table of Contents