|
- const byte ledPin = 13;
- const byte interruptPin = 2;
- volatile byte state = LOW;
- void setup() {
- pinMode(ledPin, OUTPUT);
- pinMode(interruptPin, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
- }
- void loop() {
- digitalWrite(ledPin, state);
- }
- void blink() {
- state = !state;
- }
复制代码
参考链接: https://www.arduino.cc/en/Reference/AttachInterrupt
|
|