首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino初学者问题

Arduino初学者问题
EN

Stack Overflow用户
提问于 2012-07-23 07:35:06
回答 1查看 4.1K关注 0票数 0

我对Arduino是个新手,而且还在用例子做实验。在使用以下代码时,我遇到了一些问题:

代码语言:javascript
复制
#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();
}

我得到以下错误:

代码语言:javascript
复制
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’

如果这个问题太笼统,我很抱歉,但正如我前面提到的,我是个新手,不完全理解代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-23 19:48:57

Telegraph.cpp:6:15:错误:“LETTERS”的声明中有两个或多个数据类型

在其他地方,符号LETTERS已经被定义了。也许是在Telegraph.h?你必须去寻找它。

代码语言:javascript
复制
Telegraph.cpp: In constructor ‘Telegraph::Telegraph(int, int)’:
Telegraph.cpp:24:18: error: ‘dahLength’ was not declared in this scope

相关代码:

代码语言:javascript
复制
  _dahLength  =  dahLength;

是的,dahLength没有定义。也许您想将其作为另一个参数添加到构造函数中?

代码语言:javascript
复制
Telegraph.cpp: In member function ‘void Telegraph::sendMessage(const char*)’:
Telegraph.cpp:58:18: error: ‘LETTERS’ was not declared in this scope

关于这个问题,请看上面的。解决第一个问题,忽略这个问题很久了。

代码语言:javascript
复制
Telegraph.cpp:63:30: error: assignment of read-only variable ‘currentChar’

这是由于

代码语言:javascript
复制
}else if(currentChar  =  ' '){

我确信您想使用==而不是=

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11604865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档