Factor pin-reading logic into a new set of classes.

This commit is contained in:
Anna Rose Wiggins 2021-11-22 19:12:44 +00:00
parent a4f00a0a23
commit 8ebc1a5523
6 changed files with 182 additions and 109 deletions

View file

@ -39,8 +39,10 @@ class Joystick {
// If `pullup` is false, your button should connect the pin to VCC.
// Setting `analogOnly` to true indicates your button *must* be read with analog code, such as the A6 and A7 pins
// on the Arduino Nano.
void AddButton(uint8_t pin, ButtonType type, bool pullup=true, Mux* mux=NULL, bool analog_only=false);
void AddButton(uint8_t pin, ButtonType type, bool pullup=true);
void AddMuxButton(uint8_t channel, Mux* mux, ButtonType type, bool pullup=true);
void AddMatrixButton(uint8_t row, uint8_t col, ButtonType type, bool pullup=true);
// Add a rotary encoder. ENCODER button types allow you to treat an encoder as a momentary button or an axis (TODO)
void AddEncoder(uint8_t pin1, uint8_t pin2, ButtonType type);
@ -59,6 +61,8 @@ class Joystick {
void _UpdateAxis(uint8_t index);
void _addButton(ButtonType type, Reader* reader);
Button* _buttons[JOYSTICK_NUM_BUTTONS];
uint8_t _num_buttons;
uint8_t _virtual_buttons; // a single user-defined button can have multiple virtual buttons.