diff --git a/Flight_Sim_Controller.ino b/Flight_Sim_Controller.ino index c309a6d..43d55d1 100644 --- a/Flight_Sim_Controller.ino +++ b/Flight_Sim_Controller.ino @@ -1,119 +1,75 @@ // Requires Arduino Joystick Library https://github.com/MHeironimus/ArduinoJoystickLibrary #include Joystick_ Joystick; - -int JoystickX; -int JoystickY; -int JoystickZ; -int Throttle; -int currentButtonState0; -int lastButtonState0; -int currentButtonState1; -int lastButtonState1; -int currentButtonState2; -int lastButtonState2; -int currentButtonState3; -int lastButtonState3; -int currentButtonState4; -int lastButtonState4; -int currentButtonState5; -int lastButtonState5; -int currentButtonState6; -int lastButtonState6; +int bitResolution = 12; +long sampleValue = 0; +int numberOfSamples = 1; + +const uint8_t LINEAR_PINS[] = { + A9, // JoystickX, Hall effect + A8, // JoystickY, Hall effect + A6, // JoystickZ, Hall effect + A4, // Throttle, Potentiometer +}; +const uint8_t SWITCH_PINS[] = { + 7, // Joystick Button 0 + A0, // Joystick Button 1 + 6, // Joystick Button 2 + A1, // Joystick Button 3 + A2, // Joystick Button 4 + A3, // Joystick Button 5 + A5, // Joystick Button 6 +}; + +boolean lastButtonState[sizeof(SWITCH_PINS)]; void setup() { - pinMode(6, INPUT_PULLUP); - pinMode(7, INPUT_PULLUP); - pinMode(A0, INPUT_PULLUP); - pinMode(A1, INPUT_PULLUP); - pinMode(A2, INPUT_PULLUP); - pinMode(A3, INPUT_PULLUP); - pinMode(A4, INPUT_PULLUP); - pinMode(A5, INPUT_PULLUP); - pinMode(A6, INPUT_PULLUP); - pinMode(A7, INPUT_PULLUP); - pinMode(A8, INPUT_PULLUP); - pinMode(A9, INPUT_PULLUP); - + // Setup analog inputs + for (size_t i = 0; i < sizeof(LINEAR_PINS); i++) { + pinMode(LINEAR_PINS[i], INPUT_PULLUP); + } + // Setup digital switches + for (size_t i = 0; i < sizeof(SWITCH_PINS); i++) { + pinMode(SWITCH_PINS[i], INPUT_PULLUP); + } // Initialize Joystick Library Joystick.begin(); - Joystick.setXAxisRange(0, 1024); - Joystick.setYAxisRange(0, 1024); - Joystick.setZAxisRange(0, 1024); - Joystick.setThrottleRange(0, 1024); + Joystick.setXAxisRange(0, 1<>(bitResolution-10))+(1<