<分区>
我正在尝试使用 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() {
}