Created
May 5, 2022 10:39
-
-
Save sebadima/75ba9d233054bd5e2e9b75f4dd824602 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ledPin = 13; | |
char* letters[] = { | |
“.-”, “-…”, “-.-.”, “-..”, “.”, “..-.”, “–.”, “….”, “..”, | |
“.—”, “-.-”, “.-..”, “–”, “-.”, “—”, “.–.”, “–.-”, “.-.”, | |
“…”, “-”, “..-”, “…-”, “.–”, “-..-”, “-.–”, “–..” | |
}; | |
// A-I | |
// J-R | |
// S-Z | |
char* numbers[] = { “—–”, “.—-”, “..—”, | |
“…–”, “….-”, “…..”, “-….”, | |
“–…”, “—..”, “—-.” }; | |
int dotDelay = 200; | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
char ch; | |
if (Serial.available()) { | |
ch = Serial.read(); | |
// read a single letter | |
if (ch >= ‘a’ && ch <= ‘z’) { | |
flashSequence(letters[ch - ‘a’]); | |
} | |
else if (ch >= ‘A’ && ch <= ‘Z’) { | |
flashSequence(letters[ch - ‘A’]); | |
} | |
else if (ch >= ‘0’ && ch <= ‘9’) { | |
flashSequence(numbers[ch - ‘0’]); | |
} | |
else if (ch == ‘ ‘) { | |
delay(dotDelay * 4); | |
// gap between words | |
} | |
} | |
} | |
void flashSequence(char* sequence) | |
{ | |
int i = 0; | |
while (sequence[i] != NULL) { | |
flashDotOrDash(sequence[i]); | |
i++; | |
} | |
delay(dotDelay * 3); | |
} | |
void flashDotOrDash(char dotOrDash) | |
{ | |
digitalWrite(ledPin, HIGH); | |
if (dotOrDash == ‘.’) { | |
delay(dotDelay); | |
} | |
else // must be a - | |
{ | |
delay(dotDelay * 3); | |
} | |
digitalWrite(ledPin, LOW); | |
delay(dotDelay); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment