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
  • Planning the switch table
  • Pins (in case of matrix wiring)
  • Rules
  • Assigning button numbers
  1. 1: Project planning
  2. Switch inputs

Switch table

PreviousSwitch inputsNextDirect

Last updated 1 year ago

This section will explain how to plan the switch table. No matter how you chose to wire your switches to the microcontroller, they have to end up in the table in the firmware. You'll have to plan your controllers switches accordingly, and there are some rules to follow. For matrix wiring, the wiring will naturally match the firmware table. For switches that are wired to the microcontroller, or through or , there are some additional things to pay attention to.

Planning the switch table

I use a spreadsheet to plan the switch table for my projects, with the switches represented as blocks. I will refer to blocks for the remainder of this guide. I also give blocks different colors according to what I'm going to use the switch for; neutral button, bite point button, modifier button, etc. This is not need, it is just to get an overview.

The numbers in the cells are , more on this later.

image

This table is from an early edition of the Dahl Design SW1 steering wheel, which uses DDC to build its firmware.

Every block is an adress in the table. Most switches just need 1 block. As an example, the brown block on Row 1, Column 5 represents a standard simple pushbutton used to set the bite point. Its adress is R1C5, or (1,5) in the code. If you dive deeper into the algorithms, its adress in the table is actually [0][4], since the tables in the code starts with 0, and not 1. Along with this adress, the sketch gives this button a whole bunch of variables connected to this adress; used for debouncing, determining how the switch works, storing information, duration of trigger pulses and much more.

Block demand

1 block

  • Simple pushbutton

  • On-off toggle

2 block

  • 2-bit encoders

    • CTS 288

    • CTS 12CE/11CE

    • Bourns PEC11

    • Alps EC11

    • TT Electronics EN11

    • Alps SRBM

    • Encoder on Alps RKJXT1F42001

    • ELMA E33

    • ELMA E18

    • Many more..

  • 3-way toggles (typically on-off-on)

3 block

  • 2-bit encoder with pushbutton (2 + 1 blocks)

4 block

  • 4-bit encoders

    • Grayhill Series 26

    • Bourns PAC18R

    • Panasonic EVQV9

    • Many more..

  • Hat switch without center pushbutton

5 block

  • 4-bit encoder with pushbutton

  • Alps RKJXM1015004

  • Any other hat switch with center pushbutton

7 block

  • Alps RKJXT1F42001 (5 + 2 blocks)

Pins (in case of matrix wiring)

Each row and column in the matrix needs 1 digital pin from your microcontroller. The example above has 7 rows and 7 columns, and uses a total of 14 pins.

In this example, the project has a bit fewer switches, and can do fine with a smaller matrix. 5 rows and 6 columns for a total of 11 pins needed.

Rules

In order to make the algorithms more memory- and processing friendly, they will make some assumptions regarding switch placement in the table. This means you have to follow some rules:

  • As a general rule, a switch needs all its blocks on the same row.

  • Rotary encoders, 2-bit (2 blocks) or 4-bit (4 blocks) will require you to put all the switch blocks next to eachother. As in this example, 2-bit encoders marked in red.

  • The rotary encoder on "funky" switches can have their blocks seperated, but still needs to be on the same row. Encoder blocks on row 2 are seperated, on row 5 next to eachother. Both are fine.

  • For 7-way switches, the position+push buttons (light blue and purple) all need to be on the same row, reserving 5 blocks. They don't need to be next to eachother or in any order. The encoder (orange) can be placed on a different row, and regarded as an individual switch. This means that if you include a 7-way switch into your project, you'll need at least 5 columns.

  • Encoders with pushbuttons can be regarded as two individual switches; an encoder and a simple pushbutton. This means the two can be placed on different rows. If you wired one of the pushbutton pins to the encoder common, they must be on the same row.

  • Unused spaces in the table is perfectly fine, but try to plan it so that you can use the smallest matrix possible - as these slots will still be processed and will take up memory.

Assigning button numbers

  • Button numbers go from 0 to 127. Button 0 in DDC is regarded as button 1 by Windows, returned as B0 by SimHub. Button 23 in DDC is button 24 in Windows, etc.

  • The following special buttons will not need a button number:

    • Hybrid button

    • DDButton

    • ThrottleHold button

    • Handbrake button

    • Preset next/previous

    • Bite pot locker

  • Any unused button/open slot in the table can safely be assigned 0.

  • Buttons and toggles that uses a single block simply uses the number assigned to that block.

  • Encoders:

    • An incremental encoder uses two button numbers (one for CW rotation, one for CCW). You just need to write the first of these numbers in the first encoder block in the matrix (leftmost).

This 2-bit encoder will use button numbers 23 and 24, and the 4-bit encoder use button numbers 10 and 11.

  • If you use a switch function that gives the encoder a multi-position mode, the starting number of the multi position mode goes in the first block. If this function also includes an incremental mode, the starting number of the incremental mode goes into the second block.

This 2-bit encoder has been used in a function that has a 8-position mode and an incremental mode. It will then use button numbers 23-30 in the 8-position mode and button numbers 31 and 32 in the incremental mode. If the 4-bit encoder is set up the same way, it will use button numbers 10-17 for the 8-position mode and button numbers 10 and 11 in the incremental mode.

  • For funky switch encoders, the same principle applies, just that the two blocks arent necessarily next to eachother.

  • Any encoder blocks that dont need a number in them can be assigned a 0, or any other number. It won't ever be used. Though, some kind of number should be there, as you'll need that when we start working on the code.

image
image
image
image
image
image
image
image
directly
shift registers
port expanders
button numbers