int buzzer = 2; //sets the buzzer to pin 2 of the samd11c int note = 1000; // Set the pitch for the buzzer tone int timeUnit = 100; // this var will determine the lenght of the dot,dashes and pauses on the buzzer char input; void setup () { Serial.begin(115200);//segin serial communications } void loop () { if (Serial.available()) { input = Serial.read();//read the input if (input == 'a' || input == 'A') //if the var input hold the char "a" or "A" then calls the function 1A() { lA(); } if (input == 'b' || input == 'B')//if the var input hold the char "b" or "B" then calls the function 1B() { lB(); } //from here on i'll put the if funtcion in a single line for it to use less lines if (input == 'c' || input == 'C') {lC();}//if the var input hold the char "c" or "C" then calls the function 1C() if (input == 'd' || input == 'D') {lD();}//if the var input hold the char "d" or "D" then calls the function 1D() if (input == 'e' || input == 'E') {lE();}//if the var input hold the char "e" or "E" then calls the function 1E() if (input == 'f' || input == 'F') {lF();}//if the var input hold the char "f" or "F" then calls the function 1F() if (input == 'g' || input == 'G') {lG();}//if the var input hold the char "g" or "G" then calls the function 1G() if (input == 'h' || input == 'H') {lH();}//if the var input hold the char "h" or "H" then calls the function 1H() if (input == 'i' || input == 'I') {lI();}//if the var input hold the char "i" or "I" then calls the function 1I() if (input == 'j' || input == 'J') {lJ();}//if the var input hold the char "j" or "J" then calls the function 1J() if (input == 'k' || input == 'K') {lK();}//if the var input hold the char "k" or "K" then calls the function 1K() if (input == 'l' || input == 'L') {lL();}//if the var input hold the char "l" or "L" then calls the function 1L() if (input == 'm' || input == 'M') {lM();}//if the var input hold the char "m" or "M" then calls the function 1M() if (input == 'n' || input == 'N') {lN();}//if the var input hold the char "n" or "N" then calls the function 1N() if (input == 'o' || input == 'O') {lO();}//if the var input hold the char "o" or "O" then calls the function 1O() if (input == 'p' || input == 'P') {lP();}//if the var input hold the char "p" or "P" then calls the function 1P() if (input == 'q' || input == 'Q') {lQ();}//if the var input hold the char "q" or "Q" then calls the function 1Q() if (input == 'r' || input == 'R') {lR();}//if the var input hold the char "r" or "R" then calls the function 1R() if (input == 's' || input == 'S') {lS();}//if the var input hold the char "s" or "S" then calls the function 1S() if (input == 't' || input == 'T') {lT();}//if the var input hold the char "t" or "T" then calls the function 1T() if (input == 'u' || input == 'U') {lU();}//if the var input hold the char "u" or "U" then calls the function 1U() if (input == 'v' || input == 'V') {lV();}//if the var input hold the char "v" or "V" then calls the function 1V() if (input == 'w' || input == 'W') {lW();}//if the var input hold the char "w" or "W" then calls the function 1W() if (input == 'x' || input == 'X') {lX();}//if the var input hold the char "x" or "X" then calls the function 1X() if (input == 'y' || input == 'Y') {lY();}//if the var input hold the char "y" or "Y" then calls the function 1Y() if (input == 'z' || input == 'Z') {lZ();}//if the var input hold the char "z" or "Z" then calls the function 1Z() if (input == ' ') {wordPause();}//if the var input holds the char " " (space between letters) then calls the function wordPause() Serial.println (input);//prints the value of the input } } //Letter functions void lA () //secuence of functions that represents the letter A in morse code { dot(); dash(); letterPause(); } void lB ()//secuence of functions that represents the letter A in morse code { dash(); dot(); dot(); dot(); letterPause(); } //from here on i'll put the sequences in a single line to use less lines void lC () {dash();dot();dash();dot();letterPause();} void lD () {dash();dot();dot();letterPause();} void lE () {dot();letterPause();} void lF () {dot();dot();dash();dot();letterPause();} void lG () {dash();dash();dot();letterPause();} void lH () {dot();dot();dot();dot();letterPause();} void lI () {dot();dot();letterPause();} void lJ () {dot();dash();dash();dash();letterPause();} void lK () {dash();dot();dash();letterPause();} void lL () {dot();dash();dot();dot();letterPause();} void lM () {dash();dash();letterPause();} void lN () {dash();dot();letterPause();} void lO () {dash();dash();dash();letterPause();} void lP () {dot();dash();dash();dot();letterPause();} void lQ () {dash();dash();dot();dash();letterPause();} void lR () {dot();dash();dot();letterPause();} void lS () {dot();dot();dot();letterPause();} void lT () {dash();letterPause();} void lU () {dot();dot();dash();letterPause();} void lV () {dot();dot();dot();dash();letterPause();} void lW () {dot();dash();dash();letterPause();} void lX () {dash();dot();dot();dash();letterPause();} void lY () {dash();dot();dash();dash();letterPause();} void lZ () {dash();dash();dot();dot();letterPause();} void dot()//a function that holds the "dot" feature(emits a sound for 100 miliseconds) { tone(buzzer, note, timeUnit);// function tone (pin,pitch of the tone,duration of the tone) delay(timeUnit * 2);//200 miliseconds to represent 1 dot } void dash() //Emit a longer sound to represent a dash on morse code { tone(buzzer, note, timeUnit * 3);// function tone (pin,pitch of the tone, duration of the tone 3 times longer than the dot) delay(timeUnit * 4);//400 miliseconds to represent 1 dash } void letterPause() // silence between letters { delay(timeUnit * 3);//300 miliseconds } void wordPause()//silence between words { delay (timeUnit * 7); //700 miliseconds }