Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
9.2 kB
3
Indexable
Never
const int LedLight = 7;
const int Buzzer = 8;
String code = "";
int l = 0;
char ch;
int d = 300;
void point() {
  Serial.print(".");
  digitalWrite(LedLight, HIGH);
  tone(Buzzer, 440);
  delay(d);
  digitalWrite(LedLight, LOW);
  noTone(Buzzer);
  delay(d);
}

void dash() {
  Serial.print("-");
  digitalWrite(LedLight, HIGH);
  tone(Buzzer, 440);
  delay(d * 2);
  digitalWrite(LedLight, LOW);
  noTone(Buzzer);
  delay(d);
}

void A() {
  point();
  delay(d);
  dash();
  delay(d);
}
void B() {
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void C() {
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
}
void D() {
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void E() {
  point();
  delay(d);
}
void f() {
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
}
void G() {
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
}
void H() {
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void I() {
  point();
  delay(d);
  point();
  delay(d);
}
void J() {
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}
void K() {
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}
void L() {
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void M() {
  dash();
  delay(d);
  dash();
  delay(d);
}
void N() {
  dash();
  delay(d);
  point();
  delay(d);
}
void O() {
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}
void P() {
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  point();
}
void Q() {
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}
void R() {
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
}
void S() {
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void T() {
  dash();
  delay(d);
}
void U() {
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}
void V() {
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}
void W() {
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}
void X() {
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}
void Y() {
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}
void Z() {
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void one() {
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}
void two() {
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}
void three() {
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}
void four() {
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}
void five() {
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void six() {
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void seven() {
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void eight() {
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}
void nine() {
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
}
void zero() {
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}

void period(){
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}

void comma(){
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}

void QM(){
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}

void EM(){
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
}

void colon(){
  dash();
  delay(d);
  dash();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
}

void DD(){
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}

void plus(){
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
  point();
  delay(d);
}

void minus(){
  dash();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  point();
  delay(d);
  dash();
  delay(d);
}

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 == '.')   {
    period();
    Serial.print(" ");
  }else if(ch == ',')   {
    comma();
    Serial.print(" ");
  }else if(ch == '?')   {
    QM();
    Serial.print(" ");
  }else if(ch == '!')   {
    EM();
    Serial.print(" ");
  }else if(ch == ':')   {
    colon();
    Serial.print(" ");
  }else if(ch == '=')   {
    DD();
    Serial.print(" ");
  }else if(ch == '+')   {
    plus();
    Serial.print(" ");
  }else if(ch == '-')   {
    minus();
    Serial.print(" ");
  }else if (ch == ' ')  {
    delay(d * 7);
    Serial.print("/ ");
  }else{
    Serial.println("Unknown symbol!");
  }
}

void MorseString(){
  l = code.length();
  for(int i = 0; i < l; i++){
    ch = code.charAt(i);
    morse();
  }
}

void setup(){
  Serial.begin(9600);
  pinMode(LedLight, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  Serial.print("Let start... ");
}

void loop(){
  while(Serial.available()){
    code = Serial.readString();
    Serial.print(code);
    Serial.print(" = ");
    MorseString();
    Serial.print("");
  }
  delay(1000);
}