[UNO] 为开发板Arduino UNO编译时出错

[复制链接]
657|10
 楼主 | 2018-7-5 13:04 | 显示全部楼层 |阅读模式
由于初学,实在看不出来到底为什么老是编译失败,求各位大神的指导

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

  8. }
复制代码

Light.h
  1. #ifndef Light_h
  2. #define Light_h
  3. #include"Arduino.h"

  4. class Light{
  5.   public:
  6.   Light(int R,int G,int B);
  7.   void on(char on[]);
  8.   void off();
  9.   void self(int Ranalog,int Ganalog,int Banalog);
  10.   private:
  11.   int Red;
  12.   int Blue;
  13.   int Green;
  14. };
  15. #endif
复制代码

Light.cpp
  1. #include"Arduino.h"
  2. #include"Light.h"
  3.   Light::Light(int R,int G,int B){
  4.     int Red=R;
  5.     int Blue=B;
  6.     int Green=G;
  7.     pinMode(Red,OUTPUT);
  8.     pinMode(Blue.OUTPUT);
  9.     pinMode(Green,OUTPUT);
  10.   }
  11.   void Light::on(char on[]){
  12.     if(on[0]=="R"){
  13.       digitalWrite(Red,HIGH);
  14.       digitalWrite(Blue,LOW);
  15.       digitalWrite(Green,LOW);
  16.     }  
  17.     if(on[0]=="G"){
  18.       digitalWrite(Red,LOW);
  19.       digitalWrite(Blue,LOW);
  20.       digitalWrite(Green,HIGH);
  21.     }
  22.     if(on[0]=="B"){
  23.       digitalWrite(Red,LOW);
  24.       digitalWrite(Blue,HIGH);
  25.       digitalWrite(Green,LOW);
  26.     }
  27.     if(on[0]=="Y"){
  28.       digitalWrite(Red,HIGH);
  29.       digitalWrite(Blue,LOW);
  30.       digitalWrite(Green,HIGH);
  31.     }  
  32.     if(on[0]=="P"){
  33.       digitalWrite(Red,HIGH);
  34.       digitalWrite(Blue,HIGH);
  35.       digitalWrite(Green,LOW);
  36.     }  
  37.     if(on[0]=="C"){
  38.       digitalWrite(Red,LOW);
  39.       digitalWrite(Blue,HIGH);
  40.       digitalWrite(Green,HIGH);
  41.     }  
  42.     if(on[0]=="W"){
  43.       digitalWrite(Red,HIGH);
  44.       digitalWrite(Blue,HIGH);
  45.       digitalWrite(Green,HIGH);
  46.     }  
  47.   }
  48.   void Light::off(){
  49.     digitalWrite(Red,LOW);
  50.     digitalWrite(Blue,LOW);
  51.     digitalWrite(Green,LOW);
  52.   }
  53.   
  54.   void Light::self(int Ranalog,int Ganalog,int Banalog){
  55.     if(Red!=11||Red!=10||Red!=9||Red!=6||Red!=5||Red!=3){
  56.       if(Ranalog<=512){
  57.         digitalWrite(Red,LOW);
  58.       }
  59.       else{
  60.         digitalWrite(Red,HIGH);
  61.       }
  62.     }
  63.     else{
  64.       analogWrite(Red,Ranalog);
  65.     }
  66.     if(Blue!=11||Blue!=10||Blue!=9||Blue!=6||Blue!=5||Blue!=3){
  67.       if(Banalog<=512){
  68.         digitalWrite(Blue,LOW);
  69.       }
  70.       else{
  71.         digitalWrite(Blue,HIGH);
  72.       }
  73.     }
  74.     else{
  75.       analogWrite(Blue,Banalog);
  76.     }
  77.     if(Green!=11||Green!=10||Green!=9||Green!=6||Green!=5||Green!=3){
  78.       if(Ganalog<=512){
  79.         digitalWrite(Green,LOW);
  80.       }
  81.       else{
  82.         digitalWrite(Green,HIGH);
  83.       }
  84.     }
  85.     else{
  86.       analogWrite(Green,Ganalog);
  87.     }
  88.   }
  89.   
复制代码
 楼主 | 2018-7-5 13:05 | 显示全部楼层
这是自己编的想实现控制RGB的一个库,却在使用时总是编译失败

评论

dirtwillfly 2018-7-5 14:23 回复TA
什么错误提示?发上来看看 
| 2018-7-5 15:35 | 显示全部楼层
贴个编译时的图看看
 楼主 | 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 编译时出错。
 楼主 | 2018-7-8 16:39 | 显示全部楼层
上面是错误信息
| 2018-7-8 22:03 | 显示全部楼层

上面有错误提示,根据定位的行,逐条看看是不是确定有问题
| 2018-7-8 22:03 | 显示全部楼层
08.    pinMode(Blue.OUTPUT);

应该是逗号 pinMode(Blue,OUTPUT);
| 2018-7-15 10:48 | 显示全部楼层
| 2018-7-28 10:44 | 显示全部楼层
点赞
| 2018-8-22 21:55 | 显示全部楼层
我以前用在Sublime Text下编写并通过编译的代码,放到Codeblocks下编译,死活通不过,至今也不知道原因。两个编程工具都可以编写Arduino程序,只能用哪个编写,就用哪个编译生成。
扫描二维码,随时随地手机跟帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复

您需要登录后才可以回帖
登录 | 注册
高级模式
我要创建版块 申请成为版主

论坛热帖

关闭

热门推荐上一条 /4 下一条

快速回复 返回顶部 返回列表