|
本帖最后由 topdog 于 2021-12-4 20:20 编辑
attachInterrupt(0, blink,FALLING);是中断函数的简略写法,这里不建议这样写,参数多了你自己被搞晕了!此函数不带参数,没有返回值,state1++毫无意义,因为state自加永远不会等价0。volatile bool state 定义比较合理。
[pre]const int SensorLED = 13;
const int SensorLED1 = 12;
const int SensorINPUT = 2;
const int SensorINPUT1 = 3;
volatile bool state = LOW;
volatile bool state1 = LOW;
void setup() {
pinMode(SensorLED, OUTPUT);
pinMode(SensorLED1, OUTPUT);
pinMode(SensorINPUT, INPUT_PULLUP);
pinMode(SensorINPUT1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SensorINPUT), blink, FALLING);
attachInterrupt(digitalPinToInterrupt(SensorINPUT1), blink1, FALLING);
}
void loop() {
digitalWrite(SensorLED, state);
digitalWrite(SensorLED1, state1);
}
void blink() {
state = !state;
}
void blink1() {
state1 = !state1;
}[/pre]
|
|