Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ledPin = 12;
- char* letters[] = {
- ".-", "-...", "-.-.", "-..", ".", // A-E
- "..-.", "--.", "....", "..", ".---", // F-J
- "-.-", ".-..", "--", "-.", "---", // K-O
- ".--.", "--.-", ".-.", "...", "-", // P-T
- "..-", "...-", ".--", "-..-", "-.--", // U-Y
- "--.." }; // Z
- char* numbers[] = {
- "-----", ".----", "..---", "...--", "....-", ".....", // 0-5
- "-....", "--...", "---..", "----." }; // 6-9
- String morseCode = NULL;
- void setup()
- {
- pinMode(ledPin, OUTPUT);
- Serial.begin(9600);
- flash(2000);
- }
- void loop()
- {
- while (Serial.available() > 0) {
- int ch, adjust;
- ch = Serial.read();
- // A - Z 0 - 9 a - z
- if (ch != 10) {
- adjust = (((ch >= 65) && (ch <= 90)) ? 65 : (((ch >= 48) && (ch <= 57)) ? 48 : (((ch >= 97) && (ch <= 122)) ? 97 : 0)));
- if (adjust) {
- morseCode = morseCode + letters[ch - adjust];
- }
- }
- else {
- if (morseCode) {
- Serial.print(morseCode + "!\n");
- morseCode = NULL;
- }
- }
- }
- }
- void writeMorse() {
- }
- void flash(int duration)
- {
- digitalWrite(ledPin, HIGH);
- delay(duration);
- digitalWrite(ledPin, LOW);
- delay(duration);
- }
Add Comment
Please, Sign In to add comment