【发布时间】:2021-12-27 04:46:25
【问题描述】:
我有一个 ATtiny85,我使用 sparkfun 程序员 (https://www.sparkfun.com/products/11801) 进行编程,我使用的 ATTiny Board Manager 是:https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
以下是我的代码,当我将引脚 2 接地时,我无法让中断工作。 我已经测试过 LED 确实在中断之外(循环内)工作。欢迎提出任何建议。
#include "Arduino.h"
#define interruptPin 2
const int led = 3;
bool lastState = 0;
void setup() {
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(interruptPin, pulseIsr, CHANGE);
pinMode(led, OUTPUT);
}
void loop() {
}
void pulseIsr() {
if (!lastState) {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
lastState = 1;
}
else {
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
lastState = 0;
}
}
【问题讨论】: