January 2015
Beginner
324 pages
7h 42m
English
After everything has been initialized, we can start to output Morse code symbols. We use several small helper methods to make our code as readable as possible:
| TelegraphLibrary/telegraph.cpp | |
| | void Telegraph::output_code(const char* code) { |
| | const unsigned int code_length = strlen(code); |
| | |
| | for (unsigned int i = 0; i < code_length; i++) { |
| | if (code[i] == '.') |
| | dit(); |
| | else |
| | dah(); |
| | if (i != code_length - 1) |
| | delay(_dit_length); |
| | } |
| | } |
| | |
| | void Telegraph::dit() { |
| | Serial.print("."); |
| | output_symbol(_dit_length); |
| | } |
| | |
| | void Telegraph::dah() { |
| | Serial.print("-"); |
| | output_symbol(_dah_length); |
| | } |
| | void Telegraph::output_symbol(const int length) { |
| | digitalWrite(_output_pin, ... |
Read now
Unlock full access