In this project we are working with the micro conntroller MKR-1000
Here we will see an example video when the code is executed :
This simulation is completely exceptional from the others in view that, similarly to the usage of an LED and a speaker on the equal time, as opposed to encoding the SOS sign, it converts some thing that is written inside the Arduino IDE console into morse code. subsequent, the string item is used to represent and manage a series of characters. The LEN function, then again, returns an integer price indicating the range of characters in the enter string. the next strains incorporate the "char" element, that is used to symbolize or include a single character. ultimately, the unit postpone cost is entered, which lets in defining the unit of time and the postpone time, in this situation 250 milliseconds. next, you begin with the voids, first with the setup and sprint voids, in which you outline the tone you want to achieve and the postpone of each activate and stale, whether or not brief or lengthy. Later, we start to outline the morse code of each of the letters of the alphabet in uppercase and lowercase and additionally the numbers from 0 to nine, all using the dot (for the point) and sprint (for the sprint) values described formerly. to complete, a configuration is manufactured from what is going to seem inside the console when we write anything. via "Serial.println" the special texts so as to seem inside the console are programmed, before and after making the translation to Morse code. in addition, on this final a part of the code the speed of the interpretation is defined and the LED and the loudspeaker are assigned to their outputs by "PinMode".
const int led = 13; // the LED output is the 13 const int buz = 8; // the speaker output is the 8 String code = ""; int len = 0; char ch; char new_char; int unit_delay = 250; void dot() { Serial.print("."); digitalWrite(led, HIGH); tone(buz, 1000); // tone ( Is the library of audio) delay(unit_delay); digitalWrite(led, LOW); noTone(buz); delay(unit_delay); } void dash() { Serial.print("-"); digitalWrite(led, HIGH); tone(buz, 1000); delay(unit_delay * 3); digitalWrite(led, LOW); noTone(buz); delay(unit_delay); } void A() { dot(); delay(unit_delay); dash(); delay(unit_delay); } void B() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void C() { dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void D() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void E() { dot(); delay(unit_delay); } void f() { dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void G() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void H() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void I() { dot(); delay(unit_delay); dot(); delay(unit_delay); } void J() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void K() { dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void L() { dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void M() { dash(); delay(unit_delay); dash(); delay(unit_delay); } void N() { dash(); delay(unit_delay); dot(); delay(unit_delay); } void O() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void P() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); } void Q() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void R() { dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void S() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void T() { dash(); delay(unit_delay); } void U() { dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void V() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void W() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void X() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void Y() { dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void Z() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void one() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void two() { dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void three() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void four() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void five() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void six() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void seven() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void eight() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void nine() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void zero() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void morse() { if (ch == 'A' || ch == 'a') { A(); Serial.print(" "); } else if (ch == 'B' || ch == 'b') { B(); Serial.print(" "); } else if (ch == 'C' || ch == 'c') { C(); Serial.print(" "); } else if (ch == 'D' || ch == 'd') { D(); Serial.print(" "); } else if (ch == 'E' || ch == 'e') { E(); Serial.print(" "); } else if (ch == 'f' || ch == 'f') { f(); Serial.print(" "); } else if (ch == 'G' || ch == 'g') { G(); Serial.print(" "); } else if (ch == 'H' || ch == 'h') { H(); Serial.print(" "); } else if (ch == 'I' || ch == 'i') { I(); Serial.print(" "); } else if (ch == 'J' || ch == 'j') { J(); Serial.print(" "); } else if (ch == 'K' || ch == 'k') { K(); Serial.print(" "); } else if (ch == 'L' || ch == 'l') { L(); Serial.print(" "); } else if (ch == 'M' || ch == 'm') { M(); Serial.print(" "); } else if (ch == 'N' || ch == 'n') { N(); Serial.print(" "); } else if (ch == 'O' || ch == 'o') { O(); Serial.print(" "); } else if (ch == 'P' || ch == 'p') { P(); Serial.print(" "); } else if (ch == 'Q' || ch == 'q') { Q(); Serial.print(" "); } else if (ch == 'R' || ch == 'r') { R(); Serial.print(" "); } else if (ch == 'S' || ch == 's') { S(); Serial.print(" "); } else if (ch == 'T' || ch == 't') { T(); Serial.print(" "); } else if (ch == 'U' || ch == 'u') { U(); Serial.print(" "); } else if (ch == 'V' || ch == 'v') { V(); Serial.print(" "); } else if (ch == 'W' || ch == 'w') { W(); Serial.print(" "); } else if (ch == 'X' || ch == 'x') { X(); Serial.print(" "); } else if (ch == 'Y' || ch == 'y') { Y(); Serial.print(" "); } else if (ch == 'Z' || ch == 'z') { Z(); Serial.print(" "); } else if (ch == '0') { zero(); Serial.print(" "); } else if (ch == '1') { one(); Serial.print(" "); } else if (ch == '2') { two(); Serial.print(" "); } else if (ch == '3') { three(); Serial.print(" "); } else if (ch == '4') { four(); Serial.print(" "); } else if (ch == '5') { five(); Serial.print(" "); } else if (ch == '6') { six(); Serial.print(" "); } else if (ch == '7') { seven(); Serial.print(" "); } else if (ch == '8') { eight(); Serial.print(" "); } else if (ch == '9') { nine(); Serial.print(" "); } else if(ch == ' ') { delay(unit_delay*7); Serial.print("/ "); } else Serial.println("Unknown symbol!"); } void String2Morse() { len = code.length(); for (int i = 0; i < len; i++) { ch = code.charAt(i); morse(); } } void setup() { Serial.begin(9600); pinMode(led, OUTPUT); pinMode(buz, OUTPUT); Serial.println("I am ready..."); } void loop() { while (Serial.available()) { code = Serial.readString(); Serial.print(code); Serial.print(" = "); String2Morse(); Serial.println(""); } delay(1000); }