arduino测距程序编译出错-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1157|回复: 2

[已解决] arduino测距程序编译出错

[复制链接]
发表于 2020-12-30 10:59 | 显示全部楼层 |阅读模式
本帖最后由 element115mc 于 2020-12-31 08:33 编辑

第一次玩arduino,想做个测距仪,预期效果:开屏显示“Made by element115mc”,隔2秒刷新一次距离。
结果程序怎么也写不进去,但是随便挑一个示例写进去都行
未标题-1.jpg
系统:Windows10企业版
Arduino版本:1.8.9
开发板:UNO
要搭配的外设: LCD1602A、US-025超声波模块(可兼容HC-SR04)
CH340驱动:已安装
错误信息:
Arduino:1.8.9 (Windows 10), 开发板:"Arduino/Genuino Uno"

D:\arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\arduino\hardware -tools D:\arduino\tools-builder -tools D:\arduino\hardware\tools\avr -built-in-libraries D:\arduino\libraries -libraries d:\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=1A86_7523 -ide-version=10809 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_927525 -warnings=all -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_401094 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=D:\arduino\hardware\tools\avr -verbose D:\desktop\sketch_dec30a\sketch_dec30a.ino
D:\arduino\arduino-builder -compile -logger=machine -hardware D:\arduino\hardware -tools D:\arduino\tools-builder -tools D:\arduino\hardware\tools\avr -built-in-libraries D:\arduino\libraries -libraries d:\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=1A86_7523 -ide-version=10809 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_927525 -warnings=all -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_401094 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=D:\arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=D:\arduino\hardware\tools\avr -verbose D:\desktop\sketch_dec30a\sketch_dec30a.ino
Using board 'uno' from platform in folder: D:\arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: D:\arduino\hardware\arduino\avr
Detecting libraries used...
"D:\\arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10809 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_927525\\sketch\\sketch_dec30a.ino.cpp" -o nul
"D:\\arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10809 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\arduino\\libraries\\LiquidCrystal\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_927525\\sketch\\sketch_dec30a.ino.cpp" -o nul
"D:\\arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10809 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\arduino\\libraries\\LiquidCrystal\\src" "D:\\arduino\\libraries\\LiquidCrystal\\src\\LiquidCrystal.cpp" -o nul
Generating function prototypes...
"D:\\arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10809 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\arduino\\libraries\\LiquidCrystal\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_927525\\sketch\\sketch_dec30a.ino.cpp" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_927525\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"D:\\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_927525\\preproc\\ctags_target_for_gcc_minus_e.cpp"
正在编译项目...
"D:\\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 -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10809 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-ID:\\arduino\\hardware\\arduino\\avr\\cores\\arduino" "-ID:\\arduino\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\arduino\\libraries\\LiquidCrystal\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_927525\\sketch\\sketch_dec30a.ino.cpp" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_927525\\sketch\\sketch_dec30a.ino.cpp.o"
D:\desktop\sketch_dec30a\sketch_dec30a.ino:1:27: warning: extra tokens at end of #include directive

#include <LiquidCrystal.h>;

                           ^

In file included from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_927525\sketch\sketch_dec30a.ino.cpp:1:0:

D:\desktop\sketch_dec30a\sketch_dec30a.ino: In function 'void loop()':

D:\arduino\hardware\arduino\avr\cores\arduino/Arduino.h:41:14: error: expected unqualified-id before numeric constant

#define LOW  0x0

              ^

D:\desktop\sketch_dec30a\sketch_dec30a.ino:25:21: note: in expansion of macro 'LOW'

   digitalWrite(Trig.LOW);

                     ^

使用 1.0.7  版本的库 LiquidCrystal 在文件夹: D:\arduino\libraries\LiquidCrystal
exit status 1
为开发板 Arduino/Genuino Uno 编译时出错。


源代码:
  1. #include <LiquidCrystal.h>;
  2. #define LM35 A0;
  3. #define Trig 8
  4. #define Echo 9
  5. float cm;
  6. LiquidCrystal lcd(12,11,5,4,3,2);
  7. int val = 0;
  8. float Temp = 0;

  9. void setup() {
  10.   lcd.begin(16,2);
  11.   lcd.setCursor(0,0);
  12.   lcd.print("Made by");
  13.   lcd.setCursor(0,1);
  14.   lcd.print("element115mc");
  15.   delay(2000);
  16.   lcd.clear();
  17.   pinMode(Trig,OUTPUT);
  18.   pinMode(Echo,INPUT);
  19. }



  20. void loop() {
  21.   digitalWrite(Trig.LOW);
  22.   delayMicroseconds(2);
  23.   digitalWrite(Trig,HIGH);
  24.   delayMicroseconds(10);
  25.   digitalWrite(Trig,LOW);
  26.   Temp = float(pulseIn(Echo,HIGH));
  27.   cm = (Temp*17)/1000;
  28.   lcd.setCursor(0,0);
  29.   lcd.print(cm);
  30.   lcd.setCursor(0,1);
  31.   lcd.print("centmeter");
  32.   delay(2000);
  33.   

  34. }
复制代码


发表于 2020-12-30 15:29 | 显示全部楼层
第25行的逗号写成了个点
 楼主| 发表于 2020-12-30 17:29 | 显示全部楼层
XlinliY.Zhang 发表于 2020-12-30 15:29
第25行的逗号写成了个点

感谢大佬帮助,程序已成功写入开发板
捕获.PNG 捕获1.PNG
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-29 16:33 , Processed in 0.098340 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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