0
我有一个特定的开关,我需要使用它只是碰巧切换。问题在于,无论何时按下按钮,我都需要将键盘笔划发送到我的计算机。我在Arduino网站上尝试了一个基本示例的修改,但它不适用于我:如何在我的arduino上使用切换开关作为瞬时开关?
const int buttonPin = 2; // the number of the pushbutton pin
int prior = 0;
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Keyboard.begin();
}
void loop()
{
prior = buttonState;
buttonState = digitalRead(buttonPin);
if (buttonState != prior) {
Keyboard.write(32);
}
}
你确切的问题是什么?如果你推它很多,它有时会工作吗?如果是这样,你可能只需要一个下拉电阻。祝你好运! – dbalakirev