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
  • Setup prerequisites
  • Board setup
  • Analog switches
  • Switch functions
  1. CB1
  2. Code

Essentials

PreviousCodeNextComplete project

Last updated 1 year ago

Setup prerequisites

This is a RP2040-type board, and you'll essentially treat it as a Raspberry Pi Pico board. Follow to get ready to code.

Board setup

The only thing you need to set up is in 2_Board.ino. Have a look at the very top:

/*
 * Chose your board. Default is to 32U4-based boards. 
 */

//------------------------------
//-----------BOARD MCU----------
//------------------------------

#define BOARDTYPE 0

// 0 -> Atmel 32U4 based boards. (Leonardo, Pro Micro, Feather, Teensy 2.0, etc) SAM3X based boards. (Due)

// 1 -> SAMD21 or SAMD51 based boards. (Arduino Zero and many more)

// 2 -> RP2040 based boards. (Raspberry Pi Pico, Pico W, Pro Micro RP2040, and many more)


//------------------------------
//-------DAHL DESIGN CB1--------
//------------------------------

#define USING_CB1 0

To activate the pre-programmed features for you CB1, set the following:

BOARDTYPE to 2

USING_CB1 to 1

Analog switches

Switch functions

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

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

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

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

	Joystick.sendState();

} //LOOP ENDS HERE

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

That is all. Now, if you have removed components from the board or in general have some advanced setup for switches, have a look at

If you're using analog switches that will produce button numbers (typically rotary switches), you'll have to assign some button numbers to it. More on this in the

We can move directly to start using switch functions now. This is all done in 30_Switches.ino. The various functions used to add firmware code for our switches are found in the

Lets say we have 4 wired to row 1, column pins 1-4. Open 30_Switches tab and you'll find the area between "Switches start here" and "Switches end here" to be empty. The following is all you need:

You've now edited two numbers and written 4 lines of code, your firmware is ready to

Next, look at the guide for a more comprehensive firmware setup.

these instructions
advanced settings.
complete project example.
library.
upload.
complete project
pushbuttons