Jump to content

Arduino or Zero Delay Encoder for 3-way switches?


durka-durka

Recommended Posts

Hello,

 I'm a novice at all this, but I have wires, switches, and an Arduino board.  All I want to do is wire up a few switches. (F-16 Master Arm Panel w/ autopilot switches)  I don't know code, so I'm wondering if a Zero Delay Encoder would work better than what I have now, which is Arduino Leonardo?


Or, does someone knows a simple sketch I can use for just one 3-way switch on the Arduino? I could just go off that to make the rest.  But I know just enough about coding to know I hate it.  Any help is greatly appreciated!

492nd Squadron CO (F-15E): JTF-111 -  Discord Link

Link to comment
Share on other sites

Hi mate,

I can't help you out with code per se, but you could wire each switch positiin to its own digital pin and use a common ground.

e.g.

Away positive - pin x

Centre positive - pin y

(or it could simply be off and have no connection)

Near positive - pin z

I don't know about inline resistors etc, but the code should simply be describing each pin to an equivalent button.

I have used this scheme on a zero delay enconder for trim switches, and other buttons.

I did discover that one button does become a steamvr command if held for too long (~3seconds) YMMV

Cheers,

Tom

Link to comment
Share on other sites

7 hours ago, No1sonuk said:

He said it was a Leonardo,  which does have the 32u4 processor with USB.

So the more easy way to make this a "joystick controller" is flash - using the USB cable; with MMjoy2 firmware, after make the configuration (number of axes, buttons, encoders) is done though MMJoySetup GUI.

 

27663883618_7576255b28_o.png

Well explained there: https://www.sas1946.com/main/index.php?topic=58176.24

Other option is RealRobot configurator.

main_page.jpg

https://gitlab.com/realrobots/rr_configurator

Link to comment
Share on other sites

1 hour ago, Sokol1_br said:

So the more easy way to make this a "joystick controller" is flash - using the USB cable; with MMjoy2 firmware, after make the configuration (number of axes, buttons, encoders) is done though MMJoySetup GUI.

I'd have thought the easier way would be to use the Arduino Joystick library and code it.
Then you can use DCS-BIOS as well to get feedback such as lights, etc.

Link to comment
Share on other sites

2 hours ago, No1sonuk said:

I'd have thought the easier way would be to use the Arduino Joystick library and code it.
Then you can use DCS-BIOS as well to get feedback such as lights, etc.

This is what I'm trying at the moment, but it's a lot more complicated than it seems.  I've just spent the past hour just trying to get it set up, because the original user guide for DCS-BIOS has a lot of instructions that seem to be defunct or have changed over the years.  It stinks, because the instructions are so straightforward.  

 

Right now, the "DCS Connection" in the DCS-BIOS Hub page wants my saved games put back into C drive, which it's not. It's on an L Drive now, but I've copied the script that was provided and placed it into my L:/Saved Games/DCS.openbeta/Scripts/Export.lua file, with no luck.  (I moved my "Saved Games" folder to another drive. To get the check boxes to work, I made a new fake "Saved Games" folder in C:/ Drive.

11.JPG

Unfortunately, it doesn't seem to get the Virtual Cockpit to come up.

12.JPG

 

492nd Squadron CO (F-15E): JTF-111 -  Discord Link

Link to comment
Share on other sites

1 minute ago, durka-durka said:

Thanks. I'll check this out.  Didn't know it was so complicated just to wire some switches up and use in game.

 

The Leonardo doesn't NEED DCS-BIOS if you only want it to behave like a joystick.
You can just use the Joystick library.

I only mentioned DCS-BIOS because you can use it if you want the controls DCS-BIOS offers, and/or the info DCS-BIOS exports.

Link to comment
Share on other sites

49 minutes ago, No1sonuk said:

The Leonardo doesn't NEED DCS-BIOS if you only want it to behave like a joystick.
You can just use the Joystick library.

I only mentioned DCS-BIOS because you can use it if you want the controls DCS-BIOS offers, and/or the info DCS-BIOS exports.

 

My goal is to make a small panel of switches in the F-16. Top Left Panel: 

  • 1x Laser Arm (on/off)
  • 1x Master Arm (on/off/on)
  • 2x Autopilot function switches (on/off/on). 

I'm pretty confident I can wire the switches up, but I feel like getting it to work in DCS is over my head, or I'm just overthinking it.  What's the best way to go about this?  

 

14.JPG

492nd Squadron CO (F-15E): JTF-111 -  Discord Link

Link to comment
Share on other sites

I can't see the F-16 controls in DCS as I don't have that module.
What I _CAN_ do is give you arduino code for DCS-BIOS:
 

/*
  Tell DCS-BIOS to use a serial connection and use interrupt-driven
  communication. The main program will be interrupted to prioritize
  processing incoming data.
  
  This should work on any Arduino that has an ATMega328 controller
  (Uno, Pro Mini, many others).
 */
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

// Change these to the appropriate pin numbers:

  // LASER ARM Switch, ARM/OFF
#define LaserArmPin 2

  // MASTER ARM Switch, MASTER ARM/OFF/SIMULATE
#define MasterArmPinA 3
#define MasterArmPinB 4

  // Autopilot PITCH Switch, ATT HOLD/ A/P OFF/ ALT HOLD
#define ApPitchPinA 5
#define ApPitchPinB 6

  // Autopilot ROLL Switch, STRG SEL/ATT HOLD/HDG SEL
#define ApRollPinA 7
#define ApRollPinB 8

// --------------------

/* paste code snippets from the reference documentation here */

DcsBios::Switch2Pos laserArmSw("LASER_ARM_SW", LaserArmPin);

DcsBios::Switch3Pos masterArmSw("MASTER_ARM_SW", MasterArmPinA, MasterArmPinB);

DcsBios::Switch3Pos apPitchSw("AP_PITCH_SW", ApPitchPinA, ApPitchPinB);

DcsBios::Switch3Pos apRollSw("AP_ROLL_SW", ApRollPinA, ApRollPinB);

void setup() {
  DcsBios::setup();
}

void loop() {
  DcsBios::loop();
}

That should work in most Arduinos with DCS-BIOS running in DCS.

Link to comment
Share on other sites

I have tw0 button boxes made with zero delay usb encoders......They work fine without coding, plug and play. You cant identify each individually so sometimes they get mixed up when i startup. But if you get a two player zero delay encoder you can connect up to 20 buttons without problems. At least i did..

 

Link to comment
Share on other sites

2 hours ago, durka-durka said:

 

My goal is to make a small panel of switches in the F-16. Top Left Panel: 

  • 1x Laser Arm (on/off)
  • 1x Master Arm (on/off/on)
  • 2x Autopilot function switches (on/off/on). 

I'm pretty confident I can wire the switches up, but I feel like getting it to work in DCS is over my head, or I'm just overthinking it.  What's the best way to go about this?  

 

14.JPG

Hi,

I've used Arduino's to build a range of button boxes, so you can definitely do what you want.  As per previous advice, no need to use DCS-BIOS, just use the Arduino as a "joystick controller".  See the YT link to get an idea of how to make the connections and the sketch you will use to control the device.  He is using it for a car racing game but the principle is exactly the same.  Good luck.  

 

Link to comment
Share on other sites

20 minutes ago, Rockrend said:

Hi,

I've used Arduino's to build a range of button boxes, so you can definitely do what you want.  As per previous advice, no need to use DCS-BIOS, just use the Arduino as a "joystick controller".

Not having the F16, I don't know if the 3-way switches will work right as a "joystick".

I do know that a lot of those inputs in DCS behave as toggles, so it might not be easy.

28 minutes ago, Blackhawk NC said:

I have tw0 button boxes made with zero delay usb encoders......They work fine without coding, plug and play. You cant identify each individually so sometimes they get mixed up when i startup. 

If you use a Pro Micro or Leonardo in "joystick mode", there IS a way to give them unique identities. I'll track it down later.

Link to comment
Share on other sites

When I say "joystick controller", I mean it in terms of the name Windows gives to a devices like this, as opposed to an actual joystick.  So long as you can get the switches, potentiometers and encoders, it can be done very easily.  Additionally, you can definitely set Pro Micro's with unique identities.

Hope this is helpful. 

Link to comment
Share on other sites

The problem is how DCS responds to the "button" inputs.

e.g. The A-10C responds to the flap switch on the Warthog throttle in such a way that if one of the two "button" inputs is on, the flaps go all the way up or down, and if both are off, the flaps go to a mid position. 

But the FC3 F-15 doesn't respond to the centre position.

Likewise, when you turn on and off the A-10C APU switch, it turns on and off the APU.

I have that switched mapped to the battery switch for the F15.  If I turn the switch on, the battery comes on, but turning off does nothing. I turn it on again and the battery goes off.

This is why how the aircraft module responds to HID buttons is important for the decision on which type of controller you use.

Link to comment
Share on other sites

Ok so I had a long post that seems to have been edited out all the good stuff.  Here's how I currently have it wired for the Master Arm Switch using the code @No1sonuk posted above. I haven't tested yet, but just wanted to see if I'm on the right track.

image.png

1. I have a GND (green), then the "ARM" going to Pin 4, and "Simulate" going to Pin 3.

Also, I'm using Arduino IDE 2.0.0 and when I go to validate the code, I get a big long error message.  Obviously, I have no idea what it means, but I'm guessing it has something to do with how it's communicating with DCS-BIOS or the computer in general?  Here's the error code:

Quote

In file included from C:\Users\Dave\AppData\Local\Temp\.arduinoIDE-unsaved202261-14288-13qplbh.26cv\sketch_jul1a\sketch_jul1a.ino:11:0:
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h: In function 'void DcsBios::USART_RX_vect()':
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:43:25: error: 'UDR0' was not declared in this scope
    volatile uint8_t c = UDR0;
                         ^~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:43:25: note: suggested alternative: 'UDR1'
    volatile uint8_t c = UDR0;
                         ^~~~
                         UDR1
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h: In function 'void DcsBios::setup()':
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:18:14: error: 'PRR' was not declared in this scope
 #define PRR0 PRR
              ^
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:48:4: note: in expansion of macro 'PRR0'
    PRR0 &= ~(1<<PRUSART0);
    ^~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:18:14: note: suggested alternative: 'PRR0'
 #define PRR0 PRR
              ^
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:48:4: note: in expansion of macro 'PRR0'
    PRR0 &= ~(1<<PRUSART0);
    ^~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:49:4: error: 'UBRR0H' was not declared in this scope
    UBRR0H = 0;
    ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:49:4: note: suggested alternative: 'UBRR1H'
    UBRR0H = 0;
    ^~~~~~
    UBRR1H
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:50:4: error: 'UBRR0L' was not declared in this scope
    UBRR0L = 3; // 250000 bps
    ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:50:4: note: suggested alternative: 'UBRR1L'
    UBRR0L = 3; // 250000 bps
    ^~~~~~
    UBRR1L
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:51:4: error: 'UCSR0A' was not declared in this scope
    UCSR0A = 0;
    ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:51:4: note: suggested alternative: 'UCSR1A'
    UCSR0A = 0;
    ^~~~~~
    UCSR1A
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:52:4: error: 'UCSR0C' was not declared in this scope
    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
    ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:52:4: note: suggested alternative: 'UCSR1C'
    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
    ^~~~~~
    UCSR1C
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:52:17: error: 'UCSZ00' was not declared in this scope
    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
                 ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:52:17: note: suggested alternative: 'UCSZ10'
    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
                 ^~~~~~
                 UCSZ10
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:52:31: error: 'UCSZ01' was not declared in this scope
    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
                               ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:52:31: note: suggested alternative: 'UCSZ11'
    UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
                               ^~~~~~
                               UCSZ11
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:4: error: 'UCSR0B' was not declared in this scope
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
    ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:4: note: suggested alternative: 'UCSR1B'
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
    ^~~~~~
    UCSR1B
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:17: error: 'RXEN0' was not declared in this scope
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
                 ^~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:17: note: suggested alternative: 'RXEN1'
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
                 ^~~~~
                 RXEN1
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:30: error: 'TXEN0' was not declared in this scope
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
                              ^~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:30: note: suggested alternative: 'TXEN1'
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
                              ^~~~~
                              TXEN1
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:43: error: 'RXCIE0' was not declared in this scope
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
                                           ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:54:43: note: suggested alternative: 'RXCIE1'
    UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
                                           ^~~~~~
                                           RXCIE1
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h: In function 'void DcsBios::usart_tx(const char*)':
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:67:13: error: 'UCSR0A' was not declared in this scope
     while(!(UCSR0A & (1<<UDRE0))); // wait until TX buffer is empty
             ^~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:67:13: note: suggested alternative: 'UCSR1A'
     while(!(UCSR0A & (1<<UDRE0))); // wait until TX buffer is empty
             ^~~~~~
             UCSR1A
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:67:26: error: 'UDRE0' was not declared in this scope
     while(!(UCSR0A & (1<<UDRE0))); // wait until TX buffer is empty
                          ^~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:67:26: note: suggested alternative: 'UDRE1'
     while(!(UCSR0A & (1<<UDRE0))); // wait until TX buffer is empty
                          ^~~~~
                          UDRE1
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:68:5: error: 'UDR0' was not declared in this scope
     UDR0 = *c++; // write byte to TX buffer
     ^~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11\src/DcsBios.h:68:5: note: suggested alternative: 'UDR1'
     UDR0 = *c++; // write byte to TX buffer
     ^~~~
     UDR1
Multiple libraries were found for "DcsBios.h"
  Used: C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11
  Not used: C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.3.7
exit status 1

Compilation error: exit status 1

 

I feel that if I can get this one switch to work, the rest will be easier.  As always, any help is greatly appreciated!


Edited by durka-durka

492nd Squadron CO (F-15E): JTF-111 -  Discord Link

Link to comment
Share on other sites

1 hour ago, crash test pilot said:

Delete  " C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11" and try again to compile.

Thanks, now I'm getting an error for when I hover over :

ad.JPG

 

When I try to compile, the error goes to lines 45. When I hover over it, it shows this:

No member named 'setup' in namespace 'DcsBios'; did you mean simply 'setup'? (fix available)clang(no_member_suggest)
MasterArmPanelSketch.ino(44, 6): 'setup' declared here
No quick fixes available

492nd Squadron CO (F-15E): JTF-111 -  Discord Link

Link to comment
Share on other sites

3 hours ago, No1sonuk said:

Download and install this arduino library in the IDE, then try again:
https://github.com/DCSFlightpanels/dcs-bios-arduino-library/releases/tag/0.3.7

I'm going into Sketch>Include Library>Add .ZIP Library and selecting that zip file (I'm not unzipping it).  Right?

 

Because, when I do that, and then it says "library installed" and I go to verify the Sketch, it gives me the same error code.  Is it in the wrong directory or something?

Quote

In file included from L:\Sim Pit\MasterArmPanelSketch.ino\MasterArmPanelSketch\MasterArmPanelSketch.ino:1:0:
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.3.7\src/DcsBios.h: In function 'bool sendDcsBiosMessage(const char*, const char*)':
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.3.7\src/DcsBios.h:159:18: error: 'tryToSendDcsBiosMessage' is not a member of 'DcsBios'
  while(!DcsBios::tryToSendDcsBiosMessage(msg, arg));
                  ^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.3.7\src/DcsBios.h:159:18: note: suggested alternative: 'sendDcsBiosMessage'
  while(!DcsBios::tryToSendDcsBiosMessage(msg, arg));
                  ^~~~~~~~~~~~~~~~~~~~~~~
                  sendDcsBiosMessage
