matt.israel Posted October 29, 2020 Share Posted October 29, 2020 How are folks addressing home pits requiring more than ~10 I/O ports? Just keep adding Arduinos? I'm planning on making a second button box for the FA-18c and I would like to add the INS rotary switch, but it requires 8 pins. I would be fine omitting the positions after IFA if I could edit the code below. Wondering if there are any 'reasonable' ways to reduce the number of pins needed for a 'SwitchMultiPos' in DCS- Bios? const byte insSwPins[15] = {PIN_0, PIN_1, PIN_2, PIN_3, PIN_4, PIN_5, PIN_6, PIN_7} DcsBios::SwitchMultiPos insSw("INS_SW", insSwPins, 15); Link to comment Share on other sites More sharing options...
No1sonuk Posted October 30, 2020 Share Posted October 30, 2020 Analogue pins can be used for digital O/I as well if you set them up as such. Check "Notes and warnings" here: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/ My P51 fuel system "mockpit" panel uses a Nano's A0-A3 as LED outputs too. That panel has a 5-position tank select switch, a fuel cutoff switch, 4 servo outputs and 4 LED outputs. That's 6 in and 8 out. All 14 are used as digital. Link to comment Share on other sites More sharing options...
tekadept Posted October 31, 2020 Share Posted October 31, 2020 To reduce the amount of pins for rotary switches look into resistor ladders, then you only need a single analog input to detect what position. "Lead me, follow me, or get the hell out of my way" (Gen. George Patton) https://www.tekcreations.space Link to comment Share on other sites More sharing options...
matt.israel Posted November 2, 2020 Author Share Posted November 2, 2020 To reduce the number of pins for rotary switches look into resistor ladders, then you only need a single analog input to detect what position. I've seen the resistor ladders used. Do you know if/how they work with DCS-Bios? I think it would bring me back to where I started - wondering about modifying DCS-Bios code. Based on what I read it seemed like wiring wasn't terribly difficult, but won't work with DCS-Bios. Link to comment Share on other sites More sharing options...
tekadept Posted November 2, 2020 Share Posted November 2, 2020 Well its not natively supported with a simple dcsbios command, but its easy enough to program. below is a class I use you can add to switches.h Its called by say DcsBios::AnalogMultiPos INSSW("INS_KNB", A7, 8, 250) class AnalogMultiPos : PollingInput { private: const char *msg_; char pin_; char numOfSteps; int divisor; char lastState_; int period = 750; unsigned long time_now = 0; char readState() { int which = 0; int nextval = -10; int readvalue = analogRead(pin_); for (int i = 0; i < (int)numOfSteps; i++) { if (readvalue >= nextval) { which = i; nextval = nextval + (1024 / numOfSteps); } } return which; } void pollInput() { char state = readState(); if (millis() > time_now + period) { time_now = millis(); if (state != lastState_) { if (state == 0) if (tryToSendDcsBiosMessage(msg_, "0")) lastState_ = state; if (state == 1) if (tryToSendDcsBiosMessage(msg_, "1")) lastState_ = state; if (state == 2) if (tryToSendDcsBiosMessage(msg_, "2")) lastState_ = state; if (state == 3) if (tryToSendDcsBiosMessage(msg_, "3")) lastState_ = state; if (state == 4) if (tryToSendDcsBiosMessage(msg_, "4")) lastState_ = state; if (state == 5) if (tryToSendDcsBiosMessage(msg_, "5")) lastState_ = state; if (state == 6) if (tryToSendDcsBiosMessage(msg_, "6")) lastState_ = state; if (state == 7) if (tryToSendDcsBiosMessage(msg_, "7")) lastState_ = state; if (state == 8) if (tryToSendDcsBiosMessage(msg_, "8")) lastState_ = state; if (state == 9) if (tryToSendDcsBiosMessage(msg_, "9")) lastState_ = state; if (state == 10) if (tryToSendDcsBiosMessage(msg_, "10")) lastState_ = state; } } } public: AnalogMultiPos(const char *msg, char pin, char numOfSteps_, int divisor_) { msg_ = msg; pin_ = pin; divisor = divisor_; lastState_ = readState(); numOfSteps = numOfSteps_; } void pollInputCurrent() { char state = readState(); char buf[7]; utoa(state, buf, 10); if (tryToSendDcsBiosMessage(msg_, buf)) lastState_ = state; delay(100); } void SetControl(const char *msg) { msg_ = msg; } }; "Lead me, follow me, or get the hell out of my way" (Gen. George Patton) https://www.tekcreations.space Link to comment Share on other sites More sharing options...
Recommended Posts