end of the message to be emitted as Morse code. Finally, we set
to the maximum length of the messages we are able to send.
Next we define three global variables:
gets filled with the data we receive on the serial port.
current position in the buffer, and
convert a message into "blinkenlights."
setup
initializes the serial port, and in
arrived, calling
Serial.available
and we check whether it is a newline character or whether it is the last byte
that fits into our character buffer. In both cases, we set the last byte of
sage_text
to 0, because strings in C/C++ are null-terminated. We also reset
index
so we can read the next message, and finally we send the message using
our telegraph. In all other cases, we add the latest byte to the current message
text and move on.
You should compile and upload the program now. Open the serial monitor
and choose "Newline" from the line endings drop-down menu at the bottom
of the window. With this option set, the serial monitor will automatically
append a newline character to every line it sends to the Arduino. Enter a
message such as your name, click the Send button, and see how the Arduino
turns it into light. In the following figure, you can see what happens when
you enter my name.
2.
http://en.wikipedia.org/wiki/Blinkenlights
Chapter 4. Building a Morse Code Generator Library
message_text
telegraph
is the
2
loop
we check whether new data has
. We read the next byte if new data is available,
www.it-ebooks.info
MAX_MESSAGE_LEN
is a character buffer that
index
keeps track of our
Telegraph
object we ll use to
70
mes-
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?