#include <Arduino.h>
int i = -1, j, port, N = -1, idx, AN = 0;
int rst, dot, das;
String code = "";
String Morse[36] = {
{".----"}, //1
{"..---"}, //2
{"...--"}, //3
{"....-"}, //4
{"....."}, //5
{"-...."}, //6
{"--..."}, //7
{"---.."}, //8
{"----."}, //9
{"----*"}, //0
{".-***"}, //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
};
boolean SEG16[36][18] = {
{0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1
{1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0}, //2
{1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3
{0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, //4
{1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, //5
{1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0}, //6
{1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //7
{1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0}, //8
{1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, //9
{1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1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, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0}, //R
{1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1}, //S
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0}, //T
{0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1}, //U
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0}, //V
{0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0}, //W
{0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0}, //X
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0}, //Y
{1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1}, //Z
};
void setup() {
Serial.begin(9600);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
for (j = 22; j < 40; j++) {
pinMode(j, OUTPUT);
}
}
void loop() {
delay(1000);
das = digitalRead(7);
dot = digitalRead(8);
rst = digitalRead(9);
if (rst == 1 || N > 4) {
for (i = 0; i < 36; i++) {
idx = Morse[i].indexOf("*");
//idx = code.length();
if (code.compareTo(Morse[i].substring(0, idx)) == 0) {
AN = i;
Serial.println(AN);
break;
}
}
N = -1;
code = "";
}
if (dot == 1) {
N = N + 1;
code = String(code + ".");
}
if (das == 1) {
N = N + 1;
code = String(code + "-");
}
Serial.print(code);
Serial.print("\n");
// AN = (AN + 1) % 36;
for (j = 0; j < 18; j++) {
port = 22 + j;
if (SEG16[AN][j] == 0) {
digitalWrite(port, HIGH);
}
else {
digitalWrite(port, LOW);
}
}
}
Comments