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
  • Rows and columns
  • uint8_t row[] = {0,0,0,0,0};
  • uint8_t col[] = {0,0,0,0,0};
  • uint8_t directPins[] = {99};
  • Direct wiring/shift registers
  • Button numbers
  1. 3. Coding
  2. Essentials
  3. 10_TableAndAnalog.ino

Switch table

//-----------------------------------------
//------------TABLE VARIABLES-------------
//-----------------------------------------

uint8_t row[] = { 0, 0, 0, 0, 0 };
const uint8_t rowCount = sizeof(row) / sizeof(row[0]);

uint8_t col[] = { 0, 0, 0, 0, 0 };
const uint8_t colCount = sizeof(col) / sizeof(col[0]);

//---------------------------------------
//--------TABLE DESCRIPTION-------------
//---------------------------------------

const uint8_t buttonNumber[rowCount][colCount] =
{
  {0, 0, 0, 0, 0},	//ROW 1
  {0, 0, 0, 0, 0},	//ROW 2
  {0, 0, 0, 0, 0},	//ROW 3
  {0, 0, 0, 0, 0},	//ROW 4
  {0, 0, 0, 0, 0}	//ROW 5
};

//---------------------------------------
//------------DIRECT INPUT---------------
//---------------------------------------


uint8_t directPins[] = { 99 };
const uint8_t directPinsCount = sizeof(directPins) / sizeof(directPins[0]);

//---------------------------------------
//------------DIRECT OUTPUT--------------
//---------------------------------------

#define enableOutput 0
uint8_t outputPins[] = { 99};
const uint8_t outputPinsCount = sizeof(outputPins) / sizeof(outputPins[0]);


//---------------------------------------
//--------ANALOG DESCRIPTION-------------
//---------------------------------------

#define analogSwitchCount 1

const uint8_t analogButtonNumber[analogSwitchCount] =         //ANALOG BUTTONS 1
{ 0 };

const uint8_t analogButtonNumberIncMode[analogSwitchCount] =  //ANALOG BUTTONS 2
{ 0 };

Rows and columns

We start by describing the rows and columns; their size and which pins they are connected to.

uint8_t row[] = {0,0,0,0,0};

Insert pin numbers for your rows, starting with first row. Defaults to 5 rows, reduce/increase to whatever you have in your project.

uint8_t row[] = {15,14,16,10};

uint8_t col[] = {0,0,0,0,0};

The same as above. For the example picture this will be:

uint8_t col[] = {3,4,5,6,7};

uint8_t directPins[] = {99};

  • Only relevant if using direct wiring. List the actual microcontroller input pin numbers that these switches are connected to. The order doesn't matter, this is just used for pulling up the pins. Default is "99", which is just a dummy that fills the array with someting.

As an example:

uint8_t directPins[] = {2,3,16,15,10,8,9};

Direct wiring/shift registers

When using direct wiring or shift registers, the rows and columns aren't actual microcontroller input pins - we'll use dummy-pins instead, which is "99".

Any row or column that only has direct wired switches or shift registers on them, should be written as "99". The reason we have to use a dummy is that we need to build a matrix in the firmware with the correct size. As mentioned earlier, each switch needs a slot in the firmware matrix to get memory to store switch states, timers for debouncing, etc.

uint8_t row[] = {99};

uint8_t col[] = {99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99};

uint8_t row[] = {99,99,99,99};

uint8_t col[] = {99,99,99,99};

  • A hybrid system with the first two rows reserved for direct wired switches could look like this:

uint8_t row[] = {99,99,4,5,16};

uint8_t col[] = {15,10,14,7};

The pin numbers used here are just examples.

  • An extreme example with several bundles of shift registers, matrix wiring and direct wiring in the same project:

Here, the first 5 rows are dummy-rows. But also columns 5-8, since here are only shift registers and/or direct wired switches. In essence, only the matrix wired part (rows 6-8 and columns 1-4) should have real pin numbers, the rest are "99".

uint8_t row[] = {99,99,99,99,99,4,5,16};

uint8_t col[] = {15,10,14,7,99,99,99,99};

Button numbers

The reason why I set up my switch table in a spreadsheet is this:

const uint8_t buttonNumber[rowCount][colCount] =
{
  {20, 0, 4, 5, 6},     //ROW 1
  {9, 10, 11, 12, 13},  //ROW 2
  {14, 0, 8, 22, 0},    //ROW 3
  {16, 0, 7, 18, 0},    //ROW 4
  {0, 1, 2, 3, 0}       //ROW 5
};

You simply copy your switch table to this one. By default it is a 5 x 5 table. Adjust it accordingly. 4 x 7 would be like this:

const uint8_t buttonNumber[rowCount][colCount] =
{
  {0, 0, 0, 0, 0, 0, 0},     //ROW 1
  {0, 0, 0, 0, 0, 0, 0},     //ROW 2
  {0, 0, 0, 0, 0, 0, 0},     //ROW 3
  {0, 0, 0, 0, 0, 0, 0},     //ROW 4
};

Previous10_TableAndAnalog.inoNextAnalog channels

Last updated 9 months ago

If wired like the board at the top of , you'd write it like this:

These examples from :

image
3.Wiring
1. Project planning