Figure 14—Find the sketchbook location in the Preferences.
TelegraphLibrary/examples/HelloWorld/HelloWorld.ino
#include "telegraph.h"
const unsigned int BAUD_RATE = 9600;
const unsigned int OUTPUT_PIN = 13;
const unsigned int DIT_LENGTH = 200;
Telegraph telegraph(OUTPUT_PIN, DIT_LENGTH);
void setup() {
Serial.begin(BAUD_RATE);
}
void loop() {
telegraph.send_message("Hello, world!");
delay(5000);
}
This sketch emits the string “Hello, world!” as Morse code every five seconds.
To achieve this, we include the definition of our
Telegraph
class, and we define
constants for the pin our LED is connected to and for the length of our dits.
Then we create a global
Telegraph
object and an empty
setup
function. In
loop
,
we then invoke
send_message
on our
Telegraph
instance every five seconds.
When you compile this sketch, the Arduino IDE automatically compiles the
telegraph library, too. If you forgot to copy the library files to the
libraries/Telegraph
folder, you’ll get an error message such as “Telegraph does not name a type.”
Chapter 4. Building a Morse Code Generator Library • 68
report erratum • discuss
www.it-ebooks.info