Jump to content

DCS-BIOS Arduino Sketch Multiple buttons one pin


DZ82

Recommended Posts

Hi guys,

 

New to the world of home cockpit building. I have no electronics/programming experience.

 

I can manage to build and code simple one button one pin set-ups, but I have no idea how to write the code to enable me to use multiple buttons on one Arduino Uno analog pin (Not a fan of matrix designs). Again, I can build it, I just can't find the code I need.

 

It is simple enough to find an Arduino Sketch that differentiates between different switches on one analog pin, but I don't know how to incorporate this into DCS-BIOS.

 

I would appreciate any help!!

Link to comment
Share on other sites

You can use a simple resistor ladder, but if you want to be able to detect multiple buttons at once, you need to look for "R-2R ladders".

 

e.g.:

https://forum.arduino.cc/index.php?topic=440200.0

 

Brilliant! Thank you.

 

I found this Arduino Sketch that communicates with LEDs, now I need help on how to communicate the button presses/ switch toggle with DCS.

 

For a simple 2 position switch I would use, for example:

 

DcsBios::Switch2Pos ahcpCicu("AHCP_CICU", PIN);

 

But how do I incorporate this into an if loop (I am assuming this will be the best solution), I don't know what say instead of the pin number?

 

void loop()

{

buttonValue = analogRead(A0); //Read analog value from A0 pin

 

//For 1st button:

if (buttonValue>=1010 && buttonValue<=1015){

digitalWrite(yellowLed, HIGH);

}

//For 2nd button:

else if (buttonValue>=1000 && buttonValue<=1008){

digitalWrite(redLed, HIGH);

}

//For 3rd button:

else if (buttonValue>=990 && buttonValue<=998){

digitalWrite(blueLed, HIGH);

}

//For 4th button:

else if (buttonValue>=870 && buttonValue<=880){

digitalWrite(greenLed, HIGH);

}

//No button pressed, turn off LEDs

else{

digitalWrite(yellowLed, LOW);

digitalWrite(redLed, LOW);

digitalWrite(blueLed, LOW);

digitalWrite(greenLed, LOW);

}

delay(100);

}

Link to comment
Share on other sites

Out of desperation and frustration pehaps I can use 2 boards - an Arduino mega and Uno for example, and simply do one button one pin? I wanted to keep cost down by combining cdu and aap on one biard.

Link to comment
Share on other sites

If you don't want to go with matrix you can add more digital pins to your Arduino using the MCP23017 (https://www.adafruit.com/product/732) for an extra 16 pins accessible via i2c (or the MCP23S17 spi version).

 

You can add up to 8 of these on unique addresses for a maximum of 128 extra pins.

 

I'm using these on some of my more complicated devices as I can keep the main loop clear for complicated things and use an interrupt to trigger the button state read only when something changes.

 

This takes a bit more programming work though (arduino libraries are available to do most of the work for you)

Link to comment
Share on other sites

  • 4 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...