2015-02-06 115 views
1

我想在20个传感器上使用arduino mega做一个typedef struct(或类似的,如果我不能),但是我有一个错误,我不明白为什么。是从arduino编译还是从我的代码?你认为我必须把我的代码放在一个头文件中吗?在Arduino上的typedef结构:变量没有命名一个类型

typedef struct { 
      char nom[8]; 
      int pin; 
      int onOff; 
      int pente; 
      int offset; 
      int maximun; 
      int minimum; 
      int constante1; 
      int constante2; 
      int hyst1; 
      int hyst2; 
      float moyenne; 
      float valeurs[]; 
      int frequence; 
     } structSondes; 

    structSondes sondes[20]; 
    structSondes test; 
    sondes[0].pin=1; 
    test.pin=1; 

我对编译此错误:

error: ‘sondes’ does not name a type

error: ‘test’ does not name a type

+1

错误,它显示'sonde'或'sondes'?此外,'float valeurs [];'必须结束(按照'C99')。 – 2015-02-06 13:31:51

+0

@SouravGhosh对不起,这是“探空仪” – sebastien 2015-02-06 13:37:53

回答

3

您没有提供您完整的代码,所以它可能只是猜测。

我怀疑问题是,语句:

sondes[0].pin=1; 
test.pin=1; 

都写在鲍文件的主体,而不是一个函数内部。

+0

谢谢,我想我累了。这是一个愚蠢的错误...... – sebastien 2015-02-06 14:58:19

+0

这是为什么呢?该结构实体只能在函数内部分配? – Noel 2017-04-01 17:21:26