Introduction: 解讀摩斯密碼!(使用Arduino和簡單配件)

摩斯密碼簡介:

摩斯密碼,電信代碼的最早形式之一。這種代碼形式是以其發明者塞繆爾·摩斯(Samuel Morse)的名字命名的。在創建電話之後,這種發明緊隨其後。在這種密碼中它使用的是點和線,不同的組合也表示著不同的英文字母和阿拉伯數字。

簡要分析整個產品及其運作方式:

首先,用戶將能夠輸入他們想要的字串在序列埠中。收到輸入字串後,Arduino將會對其進行處理。液晶顯示螢幕將一個字母一個字母的顯示出使用者輸入的單詞或字句。紅色LED代表點,另一個綠色的LED代表線(本篇所使用的LED顏色,每個人也可以將顏色隨意的更改!)。同時,蜂鳴器會根據點和線發出不同時長的蜂鳴聲。

這是一個衍生自其他人創作的作品,可以將此網站作為我作品的參考:

https://www.instructables.com/Morse-code-with-ardu...

我所添加的額外功能:

  1. LCD 顯示螢幕:我增加此功能是為了使用者的便利性,使用者可以不用邊看電腦邊看LED燈閃爍。LCD螢幕在最後還會顯示出完整的字串讓使用者更清楚的看懂。
  2. 字串顯示時間:原本的程式中字串會在亮完LED燈後才顯示,這會使不懂摩斯密碼的人感到毫無頭緒不知道LED在表示甚麼字母或數字。
  3. 聲音:我加了原本沒有的蜂鳴器,摩斯密碼最初就是通過聲音來和電波來傳送的,加了聲音的效果想必會讓整個系統更加的完善。
  4. 另一個LED:在原本就有的LED之上我又多加了一個新的,原本長短燈號都是用一個LED顯示的,這樣很難分辨不同的訊號,再加上一個LED就可以讓使用者用起來更方便,長、短訊號的區別也因此而更加明顯。

我添加了以上所陳述的功能,希望你會喜歡這個作品和莫爾斯密碼!

Step 1: 準備材料

這項作品所使用的材料都非常簡單和容易取得。

  1. 兩個LED
  2. 一個蜂鳴器
  3. 一個LCD顯示螢幕
  4. Arduino
  5. 麵包板
  6. 裝飾盒
  7. 用於處理程式的電腦

Step 2: 連接零件!

這一步很簡單,只要按照上面的電路接線就可以了!

  1. LED 長腳接 D-pin 短腳接 gnd
  2. 蜂鳴器紅線接 D-pin 黑線接 gnd
  3. LCD:
    1. VCC 接 5V
    2. gnd 接 gnd(地)
    3. SDA and SCA 分別接到 Arduino 上對應的角位

Step 3: 裝飾裝置

這裡我使用的是紙盒進行包裝,真的沒有很好看,你們可以選擇或使用任何的裝飾品來裝飾你們的裝置。

Step 4: 我的程式碼

#include <Wire.h> // 改
#include <LiquidCrystal_I2C.h> //改
LiquidCrystal_I2C lcd_I2C_27(0x27,16,2); //改
int led =13;//the led pin
int led2 = 12;// 改
int buzzer = 11;//改
int a = 0; //改
char input;// to save the input
void setup () {
  pinMode (led,OUTPUT);//tell that the 13 pin is an output
  pinMode (led2,OUTPUT);//改
  pinMode(buzzer, OUTPUT);//改
  lcd_I2C_27.init (); // 改
  lcd_I2C_27.backlight(); //改
  Serial.begin(9600);//for the connect with the boared
  lcd_I2C_27.clear(); // 改
} 

void loop () {
  if (Serial.available()) {
    input = Serial.read();//read the input
    lcd_I2C_27.setCursor(a , 0) ; // 改
    a += 1; //改
    lcd_I2C_27.print(input); // 改
    if (input == 'a' || input == 'A') {lA();}//if the input is a or A go to function lA
    if (input == 'b' || input == 'B') {lB();}//same but with b letter
    if (input == 'c' || input == 'C') {lC();}
    if (input == 'd' || input == 'D') {lD();}
    if (input == 'e' || input == 'E') {lE();}
    if (input == 'f' || input == 'F') {lF();}
    if (input == 'g' || input == 'G') {lG();}
    if (input == 'h' || input == 'H') {lH();}
    if (input == 'i' || input == 'I') {lI();}
    if (input == 'j' || input == 'J') {lJ();}
    if (input == 'k' || input == 'K') {lK();}
    if (input == 'l' || input == 'L') {lL();}
    if (input == 'm' || input == 'M') {lM();}
    if (input == 'n' || input == 'N') {lN();}
    if (input == 'o' || input == 'O') {lO();}
    if (input == 'p' || input == 'P') {lP();}
    if (input == 'q' || input == 'Q') {lQ();}
    if (input == 'r' || input == 'R') {lR();}
    if (input == 's' || input == 'S') {lS();}
    if (input == 't' || input == 'T') {lT();}
    if (input == 'u' || input == 'U') {lU();}
    if (input == 'v' || input == 'V') {lV();}
    if (input == 'w' || input == 'W') {lW();}
    if (input == 'x' || input == 'X') {lX();}
    if (input == 'y' || input == 'Y') {lY();}
    if (input == 'z' || input == 'Z') {lZ();}
    if (input == '1') {n1();}// the numbers
    if (input == '2') {n2();}
    if (input == '3') {n3();}
    if (input == '4') {n4();}
    if (input == '5') {n5();}
    if (input == '6') {n6();}
    if (input == '7') {n7();}
    if (input == '8') {n8();}
    if (input == '9') {n9();}
    if (input == '0') {n0();}
    if (input == ' ') {space();}//the space
    Serial.println (input);//print the latter saved in the input var
  }
}
//fonctions for the letters and the numbers
void lA () {dot();dash();shortspace();}//letter A in morse code!
void lB () {dash();dot();dot();dot();shortspace();}//same for B
void lC () {dash();dot();dash();dot();shortspace();}
void lD () {dash();dot();dot();shortspace();}
void lE () {dot();shortspace();}
void lF () {dot();dot();dash();dot();shortspace();}
void lG () {dash();dash();dot();shortspace();}
void lH () {dot();dot();dot();dot();shortspace();}
void lI () {dot();dot();shortspace();}
void lJ () {dot();dash();dash();dash();shortspace();}
void lK () {dash();dot();dash();shortspace();}
void lL () {dot();dash();dot();dot();shortspace();}
void lM () {dash();dash();shortspace();}
void lN () {dash();dot();shortspace();}
void lO () {dash();dash();dash();shortspace();}
void lP () {dot();dash();dash();dot();shortspace();}
void lQ () {dash();dash();dot();dash();shortspace();}
void lR () {dot();dash();dot();shortspace();}
void lS () {dot();dot();dot();shortspace();}
void lT () {dash();shortspace();}
void lU () {dot();dot();dash();shortspace();}
void lV () {dot();dot();dot();dash();shortspace();}
void lW () {dot();dash();dash();shortspace();}
void lX () {dash();dot();dot();dash();shortspace();}
void lY () {dash();dot();dash();dash();shortspace();}
void lZ () {dash();dash();dot();dot();shortspace();}
void n1 () {dot();dash();dash();dash();dash();shortspace();}//number 1 in morse code
void n2 () {dot();dot();dash();dash();dash();shortspace();}
void n3 () {dot();dot();dot();dash();dash();shortspace();}
void n4 () {dot();dot();dot();dot();dash();shortspace();}
void n5 () {dot();dot();dot();dot();dot();shortspace();}
void n6 () {dash();dot();dot();dot();dot();shortspace();}
void n7 () {dash();dash();dot();dot();dot();shortspace();}
void n8 () {dash();dash();dash();dot();dot();shortspace();}
void n9 () {dash();dash();dash();dash();dot();shortspace();}
void n0 () {dash();dash();dash();dash();dash();shortspace();}
void space () {delay (1200);}//space between words
void dot () {digitalWrite(led,HIGH); tone(buzzer, 500); delay (100); digitalWrite(led,LOW); noTone(buzzer); delay (200);}//改
void dash () {digitalWrite(led2,HIGH); tone(buzzer, 500); delay (300); digitalWrite(led2,LOW); noTone(buzzer); delay (200);}//改
void shortspace () {delay(600);}//改

Step 5: 最終成果

在複製完成式後就可以開始程式然後進到到序列埠中輸入你想要的字串!

STEM Contest

Participated in the
STEM Contest