-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpads_controller.cpp
More file actions
31 lines (26 loc) · 1.13 KB
/
Copy pathpads_controller.cpp
File metadata and controls
31 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "pads_controller.h"
// Initializes the Joystick library. It creates only the exact number of buttons
// needed to map all pads.
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD,
NUMBER_OF_ARROWS, 0, // Button Count, Hat Switch Count
false, false, false, // No X, Y, or Z Axis
false, false, false, // No Rx, Ry, or Rz
false, false, // No rudder or throttle
false, false, false); // No accelerator, brake, or steering
Pad *pads[NUMBER_OF_ARROWS];
void setupPads() {
Joystick.begin();
for (int padIndex = 0; padIndex < NUMBER_OF_ARROWS; padIndex++) {
pads[padIndex] = new Pad(SENSOR_PINS[padIndex], DEBOUNCE_INTERVAL);
}
}
// Iterates over all pads, checking if each one is pressed and sending the
// appropriate inputs to the Joystick and LED controller.
void checkPads() {
for (int padIndex = 0; padIndex < NUMBER_OF_ARROWS; padIndex++) {
Pad *pad = pads[padIndex];
if (pad->pressChanged()) {
Joystick.setButton(padIndex, pad->isPressed());
}
}
}