【发布时间】:2020-02-04 18:06:54
【问题描述】:
首先对不起我的英语不好
我有 Arduino Leonardo 我有一个按钮好吗?
当我单击按钮时,字母“W”会打印到记事本上 好吗?
我想要当我一直按住按钮时打印出 'w' 字母 为什么?就像在游戏中,当我按住“W”字母时,玩家会移动,然后当我松开手指时,玩家会停止。 请拜托,我需要你的帮助,因为我是初学者
这是我的代码
#include "Keyboard.h"
const int buttonPin = 4; // input pin for pushbutton
int previousButtonState = HIGH; // for checking the state of a pushButton
void setup() {
// make the pushButton pin an input:
pinMode(buttonPin, INPUT);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
// read the pushbutton:
int buttonState = digitalRead(buttonPin);
// if the button state has changed,
if ((buttonState != previousButtonState)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// type out a message
Keyboard.print("W");
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
}
【问题讨论】:
标签: arduino arduino-uno arduino-c++