Arduino:モールス変換器を構築する-仕組み
この実践的なヒントでは、Arduinoでモールストランスレーターを簡単に構築する方法を学びます。
Arduinoを使用したモールストランスレーターの構築-これが必要です
もちろん、まず、Arduinoが必要です。
- また、アクティブなブザーとLEDも点灯するはずです。
- ブザーをピン9に、LEDをピン13に接続します。
Arduino:モールス信号変換プログラム
ここでは、使用できる小さなサンプルコードをプログラムしました。 Arduinoにアップロードして、シリアルモニターを起動するだけです。
- #define debug true
- int ledPin = 13;
- int speakerPin = 9;
- int pitch1 = 140;
- int pitch2 = 140;
- int dot = 50;
- int dash = 3 * dot;
- 文字列morseATable [] = {".-"、 "-..."、 "-.-。"、 "-.."、 "。"、 "..-。"、 "-。"、 "。 ... "、" .. "、" .--- "、" _._ "、" .- .. "、"-"、"-。 "、" --- "、" .-- 。 "、" --.- "、" .-。 "、" ... "、"-"、" ..- "、" ...- "、" .-- "、" -..- "、" -.-- "、"-.. "};
- 文字列morseNTable [] = {"-----"、 ".----"、 "..---"、 "...--"、 "....-"、 "... .. "、" -.... "、" --... "、" --- .. "、" ----。 "};
- void setup(){
- pinMode(ledPin、OUTPUT);
- pinMode(speakerPin、OUTPUT);
- Serial.begin(9600)。
- if(デバッグ){
- Serial.println( "\ n始動");}
- }
- void loop(){
- if(true){
- convert2Morse(Serial.readString())。
- }
- }
- void convert2Morse(文字列メッセージ){
- for(int pos = 0; pos <message.length(); pos ++){
- if(デバッグ){
- Serial.print(message.charAt(POS))。
- Serial.print( "");
- }
- if((message.charAt(pos)> = 97)&&(message.charAt(pos)<= 122)){
- morseLED(morseATable [message.charAt(POS)-97]);}
- if((message.charAt(pos)> = 48)&&(message.charAt(pos)<= 57)){
- morseLED(モールステーブル[メッセージ[POS] -48]);}
- if(message.charAt(pos)== 32){
- morseLED( "");}
- if(デバッグ){
- Serial.println();
- }
- }}
- void morseLED(文字列シーケンス){
- for(int pos = 0; pos <sequence.length(); pos ++){
- FlashLED(sequence.charAt(POS));}
- 遅延(2 *ドット);
- }
- void flashLED(char dotOrDash){
- if(デバッグ){
- Serial.print(dotOrDash);}
- if(dotOrDash == 46){
- digitalWrite(ledPin、HIGH);
- トーン(speakerPin、pitch1);
- 遅延(ドット)。
- digitalWrite(ledPin、LOW);
- noTone(speakerPin)。
- 遅延(ドット)。
- } else if(dotOrDash == 45){
- digitalWrite(ledPin、HIGH);
- トーン(speakerPin、pitch2);
- 遅延(ダッシュ)。
- digitalWrite(ledPin、LOW);
- noTone(speakerPin)。
- 遅延(ドット)。
- } else if(dotOrDash == 32){
- 遅延(ドット);}
- }
次の実用的なヒントでは、ArduinoでGSMモジュールを使用する方法を示します。