Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Enable-disable.ino

Enable-disable

This example shows how to dynamically enable or disable specific MIDI elements.

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

Connections

The internal pull-up resistor for the button will be enabled automatically. Connect the left terminal of the potentiometer to ground, and the right one to VCC.

Behavior

At program start-up, the potentiometer is enabled, and it sends MIDI Pitch Bend messages when its position changes. By pressing the push button, the potentiometer is disabled (this is indicated by the on-board LED turning off). When disabled, Control Surface stops sampling the analog input of the potentiometer, and no Pitch Bend messages are sent for this MIDI output element (any other elements are unaffected). Pressing the push button again enables the potentiometer again.

Written by PieterP, 2018-07-26
https://github.com/tttapa/Control-Surface

Button enableButton = 2; // Momentary push button between pin 2 and ground
PBPotentiometer masterVolume {A0, Channel_9}; // Potentiometer to pin A0
void setup() {
enableButton.begin();
// Note: if you disable an element before calling Control_Surface.begin(), you
// are responsible for initializing it manually (using the begin() method of
// that element).
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
}
void loop() {
if (enableButton.getState() == Button::Falling) {
static bool state = true;
digitalWrite(LED_BUILTIN, state);
state ? masterVolume.enable() : masterVolume.disable();
}
}
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
constexpr Channel Channel_9
Definition Channel.hpp:126
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 for reading and debouncing buttons and switches.
Definition Button.hpp:15
State getState() const
Get the state of the button, without updating it.
Definition Button.cpp:32
void begin()
Initialize (enable the internal pull-up resistor).
Definition Button.cpp:7
void begin()
Initialize the Control_Surface.
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
A class of MIDIOutputElements that read the analog input from a potentiometer or fader,...
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
MIDIBLEState * state