我有一个旋转开关,想与我的 teensy 3.2 一起使用。我有这个代码:
#include <Bounce.h>
Bounce button3 = Bounce(3, 10); // Key 'Q'
Bounce button4 = Bounce(4, 10); // Key 'W'
Bounce button5 = Bounce(5, 10); // Key 'E'
Bounce button6 = Bounce(6, 10); // Key 'R'
Bounce button7 = Bounce(7, 10); // Key 'T'
int modeNum;
void setup() {
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
}
void loop {
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
if (button3.read() == LOW)
{
if (modeNum != 1)
{
modeNum = 1;
usb_keyboard_press(KEY_Q, 0);
}
}
else if (button4.read() == LOW)
{
if (modeNum != 2)
{
modeNum = 2;
usb_keyboard_press(KEY_W, 0);
}
}
else if (button5.read() == LOW)
{
if (modeNum != 3)
{
modeNum = 3;
usb_keyboard_press(KEY_E, 0);
}
}
else if (button6.read() == LOW)
{
if (modeNum != 4)
{
modeNum = 4;
usb_keyboard_press(KEY_R, 0);
}
}
else if (button7.read() == LOW)
{
if (modeNum != 5)
{
modeNum = 5;
usb_keyboard_press(KEY_T, 0);
}
}
}
我已正确初始化它。而且我的旋转编码器接线正确。我只是不知道为什么当我旋转表盘时我的代码没有发送击键。