# My Morse Code
###### tags: `Morse` `DSNA 22` `Button` `LED`
[ToC]
> Lets Send som Morse code and light related LEDS
## :memo: How it Works ?
### Step 1: Connect it well

:rocket:
### Step 2: Easy code
```
// Summary: This program is simulation to Morse code we send dots and dashes
// we ganna use 3 functions :
// 1) dot() : that that buzz and light the related led
//
// 2) dash() : that buzz longer and light another led
// 3) Which_Button : that return which Button we presed ( BLue button for //Dot , Red for dash)
// the Leds : Green when send a dot , Red when send a dash.
//
// The sound : 2 diferent Melodies for dot and for dash.
//
// Version: 1.0
// Owner: Ammar alnahhas
// ---------------------------------------------------------------
// Log: 2020-11-16 Created the file.
// 2020-11-16 Tested all values and Nich values also!
//
#define NOTE_Dot 523
#define NOTE_Dash 587
// input Buttoms Pin
const byte myPin2 =2;
const byte myPin3 =3;
// output Leds pin
const byte myPin10=10;
const byte myPin11=11;
// Buzzer
const byte myBuzzer =8;
// Parameter
int chosed = 0;
void setup() {
// input Pin
pinMode(myPin2,INPUT);
pinMode(myPin3,INPUT);
// output pin
pinMode(myPin10,OUTPUT);
pinMode(myPin11,OUTPUT);
pinMode(myBuzzer,OUTPUT);
// Computer output
Serial.begin(9600);
// Welcoming screen on Serial
Serial.println("Welcome to Morse Sender");
Serial.println(" ======================");
}
void loop() {
chosed = Which_Button();
switch (chosed)
{
case 0: //DOT
dot();
break;
case 1: // Dash
dash();
break;
}
}
void dot()
{
tone(myBuzzer, NOTE_Dot);
delay(100);
noTone(myBuzzer);
digitalWrite(myPin10, HIGH);
delay(250);
digitalWrite(myPin10, LOW);
delay(250);
}
void dash()
{
tone(myBuzzer, NOTE_Dash);
delay(200);
noTone(myBuzzer);
digitalWrite(myPin11, HIGH);
delay(250);
digitalWrite(myPin11, LOW);
delay(250);
}
int Which_Button(void)
{
int buttonState_Dot = 0;
int buttonState_Dash = 0;
Serial.println( "Dot or Dash ");
delay(200);
while (1){
buttonState_Dot = digitalRead(myPin2);
buttonState_Dash = digitalRead(myPin3);
if ( buttonState_Dot == HIGH)
{Serial.println("DOT") ;
return 0;}
else if (buttonState_Dash ==HIGH)
{Serial.println("DASH") ;
return 1;}
}
}
```
## BONUS: A Vedio Till:
- YouTube Video :
{%youtube wFnVqQ0Ng6g %}
# DSNA22 OTHER Projects :
* [My Morse Code.](https://hackmd.io/@DSNA22/MorseCode)
* [Traffic Lights Controler with IR Remote.](https://hackmd.io/@DSNA22/Italian_Job)
* [Math Trainig with Arduino , LCD,and 4X4 Keypad.](https://hackmd.io/@DSNA22/Math_Trainig_with_Arduino)
* [Rock,Scissors or Paper game.](https://hackmd.io/@DSNA22/Rock_Scissors_Paper)
* [Connecting Quad Seven segment and DHT11 via WiFi and API.](https://hackmd.io/@DSNA22/4_Seven_segment_and_DHT11_via_WiFi)
* YouTube Channel : [ Or you can visit my YouTube channel Here.](https://www.youtube.com/c/EngAmmarALNahas/videos)
# Last but not least Thanks :
Thanks for [Thomas Berggren](https://www.linkedin.com/in/tomas-berggren/) for all knowledge and experience that looks clearly in backscenes of this project!