Arduino在结构

时间:2017-08-05 17:00:31

标签: arrays struct arduino

我的代码中有以下结构:

struct digitalDataStruct {
    unsigned long timestamp;
    int digitalData;
};

struct analogDataStruct {
    unsigned long timestamp;
    int analogData[16];
};

struct structWithPositionAndCo {
    const int sizeOfDigital = 1000;
    const int sizeOfAnalog = 10;
    digitalDataStruct sensorValuesDigital[];
    analogDataStruct sensorValuesAnalog[];
    int digitalPosition = 0;
    int analogPosition = 0;
    int lastDigitalWriteToPC = 0;
    int lastAnalogWriteToPC = 0;
};

现在我想创建digitalDataStruct的数组和analogDataStruct。

structPackage.sensorValuesAnalog = new analogDataStruct[structPackage.sizeOfAnalog]; // array to store the value coming from the sensor
structPackage.sensorValuesDigital = new digitalDataStruct[structPackage.sizeOfDigital]; // array to store the value coming from the sensor

但我仍然遇到此错误:

incompatible types in assignment of 'analogDataStruct*' to 'analogDataStruct [0]'

任何线索?

1 个答案:

答案 0 :(得分:1)

您可以将digitalDataStruct和analogDataStruct成员指向这些相应类型而不是数组。如果不是可以硬编码的已知值,您还需要每个成员变量以跟踪每个项目中的项目数量。

struct structWithPositionAndCo {
const int sizeOfDigital = 1000;
const int sizeOfAnalog = 10;
digitalDataStruct* sensorValuesDigital;
analogDataStruct* sensorValuesAnalog;
int digitalPosition = 0;
int analogPosition = 0;
int lastDigitalWriteToPC = 0;
int lastAnalogWriteToPC = 0;

};