-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d48530
commit 96d20d8
Showing
3 changed files
with
280 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,277 @@ | ||
# Day four: | ||
|
||
Communicate using morse code using the Barduino. | ||
|
||
dot dot dash... Use your resources to encode a message, and try to decode the rest of messages! | ||
|
||
Here is my solution, using the LED and the buzzer. Try to do it yourself first, and check this one if you don't manage. :winking_face: | ||
|
||
## Possible solution! | ||
|
||
### Arduino code | ||
|
||
```c++ | ||
const int led = 48; | ||
const int buzzer = 14; | ||
const int freq = 800; | ||
|
||
const int wait = 200; // Duration of a unit | ||
|
||
String message = "Bon dia Pere"; | ||
|
||
void setup() { | ||
pinMode(led, OUTPUT); | ||
ledcAttachPin(buzzer, 1); | ||
//pinMode(buzzer, OUTPUT); | ||
Serial.begin(115200); | ||
delay(2000); //wait 2 seconds to start transmitting | ||
|
||
for (int i = 0; i < message.length(); i++) { | ||
char letter = toLowerCase(message[i]); | ||
Serial.print(letter); | ||
morse(letter); | ||
delay(wait * 2); // wait 3 units if time after each character (1 in each letter and 2 here) | ||
|
||
} | ||
} | ||
|
||
void loop() { | ||
} | ||
|
||
void dot() { | ||
digitalWrite(led, HIGH); | ||
ledcWriteTone(1, freq); | ||
delay(wait); | ||
digitalWrite(led, LOW); | ||
ledcWriteTone(1, 0); | ||
delay(wait); //space between parts of a letter | ||
} | ||
|
||
void dash() { | ||
digitalWrite(led, HIGH); | ||
ledcWriteTone(1, freq); | ||
delay(wait * 3); // A dash are 3 dots | ||
digitalWrite(led, LOW); | ||
ledcWriteTone(1, 0); | ||
delay(wait); //space between parts of a letter | ||
} | ||
|
||
void morse(char letter) { | ||
switch (letter) { | ||
case 'a': | ||
dot(); | ||
dash(); | ||
break; | ||
case 'b': | ||
dash(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
break; | ||
case 'c': | ||
dash(); | ||
dot(); | ||
dash(); | ||
dot(); | ||
break; | ||
case 'd': | ||
dash(); | ||
dot(); | ||
dot(); | ||
break; | ||
case 'e': | ||
dot(); | ||
break; | ||
case 'f': | ||
dot(); | ||
dot(); | ||
dash(); | ||
dot(); | ||
break; | ||
case 'g': | ||
dash(); | ||
dash(); | ||
dot(); | ||
break; | ||
case 'h': | ||
dot(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
break; | ||
case 'i': | ||
dot(); | ||
dot(); | ||
break; | ||
case 'j': | ||
dot(); | ||
dash(); | ||
dash(); | ||
dash(); | ||
break; | ||
case 'k': | ||
dash(); | ||
dot(); | ||
dash(); | ||
break; | ||
case 'l': | ||
dot(); | ||
dash(); | ||
dot(); | ||
dot(); | ||
break; | ||
case 'm': | ||
dash(); | ||
dash(); | ||
break; | ||
case 'n': | ||
dash(); | ||
dot(); | ||
break; | ||
case 'o': | ||
dash(); | ||
dash(); | ||
dash(); | ||
break; | ||
case 'p': | ||
dot(); | ||
dash(); | ||
dash(); | ||
dot(); | ||
break; | ||
case 'q': | ||
dash(); | ||
dash(); | ||
dot(); | ||
dash(); | ||
break; | ||
case 'r': | ||
dot(); | ||
dash(); | ||
dot(); | ||
break; | ||
case 's': | ||
dot(); | ||
dot(); | ||
dot(); | ||
break; | ||
case 't': | ||
dash(); | ||
break; | ||
case 'u': | ||
dot(); | ||
dot(); | ||
dash(); | ||
break; | ||
case 'v': | ||
dot(); | ||
dot(); | ||
dot(); | ||
dash(); | ||
break; | ||
case 'w': | ||
dot(); | ||
dash(); | ||
dash(); | ||
break; | ||
case 'x': | ||
dash(); | ||
dot(); | ||
dot(); | ||
dash(); | ||
break; | ||
case 'y': | ||
dash(); | ||
dot(); | ||
dash(); | ||
dash(); | ||
break; | ||
case 'z': | ||
dash(); | ||
dash(); | ||
dot(); | ||
dot(); | ||
break; | ||
case '0': | ||
dash(); | ||
dash(); | ||
dash(); | ||
dash(); | ||
dash(); | ||
break; | ||
case '1': | ||
dot(); | ||
dash(); | ||
dash(); | ||
dash(); | ||
dash(); | ||
break; | ||
case '2': | ||
dot(); | ||
dot(); | ||
dash(); | ||
dash(); | ||
dash(); | ||
break; | ||
case '3': | ||
dot(); | ||
dot(); | ||
dot(); | ||
dash(); | ||
dash(); | ||
break; | ||
case '4': | ||
dot(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
dash(); | ||
break; | ||
case '5': | ||
dot(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
break; | ||
case '6': | ||
dash(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
break; | ||
case '7': | ||
dash(); | ||
dash(); | ||
dot(); | ||
dot(); | ||
dot(); | ||
break; | ||
case '8': | ||
dash(); | ||
dash(); | ||
dash(); | ||
dot(); | ||
dot(); | ||
break; | ||
case '9': | ||
dash(); | ||
dash(); | ||
dash(); | ||
dash(); | ||
dot(); | ||
break; | ||
case ' ': | ||
delay(wait * 5); //wait 7 units of time if there is a space (1 from the last character, 5 here and 1 in the loop) | ||
default: | ||
break; | ||
} | ||
} | ||
``` | ||
## Hero shot | ||
<video controls autoplay loop style="display: block; margin: auto;"> | ||
<source src="../../../video/day04.mp4" type="video/mp4"> | ||
</video> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters