DDC
  • Welcome
    • Introduction
    • Supported hardware
  • 1: Project planning
    • Switch inputs
      • Switch table
      • Direct
      • Shift register
      • Port expander
    • Analog inputs
      • External ADC
    • RGB LED
    • Digital outputs
    • PWM / Circuit control
    • EEPROM
    • Processing and memory
  • 2. Wiring
    • Switch inputs
      • Matrix
      • Direct
      • Shift register
      • Port expander
    • Analog
      • Analog switches
      • External ADC
    • RGB LED
    • Digital outputs
    • PWM / Circuit control
    • EEPROM
  • 3. Coding
    • Essentials
      • 02_Board.ino
      • 08_Joystick
      • 10_TableAndAnalog.ino
        • Switch table
        • Analog channels
      • 30_Switches.ino
    • Peripherals
      • RGB LED
        • Firmware control
          • LED functions
          • Color
          • Brightness
          • Presets
        • SimHub control
      • Digital outputs
        • Setup
        • SimHub control
        • Firmware control
      • PWM / Circuit control
        • Setup
        • Calibrate
        • Switch control
        • Trigger control
      • Shift register
      • I2C devices
        • ADS1115
        • PCA9555
        • CAT24C512
    • Advanced
      • Analog inject
      • Conditional coding
        • Triggers
        • Editors
      • Field placement
      • Presets
        • 31_RunningPresets.ino
        • 32_Presets.ino
        • Example
    • Upload
    • Naming the controller
  • 4. Connect to SimHub
    • LED control
    • Controller settings and properties
      • How to connect?
      • How does it work?
      • How to control it?
      • Property list
  • Switch library
    • Pushbutton
    • Function switches
    • Toggle switches
    • Hat switches
    • Car control functions
      • QuickSwitch
      • BrakeMagic
      • ThrottleHold
      • Handbrake
    • Pedals & paddles
      • Brake/throttle
      • Clutch
      • Bite point & launch
      • Filtered curves
      • Shifter
    • Funky switch
      • Directional
      • Center push
    • Encoders
      • rotary2Bit
      • rotary4Bit
      • funkyRotary
      • wildEncoder
      • E18
      • rotaryPulse
      • PEC11
    • Rotary switches
      • rotaryAnalog
      • quickRotary
      • SW1
      • Editing functions
    • Multiswitch complexes
      • Hybrid rotary
      • Multifunction rotary
      • Modded encoder
      • Stacked encoder
    • Preset
    • DDS
    • RGB LED control
    • PWM / Circuit control
    • Utility
  • Fast DDC
    • Buttons and LED
    • 4 encoders, buttons and LED
    • Dual clutches, 4 encoders, buttons and LED
    • Dual clutches, 6 encoders, button matrix and LED
  • CB1
    • Ordering
      • Order together
      • Order yourself
        • 1. Open in EasyEDA
        • 2. Export files
        • 3. Edit Pick&Place
        • 4. Pin headers and jumper
        • 5. Order from JLCPCB
    • Wiring
    • Code
      • Essentials
      • Complete project
      • Settings
    • Circuit
    • Shields
      • Robin
  • Collaboration
Powered by GitBook
On this page
  • Direct wiring
  • Setup
  1. 3. Coding
  2. Essentials

30_Switches.ino

PreviousAnalog channelsNextPeripherals

Last updated 2 months ago

This is where you add all your switches. Go to the and find something that suits your needs. Anything you write here should be between the hard-to-miss warnings "SWITCHES START HERE" and "SWITCHES END HERE"

A simple pushbutton on row 3, column 1 would be written as pushButton(3,1);

Direct wiring

With matrix wiring or shift register wiring, you will just use the switch table adresses in the switch functions as explained However, with , you'll have to add some extra lines.

  • You might have asked yourself how your direct wired switches has found their way to the switch table so far. They haven't, they're still floating around. Your direct wired switches needs to have their values read and that value conveyed to a dedicated adress in the table. From there, the switch now behaves as any switch in the switch table, and allows you to use any fuction that works with a matrix wired or shift register wired button.

  • The switchTableInject() function shold be used for every pin on the Arduino that is used for direct wired switches.

  • The function needs to know the pin number to read, the table row and the table column. Like this:

switchTableInject(pin, row, column);

  • If you planned with an encoder on row 1, using column 1 and 2, and using physical Arduino pins 10 and 14, add this:

switchTableInject(10, 1, 1);

switchTableInject(14, 1, 2);

  • If you planned with a button on row 2, using column 5, and using physical Arduino pin 9, add this:

switchTableInject(9, 2, 5);

  • All instances of switchTableInject() should be called before any switch functions.

Setup

This is what the empty 30_Switches looks like:

//------------------------------------
//---------SWITCHES START HERE--------
//------------------------------------




//------------------------------------
//----------SWITCHES END HERE---------
//------------------------------------

Joystick.setZAxis(rotaryField - 32767);
Joystick.setYAxis(buttonField - 32767);

Joystick.sendState();

}

#if (LED1COUNT + LED2COUNT + LED3COUNT + LED4COUNT > 0 && BOARDTYPE == 2)
  void loop()
  {
    processCommands();
  }
#endif
  • A full (and rather feature rich) steering wheel could look like this:

//------------------------------------
//---------SWITCHES START HERE--------
//------------------------------------


    //WHEEL BUTTONS

    pushButton(1, 3);

    pushButton(3, 1);
    pushButton(3, 2);

    pushButton(4, 3);
    pushButton(4, 4);
    pushButton(4, 6);
    pushButton(4, 7);

    pushButton(6, 4);
    pushButton(6, 7);

    pushButton(7, 1);
    pushButton(7, 3);

    pushPull(3, 3, 3, 4, 6, 6, 6, 5, 7);

    toggleM(6, 3, 6);
    brakeMagic(7, 2, 4);

    //SPECIALS

    modButton(1, 7);
    neutralButton(4, 5);
    biteButton(1, 5);
    presetButton(1, 6);
    quickSwitch(1, 4);
    throttleHold(3, 5, 7, 4, true);

    //ENCODERS

    rotary2Inc(1, 1, false);
    rotary2Inc(4, 1, false);

    rotary2Inc(3, 6, true);
    rotary2Inc(6, 1, false);


    //FUNKY SWITCHES
    funkyButtonDDButton(5, 4, 5, 1, 6, 7);
    funkyButtonHybrid(5, 6, 5, 1, 4, 7);
    funkyButton(5, 1, 5, 4, 6, 7);
    funkyButton(5, 7, 5, 1, 4, 6);
    funkyPush(5, 5, 1, 4, 6, 7);

    DDSfunky(5, 2, 3);

    funkyButton(2, 1, 5, 2, 4, 7);
    funkyButton(2, 2, 5, 1, 4, 7);
    funkyButton(2, 4, 5, 1, 2, 7);
    funkyButton(2, 7, 5, 1, 2, 4);
    funkyPush(2, 5, 1, 2, 4, 7);
    funkyRotary(2, 3, 6);

    //ANALOG INPUTS


    rotaryAnalog2Mode(
        1                                                             //Analog channel
        3,                                                            //Field placement
        16, 107, 200, 291, 383, 474, 566, 657, 749, 841, 932, 1023,   //Switch position values
        false);                                                       //Rotation direction

    rotaryAnalog2Mode(
        2,                                                            //Analog channel
        2,                                                            //Field placement
        16, 107, 200, 291, 383, 474, 566, 657, 749, 841, 932, 1023,   //Switch position values
        false);                                                       //Rotation direction

    dualClutch(
        3                                                             //Analog channel (Master)
        571,                                                          //Released value (Master
        169,                                                          //Fully pressed value (Master)
        4,                                                            //Analog channel (Slave)
        527,                                                          //Released value (Slave)
        882,                                                          //Fully pressed value (Slave)
        true);                                                        //True = Master/Slave paddle is Throttle/Brake in mode 4. False is opposite.

   
//------------------------------------
//----------SWITCHES END HERE---------
//------------------------------------

Joystick.setZAxis(rotaryField - 32767);
Joystick.setYAxis(buttonField - 32767);

Joystick.sendState();

}

#if (LED1COUNT + LED2COUNT + LED3COUNT + LED4COUNT > 0 && BOARDTYPE == 2)
  void loop()
  {
    processCommands();
  }
#endif
}

Switch Library
direct wiring
below.