EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #88 background imageLoading...
Page #88 background image
If youve copied the files but made any syntactical errors, youll also be notified
now. If you have to correct some errors, make sure you change your original
source code files. After youve fixed the errors, copy the files to the
libraries
folder again, and dont forget to restart the IDE.
Turning a static string into Morse code is nice, but wouldnt it be great if our
program could work for arbitrary strings? So, lets add a more sophisticated
example. This time, well write code that reads messages from the serial port
and feeds them into a
Telegraph
instance.
Create a new sketch named
MorseCodeGenerator
and enter the following code:
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
Telegraph
class, and as usual we define
some constants:
OUTPUT_PIN
defines the pin our LED is connected to, and
DIT_LENGTH
contains the length of a dit measured in milliseconds.
NEWLINE
is
set to the ASCII code of the newline character. We need it to determine the
report erratum discuss
Installing and Using the Telegraph Class 69
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals