Good evening everyone,
First time here and very new to all this. I've been working on a flight sim button box project for a while and just got into coding it a few weeks ago. As stated in the title, for the life of me, I can't seem to get more than 32 buttons to register. For context, I have 45 switch inputs and 6 potentiometers. Testing each switch by itself, they work fine. When combining everything, I lose buttons 33 - 45. I have used multiple USB Types and most recently tried out the Flight Sim Controls + Joystick type as I saw it supports 128 inputs with 8 axes. I'm kind of at a dead end. I did make sure the JOYSTICK_SIZE in usb_desc.h was changed to 64 to accommodate more inputs. I didn't see any changes needed in usb_desc.c. I will post my sketch below - again, very new to this and know the code could be significantly shorter using arrays, but starting out, I wanted something easy for me to read and learn from. Obviously there is some FastLED stuff in there too for my backlighting of this button box.
Any help or direction would be greatly appreciated! I'm sure I'm missing something stupidly simple but I just haven't found it. Thanks again!
First time here and very new to all this. I've been working on a flight sim button box project for a while and just got into coding it a few weeks ago. As stated in the title, for the life of me, I can't seem to get more than 32 buttons to register. For context, I have 45 switch inputs and 6 potentiometers. Testing each switch by itself, they work fine. When combining everything, I lose buttons 33 - 45. I have used multiple USB Types and most recently tried out the Flight Sim Controls + Joystick type as I saw it supports 128 inputs with 8 axes. I'm kind of at a dead end. I did make sure the JOYSTICK_SIZE in usb_desc.h was changed to 64 to accommodate more inputs. I didn't see any changes needed in usb_desc.c. I will post my sketch below - again, very new to this and know the code could be significantly shorter using arrays, but starting out, I wanted something easy for me to read and learn from. Obviously there is some FastLED stuff in there too for my backlighting of this button box.
Any help or direction would be greatly appreciated! I'm sure I'm missing something stupidly simple but I just haven't found it. Thanks again!
Code:
#include <FastLED.h>
// LED Setup
#define LED_PIN 23
#define NUM_LEDS 214
CRGB leds[NUM_LEDS];
// LED Color Control
CRGB colors[] = {CRGB::Green, CRGB::Red, CRGB::Blue, CRGB::Yellow, CRGB::White};
int currentColorIndex = 0;
unsigned long lastLtTestPressTime = 0;
int ltTestPressCount = 0;
bool lastLtTestState = false;
void setup() {
Joystick.begin();
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
// Setup L GEN and R GEN switches (2-position switches)
pinMode(2, INPUT_PULLUP); // L GEN switch (up position)
pinMode(3, INPUT_PULLUP); // R GEN switch (up position)
// Setup BATT switch (3-position switch)
pinMode(0, INPUT_PULLUP); // BATT switch (up position)
pinMode(1, INPUT_PULLUP); // BATT switch (down position)
// Setup MODE switch (3-position switch)
pinMode(4, INPUT_PULLUP); // MODE switch (up position)
pinMode(5, INPUT_PULLUP); // MODE switch (down position)
// Setup CABIN PRESS switch (3-position switch)
pinMode(6, INPUT_PULLUP); // CABIN PRESS switch (up position)
pinMode(7, INPUT_PULLUP); // CABIN PRESS switch (down position)
// Setup PITOT switch (2-position switch)
pinMode(8, INPUT_PULLUP); // PITOT switch (up position)
// Setup ENG HEAT switch (3-position switch)
pinMode(9, INPUT_PULLUP); // ENG HEAT switch (up position)
pinMode(10, INPUT_PULLUP); // ENG HEAT switch (down position)
// Setup LT TEST switch (1-position switch)
pinMode(26, INPUT_PULLUP); // LT TEST switch (up position)
// Setup DAY/NITE MODE switch (3-position switch)
pinMode(27, INPUT_PULLUP); // DAY/NITE MODE switch (up position)
pinMode(28, INPUT_PULLUP); // DAY/NITE MODE switch (down position)
// Setup FLIR switch (3-position switch)
pinMode(29, INPUT_PULLUP); // FLIR switch (up position)
pinMode(30, INPUT_PULLUP); // FLIR switch (down position)
// Setup LTD/R switch (2-position switch)
pinMode(33, INPUT_PULLUP); // LTD/R switch (up position)
// Setup LST/NFLR switch (2-position switch)
pinMode(31, INPUT_PULLUP); // LST/NFLR switch (up position)
// Setup BLEED AIR switch (4-position rotary)
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
// Setup RADAR switch (4-position rotary)
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
// Setup GPS switch (8-position rotary)
pinMode(34, INPUT_PULLUP);
pinMode(35, INPUT_PULLUP);
pinMode(36, INPUT_PULLUP);
pinMode(37, INPUT_PULLUP);
pinMode(38, INPUT_PULLUP);
pinMode(39, INPUT_PULLUP);
pinMode(40, INPUT_PULLUP);
pinMode(41, INPUT_PULLUP);
}
void loop() {
bool switchLGenUpState = !digitalRead(2);
bool switchRGenUpState = !digitalRead(3);
bool switchBattUpState = !digitalRead(0);
bool switchBattDownState = !digitalRead(1);
bool switchBattCenterState = !switchBattUpState && !switchBattDownState;
bool switchModeUpState = !digitalRead(4);
bool switchModeDownState = !digitalRead(5);
bool switchModeCenterState = !switchModeUpState && !switchModeDownState;
bool switchCabinPressUpState = !digitalRead(6);
bool switchCabinPressDownState = !digitalRead(7);
bool switchCabinPressCenterState = !switchCabinPressUpState && !switchCabinPressDownState;
bool switchPitotUpState = !digitalRead(8);
bool switchPitotDownState = !switchPitotUpState;
bool switchEngHeatUpState = !digitalRead(9);
bool switchEngHeatDownState = !digitalRead(10);
bool switchEngHeatCenterState = !switchEngHeatUpState && !switchEngHeatDownState;
bool switchLtTestState = !digitalRead(26);
bool switchDayNiteUpState = !digitalRead(27);
bool switchDayNiteDownState = !digitalRead(28);
bool switchDayNiteCenterState = !switchDayNiteUpState && !switchDayNiteDownState;
bool switchFlirUpState = !digitalRead(29);
bool switchFlirDownState = !digitalRead(30);
bool switchFlirCenterState = !switchFlirUpState && !switchFlirDownState;
bool switchLtdrUpState = !digitalRead(33);
bool switchLtdrDownState = !switchLtdrUpState;
bool switchLstNflrUpState = !digitalRead(31);
bool switchLstNflrDownState = !switchLstNflrUpState;
int bleedAirPosition = (!digitalRead(11) * 1) + (!digitalRead(12) * 2) + (!digitalRead(24) * 3) + (!digitalRead(25) * 4);
int radarPosition = (!digitalRead(13) * 1) + (!digitalRead(14) * 2) + (!digitalRead(15) * 3) + (!digitalRead(16) * 4);
int gpsPosition = (!digitalRead(34) * 1) + (!digitalRead(35) * 2) + (!digitalRead(36) * 3) + (!digitalRead(37) * 4) + (!digitalRead(38) * 5) + (!digitalRead(39) * 6) + (!digitalRead(40) * 7) + (!digitalRead(41) * 8);
Joystick.button(0, switchLGenUpState);
Joystick.button(1, !switchLGenUpState);
Joystick.button(2, switchRGenUpState);
Joystick.button(3, !switchRGenUpState);
Joystick.button(4, switchBattUpState);
Joystick.button(5, switchBattDownState);
Joystick.button(6, switchBattCenterState);
Joystick.button(7, switchModeUpState);
Joystick.button(8, switchModeDownState);
Joystick.button(9, switchModeCenterState);
Joystick.button(10, switchCabinPressUpState);
Joystick.button(11, switchCabinPressDownState);
Joystick.button(12, switchCabinPressCenterState);
Joystick.button(13, switchPitotUpState);
Joystick.button(14, switchPitotDownState);
Joystick.button(15, switchEngHeatUpState);
Joystick.button(16, switchEngHeatDownState);
Joystick.button(17, switchEngHeatCenterState);
Joystick.button(18, switchLtTestState);
Joystick.button(19, switchDayNiteUpState);
Joystick.button(20, switchDayNiteDownState);
Joystick.button(21, switchDayNiteCenterState);
Joystick.button(22, switchFlirUpState);
Joystick.button(23, switchFlirDownState);
Joystick.button(24, switchFlirCenterState);
Joystick.button(25, switchLtdrUpState);
Joystick.button(26, switchLtdrDownState);
Joystick.button(27, switchLstNflrUpState);
Joystick.button(28, switchLstNflrDownState);
Joystick.button(29, bleedAirPosition == 1);
Joystick.button(30, bleedAirPosition == 2);
Joystick.button(31, bleedAirPosition == 3);
Joystick.button(32, bleedAirPosition == 4);
Joystick.button(33, radarPosition == 1);
Joystick.button(34, radarPosition == 2);
Joystick.button(35, radarPosition == 3);
Joystick.button(36, radarPosition == 4);
Joystick.button(37, gpsPosition == 1);
Joystick.button(38, gpsPosition == 2);
Joystick.button(39, gpsPosition == 3);
Joystick.button(40, gpsPosition == 4);
Joystick.button(41, gpsPosition == 5);
Joystick.button(42, gpsPosition == 6);
Joystick.button(43, gpsPosition == 7);
Joystick.button(44, gpsPosition == 8);
// Potentiometer readings
Joystick.X(1023 - analogRead(17)); // TEMP Pot
Joystick.Y(1023 - analogRead(18)); // CONSOLES Pot (Also LED Brightness Control)
Joystick.Z(1023 - analogRead(19)); // INST PNL Pot
Joystick.Xrotate(1023 - analogRead(20)); // FLOOD Pot
Joystick.Yrotate(1023 - analogRead(21)); // WARN/CAUT Pot
Joystick.Zrotate(1023 - analogRead(22)); // CHART Pot
unsigned long currentTime = millis();
// LT TEST switch color cycling logic with debounce
if (switchLtTestState && !lastLtTestState) { // Detects only new presses
if (currentTime - lastLtTestPressTime < 1000) {
ltTestPressCount++;
} else {
ltTestPressCount = 1;
}
lastLtTestPressTime = currentTime;
}
lastLtTestState = switchLtTestState;
if (ltTestPressCount >= 3) {
currentColorIndex = (currentColorIndex + 1) % (sizeof(colors) / sizeof(colors[0]));
ltTestPressCount = 0; // Reset counter
}
// LED Brightness and Color Control
int brightness = map(analogRead(18), 0, 1023, 255, 0);
FastLED.setBrightness(brightness);
fill_solid(leds, NUM_LEDS, colors[currentColorIndex]);
FastLED.show();
Joystick.send_now();
delay(5);
}