Archiving a bunch of old stuff

This commit is contained in:
Dan Buch
2015-06-22 13:15:42 -05:00
parent a6ec1d560e
commit bd1abd8734
395 changed files with 1 additions and 76 deletions

View File

@@ -0,0 +1 @@
../../../arduino.mk

View File

@@ -0,0 +1,5 @@
void setup() {
}
void loop() {
}

View File

@@ -0,0 +1,105 @@
// vim:filetype=arduino
#include <ctype.h>
#include <Arduino.h>
#include "telegraph.h"
const char* LETTERS[] = {
".-", // A
"-...", // B
"-.-.", // C
"-..", // D
".", // E
"..-.", // F
"--.", // G
"....", // H
"..", // I
".---", // J
"-.-", // K
".-..", // L
"--", // M
"-.", // N
"---", // O
".--.", // P
"--.-", // Q
".-.", // R
"...", // S
"-", // T
"..-", // U
"...-", // V
".--", // W
"-..-", // X
"-.--", // Y
"--.." // Z
};
const char* DIGITS[] = {
"-----", // 0
".----", // 1
"..---", // 2
"...--", // 3
"....-", // 4
".....", // 5
"-....", // 6
"--...", // 7
"---..", // 8
"----.", // 9
};
Telegraph::Telegraph(const int output_pin, const int dit_length) {
_output_pin = output_pin;
_dit_length = dit_length;
_dah_length = dit_length * 3;
pinMode(_output_pin, OUTPUT);
}
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, HIGH);
delay(length);
digitalWrite(_output_pin, LOW);
}
void Telegraph::send_message(const char* message) {
unsigned int message_length = (unsigned int)strlen(message);
for (unsigned int i = 0; i < message_length; i++) {
const char current_char = toupper(message[i]);
if (isalpha(current_char)) {
output_code(LETTERS[current_char - 'A']);
delay(_dah_length);
} else if (isdigit(current_char)) {
output_code(DIGITS[current_char - '0']);
delay(_dah_length);
} else if (current_char == ' ') {
Serial.print(" ");
delay(_dit_length * 7);
}
}
Serial.println();
}

View File

@@ -0,0 +1,18 @@
#ifndef __TELEGRAPH_H__
#define __TELEGRAPH_H__
class Telegraph {
public:
Telegraph(const int output_pin, const int dit_length);
void send_message(const char* message);
private:
void dit();
void dah();
void output_code(const char* code);
void output_symbol(const int length);
int _output_pin;
int _dit_length;
int _dah_length;
};
#endif