0

私はArduinoに非常に慣れておらず、例を試しています。次のコードを使用すると、いくつかの問題が発生します。

#include <ctype.h>
#include <Arduino.h>
#include "Telegraph.h"
//#include <Telegraph.h>

char* LETTERS[]  =  {
  ".-", "-...", "-.-.", "-..", ".",      // A-E
  "..-.", "--.", "....", "..", ".---",   // F-J
  "-.-", ".-..", "--", "-.", "---",      // K-O
  ".--.", "--.-", ".-.", "...", "-",     // P-T
  "..-", "...-", ".--", "-..-", "-.--",  // U-Y
  "--.."                                 // Z
};

char* DIGITS[]  =  {
  "-----", ".----", "..---", "...--",     //0-3
  "....-", ".....", "-....", "--...",     //4-7
  "---..", "----."                        //8-9
};

Telegraph::Telegraph(const int outputPin, const int ditLength){
  _outputPin  =  outputPin;
  _ditLength  =  ditLength;
  _dahLength  =  dahLength;
  pinMode(_outputPin, OUTPUT);
}

void Telegraph::outputCode(const char* code){
  for(int i=0; i<strlen(code); i++){
    if( code[i]  ==  '.' )
      dit();
    else
      dah();
  }
}

void Telegraph::dit(){
  Serial.print(".");
  outputSymbol(_ditLength);
}

void Telegraph::dah(){
  Serial.print("-");
  outputSymbol(_dahLength);
}

void Telegraph::outputSymbol(const int length){
  digitalWrite(_outputPin, HIGH);
  delay(length);
  digitalWrite(_outputPin, LOW);
  delay(length);
}

void Telegraph::sendMessage(const char* message){
  for(int i=0;  i  <  strlen(message); i++){
    const char currentChar  =  toupper(message[i]);
    if( isalpha(currentChar) ){
      outputCode(LETTERS[currentChar  -  'A']);
      delay(_dahLength);
    }else if(isdigit(currentChar) ){
      outputCode(DIGITS[currentChar  -  '0']);
      delay(_dahLength);
    }else if(currentChar  =  ' '){
      Serial.print(" ");
      delay(_ditLength * 7);
    }
  }
  Serial.println();
}

次のエラーが発生します。

Telegraph.cpp:6:15: error: two or more data types in declaration of ‘LETTERS’
Telegraph.cpp: In constructor ‘Telegraph::Telegraph(int, int)’:
Telegraph.cpp:24:18: error: ‘dahLength’ was not declared in this scope
Telegraph.cpp: In member function ‘void Telegraph::sendMessage(const char*)’:
Telegraph.cpp:58:18: error: ‘LETTERS’ was not declared in this scope
Telegraph.cpp:63:30: error: assignment of read-only variable ‘currentChar’

この質問が一般的すぎる場合は申し訳ありませんが、私が述べたように、私は非常に新しく、コードを完全には理解していません。

4

1 に答える 1

0

Telegraph.cpp:6:15:エラー:「LETTERS」の宣言に2つ以上のデータ型があります</ p>

他の場所で、シンボルLETTERSはすでに定義されています。おそらくTelegraph.h?あなたはそれを探す必要があります。

Telegraph.cpp: In constructor ‘Telegraph::Telegraph(int, int)’:
Telegraph.cpp:24:18: error: ‘dahLength’ was not declared in this scope

関連するコード:

  _dahLength  =  dahLength;

はい、dahLengthどこにも定義されていません。おそらく、これを別のパラメーターとしてコンストラクターに追加したいと思いますか?

Telegraph.cpp: In member function ‘void Telegraph::sendMessage(const char*)’:
Telegraph.cpp:58:18: error: ‘LETTERS’ was not declared in this scope

その問題については上記を参照してください。最初の問題を解決し、これを長い間無視してください。

Telegraph.cpp:63:30: error: assignment of read-only variable ‘currentChar’

これは、に起因するものです

}else if(currentChar  =  ' '){

==の代わりに使用したいと思います=

于 2012-07-23T11:48:56.890 に答える