Now open a new tab, and when asked for a filename, enter
will create a good old C header file. (To be precise, it will even be a C++
header file.)
TelegraphLibrary/telegraph.h
#ifndef __TELEGRAPH_H__
#define __TELEGRAPH_H__
class
Telegraph {
public:
Telegraph(const int
void send_message(const
private:
void
dit();
void
dah();
void output_code(const
void output_symbol(const int
int
_output_pin;
int
_dit_length;
int
_dah_length;
};
#endif
Ah, obviously object-oriented programming is not only for the big CPUs any-
more! This is an interface description of a
in your next enterprise project (provided that you need to transmit some
information as Morse code, that is).
We start with the classic double-include prevention mechanism; that is, the
body of the header file defines a preprocessor macro named
We wrap the body (that contains this definition) in an
is only compiled if the macro has not been defined. That way, you can include
the header as many times as you want, and the body will be compiled only
once.
The interface of the
Telegraph
class have access to and a private part that only members of the class can
use. In the public part, you find two things: a constructor that creates new
Telegraph
objects and a method named
emitting it as Morse code. In your applications, you can use the class as fol-
lows:
Telegraph telegraph(13, 200);
telegraph.send_message("Hello,
output_pin,
const int
char* message);
char* code);
length);
Telegraph
class consists of a public part that users of the
send_message
world!");
www.it-ebooks.info
Building a Morse Code Generator
telegraph.h
dit_length);
class that you could use
__TELEGRAPH_H__
#ifndef
so that the body
that sends a message by
63
. Yes, we
.
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?