L:\Sim Pit\MasterArmPanelSketch.ino\MasterArmPanelSketch\MasterArmPanelSketch.ino: In function 'void setup()':
L:\Sim Pit\MasterArmPanelSketch.ino\MasterArmPanelSketch\MasterArmPanelSketch.ino:45:12: error: 'setup' is not a member of 'DcsBios'
   DcsBios::setup();
            ^~~~~
L:\Sim Pit\MasterArmPanelSketch.ino\MasterArmPanelSketch\MasterArmPanelSketch.ino:45:12: note: suggested alternative:
L:\Sim Pit\MasterArmPanelSketch.ino\MasterArmPanelSketch\MasterArmPanelSketch.ino:44:6: note:   'setup'
 void setup() {
      ^~~~~
L:\Sim Pit\MasterArmPanelSketch.ino\MasterArmPanelSketch\MasterArmPanelSketch.ino: In function 'void loop()':
L:\Sim Pit\MasterArmPanelSketch.ino\MasterArmPanelSketch\MasterArmPanelSketch.ino:49:3: error: expected primary-expression before ':' token
   :loop();
   ^

exit status 1

Compilation error: 'setup' is not a member of 'DcsBios'

 

492nd Squadron CO (F-15E): JTF-111 -  Discord Link

Link to comment
Share on other sites

The directory is correct, as is the method of adding a library. Your error message stated that you have two dcs-bios librarys:

  Used: C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.2.11
  Not used: C:\Users\Dave\Documents\Arduino\libraries\dcs-bios-arduino-library-0.3.7

So i told you to delete the old one.

I use arduino IDE 1.8.13, maybe you try the actual one from arduino.cc (1.8.19)? I think i read something about the 2.0.0 being a bit "finicky" but i dont remember where... So maybe you give that a try - the scetch looks good from my side.

 

edit:link

https://www.arduino.cc/en/software

 


Edited by crash test pilot
Link to comment
Share on other sites

UPDATE:  I finally got it to work, mostly.  I used the video below to code my arduino as a regular gamepad with buttons only, and tied each switch state to a button.  Funnily enough, the DCS F-16 Controls have some 3-position switches as controls, such as the Master Arm/Off/Simulate control.  

UNfunnily enough, the even though the two autopilot switches are 3-position, only the STG/HDG switch shows up as a 3-position switch, while the main autopilot is just tied to 3 separate buttons.

ag.JPG

So, I have to now figure out a way to get my 3position switch to work for the ATT/ALT Hold switch and I'm golden.  Thanks all for helping me out.

Video I used to code:

Code I used in Arduino IDE:  

Quote

#include <Joystick.h>

//Define Input Pins - joyButton1 1 means Button 1 in Windows will come from Pin1 on the Arduino. joyButton4 4 means Button 4 in Windows goes to Pin4 on the board
#define joyButton1 1
#define joyButton2 2
#define joyButton3 3
#define joyButton4 4
#define joyButton5 5
#define joyButton6 6
#define joyButton7 7
#define joyButton8 8
#define joyButton9 9
#define joyButton10 10
#define joyButton11 11

//Joystick (Joystick HID ID, Joystick Type, Button Count, Hat switch count, include x, include y, include z, include Rx, Include Ry, Include Rz, Include Rudder, Include Throttle, Include Accelerator, Include Brake, Include Steering

Joystick_ Joystick(0x15, JOYSTICK_TYPE_JOYSTICK, 11, 0, false, false, false, false, false, false, false, false, false, false, false);

const bool initAutoSendState = true; //says info sent to board is being sent automatically

//Set button default states
  int lastButton1State = 0;
  int lastButton2State = 0;
  int lastButton3State = 0;
  int lastButton4State = 0;
  int lastButton5State = 0;
  int lastButton6State = 0;
  int lastButton7State = 0;
  int lastButton8State = 0;
  int lastButton9State = 0;
  int lastButton10State = 0;
  int lastButton11State = 0;


 void setup() {
  //put your setup code here, to run once;
  pinMode(joyButton1, INPUT_PULLUP);
  pinMode(joyButton2, INPUT_PULLUP);
  pinMode(joyButton3, INPUT_PULLUP);
  pinMode(joyButton4, INPUT_PULLUP);
  pinMode(joyButton5, INPUT_PULLUP);
  pinMode(joyButton6, INPUT_PULLUP);
  pinMode(joyButton7, INPUT_PULLUP);
  pinMode(joyButton8, INPUT_PULLUP);
  pinMode(joyButton9, INPUT_PULLUP);
  pinMode(joyButton10, INPUT_PULLUP);
  pinMode(joyButton11, INPUT_PULLUP);
   

  Joystick.begin();
 }

 void loop() {
  //put your main code here, to run repeatedly;
  //Button Runtime
  
  int currentButton1State = !digitalRead(joyButton1);
  if (currentButton1State != lastButton1State) {
    Joystick.setButton (0, currentButton1State);
    lastButton1State = currentButton1State;  
  }
  int currentButton2State = !digitalRead(joyButton2);
  if (currentButton2State != lastButton2State) {
    Joystick.setButton (1, currentButton2State);
    lastButton2State = currentButton2State;  
  }
  int currentButton3State = !digitalRead(joyButton3);
  if (currentButton3State != lastButton3State) {
    Joystick.setButton (2, currentButton3State);
    lastButton3State = currentButton3State;  
  }

   int currentButton4State = !digitalRead(joyButton4);
  if (currentButton4State != lastButton4State) {
    Joystick.setButton (3, currentButton4State);
    lastButton4State = currentButton4State;  
  }

  int currentButton5State = !digitalRead(joyButton5);
  if (currentButton5State != lastButton5State) {
    Joystick.setButton (4, currentButton5State);
    lastButton5State = currentButton5State;  
  }

  int currentButton6State = !digitalRead(joyButton6);
  if (currentButton6State != lastButton6State) {
    Joystick.setButton (5, currentButton6State);
    lastButton6State = currentButton6State;  
  }

  int currentButton7State = !digitalRead(joyButton7);
  if (currentButton7State != lastButton7State) {
    Joystick.setButton (6, currentButton7State);
    lastButton7State = currentButton7State;  
  }

    int currentButton8State = !digitalRead(joyButton8);
  if (currentButton8State != lastButton8State) {
    Joystick.setButton (7, currentButton8State);
    lastButton8State = currentButton8State;  
  }

    int currentButton9State = !digitalRead(joyButton9);
  if (currentButton9State != lastButton9State) {
    Joystick.setButton (8, currentButton9State);
    lastButton9State = currentButton9State;  
  }

    int currentButton10State = !digitalRead(joyButton10);
  if (currentButton10State != lastButton10State) {
    Joystick.setButton (9, currentButton10State);
    lastButton10State = currentButton10State;  
  }

    int currentButton11State = !digitalRead(joyButton11);
  if (currentButton11State != lastButton11State) {
    Joystick.setButton (10, currentButton11State);
    lastButton11State = currentButton11State;  
  }


//Pole Delay/Debounce
delay(10);  
 }

Final picture: (It'll be painted and closed up soon)

20220704_155230.jpg

 


Edited by durka-durka

492nd Squadron CO (F-15E): JTF-111 -  Discord Link

Link to comment
Share on other sites

9 minutes ago, durka-durka said:

UNfunnily enough, the even though the two autopilot switches are 3-position, only the STG/HDG switch shows up as a 3-position switch, while the main autopilot is just tied to 3 separate buttons.

So, I have to now figure out a way to get my 3position switch to work for the ATT/ALT Hold switch and I'm golden.  Thanks all for helping me out.

Use a "virtual button" for the centre position.
Read the two inputs in one code block and set the 3 output "buttons" appropriately:

Input_A = off, Input_B = off (Centre) gives  button 12 = off, button 13 = on, button 14 = off

Input_A = on, Input_B = off (Up) gives  button 12 = on, button 13 = off, button 14 = off

Input_A = off, Input_B = on (Down) gives  button 12 = off, button 13 = off, button 14 = on

I showed a way to do this here:

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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