计算机初学小白 2022-09-24 17:48 采纳率: 0%
浏览 44

如何在软件上编辑迎宾机器人的程序,出现错误?

在arduio软件上编辑迎宾机器人的程序,出现错误,

代码:

#include <SoftwareSerial.h>
#include<Servo.h>
Servo myServo;
myServo.attach(11);
SoftwareSerial Serial1(10,4);     
int b = 0;             
void mp3_volume(uint8_t level){
  uint8_t sum = level + 0xBE;
  uint8_t volume [5] = {0xAA,0x13,0x01,level,sum};
  Serial1.write(volume,5);
}
void mp3_play_chapter(uint16_t chapter){
  uint8_t chapter_h = chapter >> 8;
  uint8_t chapter_l = chapter;
  uint8_t sum = 0xB3 + chapter_h + chapter_l;
  uint8_t play_chapter[6] = {0xAA,0x07,0x02,chapter_h,chapter_l,sum};
  Serial1.write(play_chapter,6);
}
void setup(){
  Serial1.begin(9600);
  Serial.begin(9600);
  pinMode(2,OUTPUT);
  pinMode(3,INPUT);
  servo.write(90);
  delay(100);
}
void loop(){
  chaoshengbuo();
  Serial.println(a);
  if(a >= 10 && a < 15){
    if(b > a){
      myServo.write(180);
      mp3_volume(30);                       
      mp3_play_chapter(26);            
      delay(2000); 
    }
  }
  else if(a >= 15 && a < 20){
    if(b < a){
      myServo.write(180);
      mp3_volume(30);                       
      mp3_play_chapter(50);
      mp3_play_chapter(25);                 
      delay(1500);
      mp3_play_chapter(59);      
    }
  }
}
void chaoshengbuo(){
  digitalWrite(2,LOW);
  delayMicroseconds(2);
  digitalWrite(2,HIGH);
  delayMicroseconds(10);
  digitalWrite(2,LOW);
  int a = pulseIn(3,HIGH)/58.0;
}

报错:
Arduino:1.8.5 (Windows 10), 开发板:"Arduino/Genuino Uno"

sketch_sep24a:4: error: 'myServo' does not name a type

myServo.attach(11);

^

C:\Users\dell\Desktop\sketch_sep24a\sketch_sep24a.ino: In function 'void setup()':

sketch_sep24a:24: error: 'servo' was not declared in this scope

servo.write(90);

^

C:\Users\dell\Desktop\sketch_sep24a\sketch_sep24a.ino: In function 'void loop()':

sketch_sep24a:29: error: 'a' was not declared in this scope

Serial.println(a);

              ^

exit status 1
'myServo' does not name a type

在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。

  • 写回答

1条回答 默认 最新

  • qllaoda 2022-09-24 18:12
    关注

    第4行,是运行语句,不能写在函数外。
    24行,servo没有定义过,你是想用你你前面定义的那个myServo吧?

    评论

报告相同问题?

问题事件

  • 创建了问题 9月24日

悬赏问题

  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站