1
0
mirror of https://github.com/limyz/573controller synced 2024-11-30 18:24:28 +01:00

Optimize code slightly

This commit is contained in:
987123879113 2020-06-04 17:06:22 +09:00
parent 9849b5c7f2
commit 4f9a699823
2 changed files with 9 additions and 41 deletions

View File

@ -94,23 +94,7 @@ void loop() {
for (int index = 0; index < 5; index++) { for (int index = 0; index < 5; index++) {
int currentButtonState = !digitalRead(index + pinToButtonMap); int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index]) { if (currentButtonState != lastButtonState[index]) {
switch (index) { Joystick.setButton(index, currentButtonState);
case 0:
Joystick.setButton(0, currentButtonState);
break;
case 1:
Joystick.setButton(1, currentButtonState);
break;
case 2:
Joystick.setButton(2, currentButtonState);
break;
case 3:
Joystick.setButton(3, currentButtonState);
break;
case 4:
Joystick.setButton(4, currentButtonState);
break;
}
lastButtonState[index] = currentButtonState; lastButtonState[index] = currentButtonState;
} }
} }

View File

@ -84,23 +84,7 @@ void loop() {
for (int index = 0; index < 5; index++) { for (int index = 0; index < 5; index++) {
int currentButtonState = !digitalRead(index + pinToButtonMap); int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index]) { if (currentButtonState != lastButtonState[index]) {
switch (index) { Joystick.setButton(index, currentButtonState);
case 0:
Joystick.setButton(0, currentButtonState);
break;
case 1:
Joystick.setButton(1, currentButtonState);
break;
case 2:
Joystick.setButton(2, currentButtonState);
break;
case 3:
Joystick.setButton(3, currentButtonState);
break;
case 4:
Joystick.setButton(4, currentButtonState);
break;
}
lastButtonState[index] = currentButtonState; lastButtonState[index] = currentButtonState;
} }
} }