Update board and code to use a scan matrix. This is cheaper, has a smaller footprint, and is at least as performant as the multiplexer approach.
This commit is contained in:
parent
28c135140c
commit
35098e12a6
BIN
flight-panel-2021-11/Flight Panel 2021-11 Board.pdf
Normal file
BIN
flight-panel-2021-11/Flight Panel 2021-11 Board.pdf
Normal file
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,75 +1,82 @@
|
|||
#include <Joystick.h>
|
||||
#include <Mux.h>
|
||||
#include <Matrix.h>
|
||||
|
||||
Joystick joystick(false);
|
||||
|
||||
// These defines match the board schematic
|
||||
#define ENC1 2, 3
|
||||
#define ENC2 4, 5
|
||||
#define BTN1 6
|
||||
#define BTN2 7
|
||||
#define BTN3 8
|
||||
#define BTN4 9
|
||||
#define BTN5 10
|
||||
#define BTN6 11
|
||||
#define BTN7 12
|
||||
#define BTN8 13
|
||||
#define BTN9 A0
|
||||
#define ENC1 2, 4
|
||||
#define ENC2 3, 5
|
||||
|
||||
// Buttons 10 and higher are all on A1 (the MUX signal pin), these are multiplexer channel IDs
|
||||
#define BTN10 0
|
||||
#define BTN11 1
|
||||
#define BTN12 2
|
||||
#define BTN13 3
|
||||
#define BTN14 4
|
||||
#define BTN15 5
|
||||
#define BTN16 6
|
||||
#define BTN17 7
|
||||
#define BTN18 8
|
||||
#define BTN19 9
|
||||
#define BTN20 10
|
||||
#define BTN21 11
|
||||
#define BTN22 12
|
||||
#define KBTN1 13
|
||||
#define KBTN2 14
|
||||
#define KBTN3 15
|
||||
// Matrix defines
|
||||
#define R0 6
|
||||
#define R1 7
|
||||
#define R2 8
|
||||
#define R3 9
|
||||
#define R4 10
|
||||
#define C0 A3
|
||||
#define C1 A2
|
||||
#define C2 A1
|
||||
#define C3 A0
|
||||
|
||||
#define BTN1 R0,C0
|
||||
#define BTN2 R1,C0
|
||||
#define BTN3 R2,C0
|
||||
#define BTN4 R3,C0
|
||||
#define BTN5 R4,C0
|
||||
#define BTN6 R0,C1
|
||||
#define BTN7 R1,C1
|
||||
#define BTN8 R2,C1
|
||||
#define BTN9 R3,C1
|
||||
#define BTN10 R0,C2
|
||||
#define BTN11 R1,C2
|
||||
#define BTN12 R2,C2
|
||||
#define BTN13 R3,C2
|
||||
#define BTN14 R0,C3
|
||||
#define BTN15 R1,C3
|
||||
#define BTN16 R2,C3
|
||||
#define BTN17 R3,C3
|
||||
#define KBTN1 R4,C1
|
||||
#define KBTN2 R4,C2
|
||||
#define KBTN3 R4,C3
|
||||
|
||||
void setup() {
|
||||
// Encoders
|
||||
joystick.AddEncoder(ENC1, ENCODER_PULSED_SPLIT);
|
||||
joystick.AddEncoder(ENC2, ENCODER_PULSED_SPLIT);
|
||||
|
||||
// // Power switches
|
||||
joystick.AddButton(BTN1, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddButton(BTN2, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddButton(BTN3, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddButton(BTN4, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
// We will add the 2-stage "key buttons" in a slightly odd order
|
||||
// in order to keep columns together for faster scanning.
|
||||
Matrix* matrix = new Matrix({C0, C1, C2, C3}, 4);
|
||||
|
||||
// // HUD modes
|
||||
joystick.AddButton(BTN5, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(BTN6, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(BTN7, BUTTON_PASSTHRU);
|
||||
// Flight modes
|
||||
joystick.AddMatrixButton(BTN1, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN2, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN3, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN4, matrix, BUTTON_PASSTHRU);
|
||||
|
||||
// // Mining Modules
|
||||
joystick.AddButton(BTN8, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(BTN9, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(BTN10, BUTTON_PASSTHRU, true, mux);
|
||||
// Lights and Doors
|
||||
joystick.AddMatrixButton(BTN5, matrix, BUTTON_PULSED_DOUBLE_ACTION);
|
||||
joystick.AddMatrixButton(BTN6, matrix, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddMatrixButton(BTN7, matrix, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
|
||||
// // Flight Modes
|
||||
joystick.AddButton(BTN11, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(BTN12, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(BTN13, BUTTON_PASSTHRU, true, mux);
|
||||
joystick.AddButton(BTN14, BUTTON_PASSTHRU, true, mux);
|
||||
// Mining modules (plus first keybutton)
|
||||
joystick.AddMatrixButton(BTN8, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN9, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(KBTN1, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN10, matrix, BUTTON_PASSTHRU);
|
||||
|
||||
// // Doors & Lights
|
||||
joystick.AddButton(BTN15, BUTTON_PULSED_DOUBLE_ACTION, true, mux);
|
||||
joystick.AddButton(BTN16, BUTTON_PULSED_DOUBLE_ACTION_SPLIT, true, mux);
|
||||
joystick.AddButton(BTN17, BUTTON_PULSED_DOUBLE_ACTION_SPLIT, true, mux);
|
||||
// HUD modes
|
||||
joystick.AddMatrixButton(BTN11, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN12, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN13, matrix, BUTTON_PASSTHRU);
|
||||
|
||||
// // Emergency Panel
|
||||
joystick.AddButton(KBTN1, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(KBTN2, BUTTON_PASSTHRU);
|
||||
joystick.AddButton(KBTN3, BUTTON_PASSTHRU);
|
||||
// Flight modes (and latter 2 keybuttons)
|
||||
joystick.AddMatrixButton(KBTN2, matrix, BUTTON_PASSTHRU);
|
||||
joystick.AddMatrixButton(BTN14, matrix, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddMatrixButton(BTN15, matrix, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddMatrixButton(BTN16, matrix, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddMatrixButton(BTN17, matrix, BUTTON_PULSED_DOUBLE_ACTION_SPLIT);
|
||||
joystick.AddMatrixButton(KBTN3, matrix, BUTTON_PASSTHRU);
|
||||
|
||||
joystick.Init();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user