Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Bankable-Smart-Control-Change-Potentiometer.ino

Bankable-Smart-Control-Change-Potentiometer

This example introduces smart bankable potentiometers to prevent values jumping around when changing banks.

Boards: 🛈
AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Teensy 3.x, ESP32, ESP8266

Connections

Connect the left terminal of the potentiometer to ground, and the right one to VCC.
The internal pull-up resistors for the push buttons will be enabled.

Behavior

If you move the potentiometer to, say, 60%, then switch to bank #2, move the potentiometer to 20%, and then switch back to bank #1, the potentiometer will be disabled, until you move it up to 60% again.

This prevents values jumping around in your DAW when cycling through the different banks.

Changing banks is done using the two push buttons. The push button on pin 2 increments the bank number, the push button on pin 3 decrements the bank number.

Mapping

Select the Arduino as a custom MIDI controller in your DAW, and use the MIDI learn option to assign the potentiometer to a function, change the
bank using the buttons, and map the potentiometer again. It will send the MIDI Control Change Channel Volume parameter for channels 1, 2, 3 and 4 (for banks #1, #2, #3 and #4 respectively).

Written by PieterP, 2020-04-09
https://github.com/tttapa/Control-Surface

#include <Control_Surface.h> // Include the Control Surface library
// Instantiate a MIDI over USB interface.
// Four banks to change the channel of the potentiometer
Bank<4> bank;
// Selector to change banks
IncrementDecrementSelector<4> selector {bank, {2, 3}};
// Handy type alias
// Instantiate a CCPotentiometer object
CCSmartPot potentiometer {
{bank, BankType::ChangeChannel}, // Bank configuration
A0, // Analog pin connected to potentiometer
{MIDI_CC::Channel_Volume, Channel_1}, // Channel volume of channel 1
};
/*
* You can do the same for PBSmartPotentiometers (Pitch Bend)
*
* // Handy type alias
* using PBSmartPot = Bankable::PBSmartPotentiometer<4>;
*
* // Instantiate a CCPotentiometer object
* PBSmartPot potentiometer {
* {bank, BankType::ChangeChannel}, // Bank configuration
* A0, // Analog pin connected to potentiometer
* Channel_1, // Channel 1
* };
*/
void setup() {
Control_Surface.begin(); // Initialize Control Surface
}
void loop() {
Control_Surface.loop(); // Update the Control Surface
// You can request the state of the smart potentiometer:
if (potentiometer.getState() == CCSmartPot::Lower) {
// Turn on an LED to indicate that the potentiometer
// value is too low to be active
} else if (potentiometer.getState() == CCSmartPot::Higher) {
// Turn on an LED to indicate that the potentiometer
// value is too high to be active
}
}
@ ChangeChannel
Change the offset of the channel number of the element.
constexpr Channel Channel_1
Definition Channel.hpp:118
The main header file that includes all Control-Surface header files.
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
A class that groups Bankable MIDI Output Elements and Bankable MIDI Input Elements,...
Definition Bank.hpp:94
A class of MIDIOutputElements that read the analog input from a potentiometer or fader,...
void begin()
Initialize the Control_Surface.
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
Selector with two buttons (one to increment, one to decrement).
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over the USB CDC...
constexpr uint8_t Channel_Volume