Transmisor y Receptor de Clave Morse
Transmisor y Receptor de Clave Morse
COMUNICACIÓN DE DATOS II
UNIVERSIDAD DE CUNDINAMARCA
EXTENSIÓN CHIA
2020
CLAVE MORSE
Materiales:
- Arduino Uno o Mega
- Protoboard
- Potenciometro
- 3 Resistencias de 1k
- 1 Resistencia de 470k
- Buzzer
- 2 Pulsadores
- 1 Led
CÓDIGO ARDUINO
#include <Wire.h>
#include <LiquidCrystal.h>
#define SLEUTEL 15
#define BUZZER 14
#define CLEAR2 16
char* letters[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", //A-I
".--", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", //J-R
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." //S-Z
};
char* numbers [ ] = {"-----", ".----", " ..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." };
int dotDelay = 200;
LiquidCrystal lcd(8,9,10,11,12,13);
void setup() {
pinMode(SLEUTEL, INPUT_PULLUP);
pinMode(BUZZER, OUTPUT);
Serial.begin(115200);
lcd.begin(16,2);
if (S) {
if (S != PrevS) {
tStartTeken = millis();
DecodeerPauze(tStartPauze);
}
digitalWrite(BUZZER, HIGH);
}
else {
if (S != PrevS) {
tStartPauze = millis();
Decodeer(tStartTeken);
}
digitalWrite(BUZZER, LOW);
}
PrevS = S;
if (teken == '-') {
if (tijd > StreepDuur) StreepDuur++;
if (tijd < StreepDuur) StreepDuur--;
}
else if (teken == '.') {
if (tijd > StreepDuur / 3.0) StreepDuur++;
if (tijd < StreepDuur / 3.0) StreepDuur--;
}
kar += teken;
//Serial.println(teken);
}
void DecodeerKar() {
static String letters[] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-",
".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", "E"
};
int i = 0;
while (letters[i] != "E") {
if (letters[i] == kar) {
Print((char)('A' + i));
Serial.print((char)('A' + i));
break;
}
i++;
}
if (letters[i] == "E") {
Print(kar);
Serial.print(kar);
}
kar = "";
int y = 0, x = 0;
void Print(String &s) {
for (int i = 0; i < s.length(); i++) {
upd();
lcd.print(s[i]);
}
}
void Print(char s) {
upd();
lcd.print(s);
}
void Print(char *s) {
for (int i = 0; i < strlen(s); i++) {
upd();
lcd.print(s[i]);
}
}
void upd() {
lcd.setCursor(x, y);
x++; if (x >= 20) {
x = 0;
y++;
}
if (y >= 4) {
lcd.clear();
x=y = 0;
}
if(CLEAR2 == HIGH){
lcd.clear();
}
}