按钮间歇工作(Arduino)

时间:2018-02-07 10:13:52

标签: button arduino led

我正在和Arduino一起玩,我尝试simple circuit,当您使用attachInterrupt()功能按pushbutton时,LED会亮起。

以下是代码:

const byte LED = 11;
const byte Pushbutton = 2;

// run setup code

void setup() {
  pinMode(Pushbutton, INPUT);
  pinMode(LED, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(Pushbutton), LEDManager, CHANGE);
}

void loop() {}

// <summary>LED manager HIGH or LOW</summary>
void LEDManager() {
  digitalWrite(LED, digitalRead(Pushbutton));
}

我的电路工作但间歇性地或当我触摸连接到引脚D2的电线时。

我不明白为什么,我需要一些帮助!

更新

我尝试了很多配置,当我使用新线时,它可以工作!问题是焊接,它们做得不好而且可能损坏了电线(我的烙铁太烫)。

(剧透,一个新的失败!哇!)

更新2!

这一次,我将电路和连接引脚D2更改为按钮的COM端口。 COM端口连接到10k欧姆电阻器,连接到Gnd引脚,3.3V引脚连接到按钮的ON端口(我的灵感来自that谢谢ingo )。

它最终正在工作,白痴!

0 个答案:

没有答案