1 按键触摸LED
#define GPIO_PIN 14 // 14--D5 不要上拉电阻
// 板载led --D4 --2 号 有上拉电阻 给低电平是亮的
uint8_t led = LOW;
void setup(){
pinMode(GPIO_PIN, INPUT);
pinMode(BUILTIN_LED, OUTPUT);
setLED();
attachInterrupt(GPIO_PIN, highInterrupt, RISING);
}
void highInterrupt(){
led = HIGH;
detachInterrupt(GPIO_PIN);
attachInterrupt(GPIO_PIN, lowInterrupt, FALLING);
}
void lowInterrupt(){
led = LOW;
detachInterrupt(GPIO_PIN);
attachInterrupt(GPIO_PIN, highInterrupt, RISING);
}
void setLED(){
digitalWrite(BUILTIN_LED, led);
}
void loop(){
setLED();
}
2 订阅和发布信号