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
  1. 3. Coding
  2. Advanced
  3. Conditional coding

Editors

These are simple functions that can be used with conditional coding to edit stuff that is more deeply rooted in the firmware.

setButtonNumber(int row, int column, int number)

Changing the button number for a switch in the switch table. Chose the row and column and what to update the button number with. Example: setButtonNumber(2,3,13); will set the button number to switch on row 2 column 3 to 13 (shown as 14 in Windows).

setAnalogButtonNumber(int analogChannel, int layer, int number)

Changing the button number for a analog switch. Chose the analog channel and which "layer" to put the number in - refering to the two arrays with button numbers under 10_TableAndAnalog. Layer 1 is the top one, Layer 2 is the bottom one. These are the only two options.

  • Layer 1 is typically for multiposition button numbers

  • Layer 2 is typically for the two button numbers used in incremental switch mode

Example: setAnalogButtonNumber(2,1,42); will set the button number to analog channel 2 in the upper layer to 42 (shown as 43 in Windows).

setSwitchMode(int row, int column, int mode)

Changing the switch mode for a switch in the switch table. Mode can only be 0 or 1. For switches with 4 modes, typically two adresses in the switch table are used - both the column adresses for the switch (only encoders that have 4 switch modes, they have at least two column adresses).

Example: setSwitchMode(1,1,0); will set the mode of the switch on row 1 column 1 to 0.

setAnalogSwitchMode(int analogChannel, int modeBit, int modeValue)

Changing the switch mode for an analog channel. Some of the analog switch functions have more than 2 modes - using more than 1 bit. Dual clutch for instance has 4 modes (0-3), using 2 bits. So to change into clutch modes 2 and 3 you need to make two of these functions. Lets see how to set a clutch into mode 3, which is binary 11:

setAnalogSwitchMode(5,1,1);

setAnalogSwitchMode(5,2,1);

Both act on analog channel 5. We're setting the 1st bit to 1 and the 2nd bit to 1. That would be 11, switch mode 3.

sendToButtonField(int fieldPosition, bool condition)

Set a selected bit in buttonField (the first bit being bit 1, not 0) to 0 or 1 depending on the result of a condition. You can use triggers for conditions or write your own.

sendToButtonField(2, modButtonPressed());

This will set bit #2 in buttonField to 1 if the mod button is pressed.

sendToButtonField(4, rotaryPosition(2, 6));

This will set bit #4 in buttonField to 1 if the rotary switch on analog channel 2 is in position 6.

sendToRotaryField(int fieldPosition, bool condition)

Same as above, but to rotaryField instead of buttonField.

PreviousTriggersNextField placement

Last updated 4 months ago