Custom-Selector-Callback
This example demonstrates how to use custom callbacks to display the value of a selector.
- Boards: 🛈
- AVR, AVR USB, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Due, Teensy 3.x, ESP8266, ESP32
Connections
- 10: Red pin of an RGB LED (+ series resistor)
- 11: Green pin of an RGB LED (+ series resistor)
- 12: Blue pin of an RGB LED (+ series resistor)
- 2: Push button (to ground, internal pull-up resistor will be used)
- 3: Push button (to ground, internal pull-up resistor will be used)
Connect the common cathode of the RGB LED to ground.
Behavior
The LEDs display the current setting of the bank. Red is the first bank (0), yellow is the second bank (1), green is the third bank (2), cyan is the fourth bank (3), blue is the fifth bank (4), and purple is the sixth bank (5).
Use the two push buttons to change the setting. The one on on pin 2 increments the setting, the one on pin 3 decrements the setting.
Keeping one of the buttons pressed will keep on cycling through the settings until you let go of it.
Pressing both buttons simultaneously resets the setting to its initial value.
Note: this example doesn't send any MIDI, but you could use it as a template for a MIDI controller with banks.
Mapping
None.
Written by PieterP, 2020-02-03
https://github.com/tttapa/Control-Surface
class MySelectorCallback {
public:
MySelectorCallback(pin_t redLED, pin_t greenLED, pin_t blueLED)
: redLED(redLED), greenLED(greenLED), blueLED(blueLED) {}
void begin() {
show(0);
}
void update() {}
(void)oldSetting;
show(newSetting);
}
private:
uint8_t color = getColor(setting);
digitalWrite(redLED, color & 0b001 ?
HIGH :
LOW);
digitalWrite(greenLED, color & 0b010 ?
HIGH :
LOW);
digitalWrite(blueLED, color & 0b100 ?
HIGH :
LOW);
}
switch (setting) {
case 0: return 0b001;
case 1: return 0b011;
case 2: return 0b010;
case 3: return 0b110;
case 4: return 0b100;
case 5: return 0b101;
default: return 0b000;
}
}
private:
pin_t redLED, greenLED, blueLED;
};
bank,
{10, 11, 12},
{2, 3},
};
void setup() {
}
void loop() {
}
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
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.
uint8_t setting_t
The type used for Selectors.
@ Wrap
When the maximum (minimum) setting is reached, wrap around to the minimum (maximum) setting.
A class that groups Bankable MIDI Output Elements and Bankable MIDI Input Elements,...
void begin()
Initialize the Control_Surface.
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.