Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5aaff79

Browse files
committed
buttons: remove need to declare button array size
1 parent 68332dc commit 5aaff79

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

‎FlightStick.ino

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@
66
#include "Bezier.hpp"
77

88
#define CALIBRATION_BUTTON 7
9-
#define AXIS_ARRAY_SIZE 3
109
#define LED 13
10+
1111
#define CENTER 512
1212

13+
#define AXIS_ARRAY_SIZE 3
14+
1315
#define LINEAR 2
1416
#define CURVE 1
1517

16-
#define ANALOG_FILTER_M_COUNT 3
17-
#define ANALOG_FILTER_M_DISCARD 1
18-
1918
// some pins can function as either digital or analog inputs, so we predefine
2019
// which will operate in which mode
21-
// X Y RX RY Th
22-
/* static const int analog_pins[] = { A0, A1, A8, A9, A6 }; */
20+
// X Y Th
2321
static const int analog_pins[] = { A0, A1, A6 };
24-
static const int digital_pins[] = { 3, 5, 6, 7, 8, 9 };
22+
static const int digital_pins[] = { 3, 5, 6, 7, 8, 9, 14 };
2523

2624
struct {
2725
bool is_calibrated = false;
@@ -230,6 +228,10 @@ int axisRead(int index, int option = CURVE)
230228
1023),
231229
0,
232230
1023);
231+
232+
int buttonRead(int index)
233+
{
234+
return !digitalRead(digital_pins[index]);
233235
}
234236

235237
// ===========================================================================
@@ -258,8 +260,8 @@ void setup()
258260
void loop()
259261
{
260262
// read the buttons
261-
for (int i = 0; i < sizeof(digital_pins) / sizeof(int); i++)
262-
joystick.setButton(i, !digitalRead(digital_pins[i]));
263+
for (int btn = 0; btn < (sizeof(digital_pins) / sizeof(int)); btn++)
264+
joystick.setButton(btn, buttonRead(btn));
263265

264266
// read the analog inputs
265267
joystick.setYAxis(axisRead(0, CURVE));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /