打印
[UNO]

为开发板Arduino UNO编译时出错

[复制链接]
9280|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
叶子Xiaoyao|  楼主 | 2018-7-5 13:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
由于初学,实在看不出来到底为什么老是编译失败,求各位大神的指导

主程序代码:
#include"Light.h"
#include"Arduino.h"
Light light(13,11,12);
void setup() {
}
void loop() {
  light.on("Pink");

}

Light.h
#ifndef Light_h
#define Light_h
#include"Arduino.h"

class Light{
  public:
  Light(int R,int G,int B);
  void on(char on[]);
  void off();
  void self(int Ranalog,int Ganalog,int Banalog);
  private:
  int Red;
  int Blue;
  int Green;
};
#endif

Light.cpp
#include"Arduino.h"
#include"Light.h"
  Light::Light(int R,int G,int B){
    int Red=R;
    int Blue=B;
    int Green=G;
    pinMode(Red,OUTPUT);
    pinMode(Blue.OUTPUT);
    pinMode(Green,OUTPUT);
  }
  void Light::on(char on[]){
    if(on[0]=="R"){
      digitalWrite(Red,HIGH);
      digitalWrite(Blue,LOW);
      digitalWrite(Green,LOW);
    }  
    if(on[0]=="G"){
      digitalWrite(Red,LOW);
      digitalWrite(Blue,LOW);
      digitalWrite(Green,HIGH);
    }
    if(on[0]=="B"){
      digitalWrite(Red,LOW);
      digitalWrite(Blue,HIGH);
      digitalWrite(Green,LOW);
    }
    if(on[0]=="Y"){
      digitalWrite(Red,HIGH);
      digitalWrite(Blue,LOW);
      digitalWrite(Green,HIGH);
    }  
    if(on[0]=="P"){
      digitalWrite(Red,HIGH);
      digitalWrite(Blue,HIGH);
      digitalWrite(Green,LOW);
    }  
    if(on[0]=="C"){
      digitalWrite(Red,LOW);
      digitalWrite(Blue,HIGH);
      digitalWrite(Green,HIGH);
    }  
    if(on[0]=="W"){
      digitalWrite(Red,HIGH);
      digitalWrite(Blue,HIGH);
      digitalWrite(Green,HIGH);
    }  
  }
  void Light::off(){
    digitalWrite(Red,LOW);
    digitalWrite(Blue,LOW);
    digitalWrite(Green,LOW);
  }
  
  void Light::self(int Ranalog,int Ganalog,int Banalog){
    if(Red!=11||Red!=10||Red!=9||Red!=6||Red!=5||Red!=3){
      if(Ranalog<=512){
        digitalWrite(Red,LOW);
      }
      else{
        digitalWrite(Red,HIGH);
      }
    }
    else{
      analogWrite(Red,Ranalog);
    }
    if(Blue!=11||Blue!=10||Blue!=9||Blue!=6||Blue!=5||Blue!=3){
      if(Banalog<=512){
        digitalWrite(Blue,LOW);
      }
      else{
        digitalWrite(Blue,HIGH);
      }
    }
    else{
      analogWrite(Blue,Banalog);
    }
    if(Green!=11||Green!=10||Green!=9||Green!=6||Green!=5||Green!=3){
      if(Ganalog<=512){
        digitalWrite(Green,LOW);
      }
      else{
        digitalWrite(Green,HIGH);
      }
    }
    else{
      analogWrite(Green,Ganalog);
    }
  }
  

相关帖子

沙发
叶子Xiaoyao|  楼主 | 2018-7-5 13:05 | 只看该作者
这是自己编的想实现控制RGB的一个库,却在使用时总是编译失败

使用特权

评论回复
评论
dirtwillfly 2018-7-5 14:23 回复TA
什么错误提示?发上来看看 
板凳
hbzjt2011| | 2018-7-5 15:35 | 只看该作者
贴个编译时的图看看

使用特权

评论回复
地板
叶子Xiaoyao|  楼主 | 2018-7-8 16:38 | 只看该作者
Arduino:1.8.5 (Windows 7), 开发板:"Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712 -warnings=all -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_753323 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Administrator\Documents\Arduino\sketch_jul04a\sketch_jul04a.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712 -warnings=all -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_753323 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Administrator\Documents\Arduino\sketch_jul04a\sketch_jul04a.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\sketch_jul04a.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp" -o "nul"
Generating function prototypes...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\sketch_jul04a.ino.cpp" -o "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\preproc\ctags_target_for_gcc_minus_e.cpp"
正在编译项目...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp" -o "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp.o"
In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:1:0:

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp: In constructor 'Light::Light(int, int, int)':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:44:16: error: expected unqualified-id before numeric constant

#define OUTPUT 0x1

                ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:8:18: note: in expansion of macro 'OUTPUT'

     pinMode(Blue.OUTPUT);

                  ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp: In member function 'void Light::on(char*)':

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:12:15: warning: comparison with string literal results in unspecified behaviour [-Waddress]

     if(on[0]=="R"){

               ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:12:15: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:17:15: warning: comparison with string literal results in unspecified behaviour [-Waddress]

     if(on[0]=="G"){

               ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:17:15: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:22:15: warning: comparison with string literal results in unspecified behaviour [-Waddress]

     if(on[0]=="B"){

               ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:22:15: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:27:15: warning: comparison with string literal results in unspecified behaviour [-Waddress]

     if(on[0]=="Y"){

               ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:27:15: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:32:15: warning: comparison with string literal results in unspecified behaviour [-Waddress]

     if(on[0]=="P"){

               ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:32:15: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:37:15: warning: comparison with string literal results in unspecified behaviour [-Waddress]

     if(on[0]=="C"){

               ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:37:15: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:42:15: warning: comparison with string literal results in unspecified behaviour [-Waddress]

     if(on[0]=="W"){

               ^

C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_143712\sketch\Light.cpp:42:15: warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

exit status 1
为开发板 Arduino/Genuino Uno 编译时出错。

使用特权

评论回复
5
叶子Xiaoyao|  楼主 | 2018-7-8 16:39 | 只看该作者
上面是错误信息

使用特权

评论回复
6
dirtwillfly| | 2018-7-8 22:03 | 只看该作者

上面有错误提示,根据定位的行,逐条看看是不是确定有问题

使用特权

评论回复
7
redleaves| | 2018-7-8 22:03 | 只看该作者
08.    pinMode(Blue.OUTPUT);

应该是逗号 pinMode(Blue,OUTPUT);

使用特权

评论回复
8
gxncjlg| | 2018-7-15 10:48 | 只看该作者

使用特权

评论回复
9
似水若云| | 2018-7-28 10:44 | 只看该作者
点赞

使用特权

评论回复
10
nuaabob| | 2018-8-22 21:55 | 只看该作者
我以前用在Sublime Text下编写并通过编译的代码,放到Codeblocks下编译,死活通不过,至今也不知道原因。两个编程工具都可以编写Arduino程序,只能用哪个编写,就用哪个编译生成。

使用特权

评论回复
11
cqs16800| | 2018-12-25 13:12 | 只看该作者
redleaves 发表于 2018-7-8 22:03
08.    pinMode(Blue.OUTPUT);

应该是逗号 pinMode(Blue,OUTPUT);

老大,这你都能马上看出来

使用特权

评论回复
12
qiuchenchat| | 2019-1-2 23:12 | 只看该作者
redleaves 发表于 2018-7-8 22:03
08.    pinMode(Blue.OUTPUT);

应该是逗号 pinMode(Blue,OUTPUT);

大佬 真厉害

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

4

帖子

0

粉丝