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 订阅和发布信号
原文地址:https://www.cnblogs.com/kekeoutlook/p/8504487.html
时间: 2024-11-06 07:39:58