繁体   English   中英

Arduino伺服结构“未命名类型”

[英]Arduino servo struct “does not name a type”

我正在尝试运行一个arduino程序,该程序使用包含伺服对象的结构,它给了我这个错误:

error: 'leg' does not name a type

我认为我在内存管理方面做错了事,但是对此我还很陌生,因此可以提供任何帮助。

这是我的代码:

#include <Servo.h> 

typedef struct{
 Servo hip;
 Servo shin;
 Servo foot;
}leg;



int currentPin = 0; //this is the pin that the leg will be attached to


leg getLeg(void){
  leg newLeg;
  newLeg.hip.attach(currentPin++);
  newLeg.shin.attach(currentPin++);
  newLeg.foot.attach(currentPin++);

  return newLeg;  

}

void setup() 
{ 
  leg frontLeft = getLeg();
  leg frontRight = getLeg();
  leg backRight = getLeg();
  leg backLeft = getLeg();
} 


void loop() 
{ 


} 

试试这个

struct legtype {
    Servo hip;
    Servo shin;
    Servo foot;
};

typedef legtype leg;

那样有用吗?

干杯,

在头文件中定义结构可以解决此问题。 在arduino中,创建一个新的标签,名为:“ whatever.h ”,在主文件中的what.h中定义结构。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM