使用Arduino IDE,我试图为控制按钮的对象使用结构。
我将fillAndFire.pin
的值分配为14。
fillAndFire.pin = 14;
稍后,代码会将值重新分配为零,但不应这样做。
displayLine[i] = displayLine[i-1];
完整代码:
char* displayLine[15];
struct Buttons{
int pin;
int lightPin;
bool io;
bool pressed;
uint8_t* bName;
} fillAndFire;
void setup() {
//start Serial service
Serial.begin(9600);
while (!Serial){
delay(1);
}
//define pin
fillAndFire.pin = 14;
//message 1 gives a value of 14
Serial.print("fillAndFire.pin 1 = ");Serial.println(fillAndFire.pin);
//mysteriously, this changes the value of Buttons fillAndFire.pin from 14 to 0
//if I change the 15 to 14, it does not affect the fillAndFire.pin variable.
//other numbers, like "1" works just fine, but not 2, 3 or 14
//even other assignments, like "fillAndFire.lightpin = 14" works?!?!?!
displayLine[15] = displayLine[13];
//message 4 gives a value of 0,
//but it has not be explicitly reassigned
Serial.print("fillAndFire.pin 4 = ");Serial.println(fillAndFire.pin);
}
void loop() {
}
答案 0 :(得分:2)
我不知道是否会受到以下影响,但是似乎您有一个15长度的displayLine[0..14]
向量,即displayLine[15]
,并且在赋值的for循环中,在第一次迭代中将会发生for(int i = 14; ...)
不存在的情况。在计算机中,这应该会导致分段错误,但是在Arduino中,这可能是原因。尝试to_date