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. Switch library

PWM / Circuit control

PreviousRGB LED controlNextUtility

Last updated 4 months ago

These functions control .

Generally, these functions will adjust the channel volume (0 - 100% within the set PWM range on the channel) or turn the channel on/off (switching between the set volume and outputting 0V on the PWM channel).

PWMToggle()

Use a toggle switch to turn a PWM channel on/off, or just use a regular button (will have to be held pressed unless it is a physically latching button).

void PWMToggle(int row, int column, int PWMChannel)

Example:

  • A toggle switch on row 4 column 2.

  • Controlling PWM channel 3.

PWMToggle(4, 2, 3);

  • 1 PWM channel

PWMPot()

Set up a potentiometer to adjust the volume of a PWM channel.

void PWMPot(int analogChannel, int startValue, int endValue, int PWMChannel )

Example:

  • Potentiometer on analog channel 2.

  • Using checkValue(2) in 30_switches we've found the range of the potentiometers values to be 0 to 1021.

  • Controlling PWM channel 3 volume.

PWMPot(2, 0, 1021, 3);

  • 1 PWM channel

rotary2PWM()

Standard incremental encoder in the rotary2bit . Rotating CW will give a button pulse, rotating CCW will give a button pulse with a button number 1 value higher.

Holding the modButton will make this encoder adjust the PWM volume up and down by a custom increment.

void rotary2PWM(int row, int column, bool reverse, int8_t PWMChannel, int8_t stepSize)

Example:

  • Encoder with pins A and B to columns 3 and 4. Common pin to row 2.

  • Controlling PWM channel 3 volume with increments of 5%.

rotary2PWM(2, 3, false, 3, 5);

The button numbers used is determined by the number written in the block for the A pin. B pin block will not be read. If button number was set to 15, the switch will use buttons 15 and 16. The reverse part of the function will switch the button numbers if set to true.

  • 2 button numbers

  • modButton()

  • 1 PWM channel

funkyPWM()

Standard incremental encoder in the funkyRotary . Rotating CW will give a button pulse, rotating CCW will give a button pulse with a button number 1 value higher.

Holding the modButton will make this encoder adjust the PWM volume up and down by a custom increment.

void funkyPWM(int Arow, int Acolumn, int Bcol, bool reverse, int8_t PWMChannel, int8_t stepSize)

Example:

  • Encoder with pins A and B to columns 3 and 4. Common pin to row 2.

  • Controlling PWM channel 3 volume with increments of 5%.

funkyPWM(2, 3, 4, false, 3, 5);

The button numbers used is determined by the number written in the block for the A pin. B pin block will not be read. If button number was set to 15, the switch will use buttons 15 and 16. The reverse part of the function will switch the button numbers if set to true.

  • 2 button numbers

  • modButton()

  • 1 PWM channel

PEC11PWM()

Standard incremental encoder in the PEC11 Rotating CW will give a button pulse, rotating CCW will give a button pulse with a button number 1 value higher.

Holding the modButton will make this encoder adjust the PWM volume up and down by a custom increment.

void PEC11PWM(int row, int column, bool reverse, int8_t PWMChannel, int8_t stepSize)

Example:

  • Encoder with pins A and B to columns 3 and 4. Common pin to row 2.

  • Controlling PWM channel 3 volume with increments of 5%.

PEC11PWM(2, 3, false, 3, 5);

The button numbers used is determined by the number written in the block for the A pin. B pin block will not be read. If button number was set to 15, the switch will use buttons 15 and 16. The reverse part of the function will switch the button numbers if set to true.

  • 2 button numbers

  • modButton()

  • 1 PWM channel

rotaryPulsePWM()

Holding the modButton will make this encoder adjust the PWM volume up and down by a custom increment.

void rotaryPulsePWM(int row, int column, bool reverse, int8_t PWMChannel, int8_t stepSize)

Example:

  • Encoder with pins A and B to columns 3 and 4. Common pin to row 2.

  • Controlling PWM channel 3 volume with increments of 5%.

rotaryPulsePWM(2, 3, false, 3, 5);

The button numbers used is determined by the number written in the block for the A pin. B pin block will not be read. If button number was set to 15, the switch will use buttons 15 and 16. The reverse part of the function will switch the button numbers if set to true.

  • 2 button numbers

  • modButton()

  • 1 PWM channel

rotaryAnalogPWM()

12 - position switch. Absolute.

void rotaryAnalogPWM(int analogChannel, int PWMChannel, int pos1, int pos2, int pos3, int pos4, int pos5, int pos6, int pos7, int pos8, int pos9, int pos10, int pos11, int pos12, bool reverse)

Switch setup with explainations:

rotaryAnalogPWM(

2, <- The analog channel this switch is set up on

2, <- The PWM channel it controls

16, 107, 200, 291, 383, 474, 566, 657, 749, 841, 932, 1023, <- Switch position values

false); <- Direction is not reversed, so CW rotation increasese button number.

  • This switch has "reverse" set to true, which can be a good idea if it is placed horizontally on the right side. Turning it CCW will now increase the brightness instead of reducing. So typed out in 30_Switches.ino:

rotaryAnalogPWM(2, 2, 16, 107, 200, 291, 383, 474, 566, 657, 749, 841, 932, 1023, false);

This switch will set the volume to 0% in position 1 and 100% in position 12. The positions in between will be a gradual increase from 0 to 100%.

  • 1 PWM channel

rotaryAnalogPWM12()

12 - position switch. Absolute.

void rotaryAnalogPWM12(int analogChannel, int PWMChannel, int stepSize, int pos1, int pos2, int pos3, int pos4, int pos5, int pos6, int pos7, int pos8, int pos9, int pos10, int pos11, int pos12, bool reverse)

Switch setup with explainations:

rotaryAnalogPWM12(

2, <- The analog channel this switch is set up on

2, <- The PWM channel it controls

5, <- The increments of volume adjustment

16, 107, 200, 291, 383, 474, 566, 657, 749, 841, 932, 1023, <- Switch position values

false); <- Direction is not reversed, so CW rotation increasese button number.

  • This switch has "reverse" set to true, which can be a good idea if it is placed horizontally on the right side. Turning it CCW will now increase the brightness instead of reducing. So typed out in 30_Switches.ino:

rotaryAnalogPWM12(2, 2, 5, 16, 107, 200, 291, 383, 474, 566, 657, 749, 841, 932, 1023, false);

  • 12 button numbers

  • modButton()

  • 1 PWM channel

Standard incremental encoder in the rotaryPulse . Rotating CW will give a button pulse, rotating CCW will give a button pulse with a button number 1 value higher.

Produces no button presses, but the position of the switch is still detected by the firmware and can be used for or . The switch works like a volume knob for a PWM channel.

Works similar to, but with the added feature of producing button presses in each position. To adjust PWM volume you'l have to hold a modButton. Adjustments are with a custom increment.

PWM channels
conditional coding
category
category
category.
category
rotaryInject
rotaryAnalogSimple()