Skip to content

Commit

Permalink
Add example for tttapa/MIDI_controller#97
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Dec 10, 2019
1 parent 141749a commit 74ff052
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* <https://github.com/tttapa/MIDI_controller/issues/97#issuecomment-564247602>
*
* Many bankable potentiometers and buttons.
*
* @boards Mega
*/

#include <Control_Surface.h>

#include <AH/STL/algorithm> // std::any_of

Bank<4> bank(16);

// Create a new bank selector that changes the bank setting of the bank we just
// created.
// It has push buttons connected to pins 21 and 20 that increment or decrement
// the bank setting, and 4 LEDs to pins 46, 48, 50, 52 that display the current
// bank setting.
IncrementDecrementSelectorLEDs<4> bankSelector = {
bank,
{21, 20}, // button pins
{46, 48, 50, 52}, // LED pins
};

using namespace MIDI_CC;
Bankable::CCPotentiometer potentiometers[] = {
{{bank, BankType::CHANGE_CHANNEL}, A0, {Channel_Volume, CHANNEL_1}},
{{bank, BankType::CHANGE_CHANNEL}, A1, {Channel_Volume, CHANNEL_2}},
{{bank, BankType::CHANGE_CHANNEL}, A2, {Sound_Controller_3, CHANNEL_3}},
{{bank, BankType::CHANGE_CHANNEL}, A3, {Sound_Controller_4, CHANNEL_4}},
{{bank, BankType::CHANGE_CHANNEL}, A4, {Sound_Controller_5, CHANNEL_5}},
{{bank, BankType::CHANGE_CHANNEL}, A5, {Sound_Controller_6, CHANNEL_6}},
{{bank, BankType::CHANGE_CHANNEL}, A6, {Effects_1, CHANNEL_7}},
{{bank, BankType::CHANGE_CHANNEL}, A7, {Effects_2, CHANNEL_8}},
{{bank, BankType::CHANGE_CHANNEL}, A8, {Effects_3, CHANNEL_9}},
{{bank, BankType::CHANGE_CHANNEL}, A9, {Effects_4, CHANNEL_10}},
{{bank, BankType::CHANGE_CHANNEL}, A10, {Effect_Control_1, CHANNEL_11}},
{{bank, BankType::CHANGE_CHANNEL}, A11, {Effect_Control_2, CHANNEL_12}},
};

Bankable::NoteButton muteButtons[] = {
{bank, 13, 0x14},
{bank, 12, 0x15},
{bank, 11, 0x16},
{bank, 10, 0x17},
{bank, 9, 0x18},
{bank, 8, 0x19},
{bank, 7, 0x1A},
{bank, 6, 0x1B},
{bank, 5, 0x1C},
{bank, 4, 0x1D},
{bank, 3, 0x1E},
{bank, 2, 0x1F},
{bank, 14, 0x20},
{bank, 15, 0x21},
{bank, 16, 0x22},
{bank, 17, 0x23},
{bank, 18, {0x33, CHANNEL_2}},
{bank, 19, {0x34, CHANNEL_2}},
};

constexpr pin_t ledPin = 22;

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //

void setup() {
Control_Surface.begin();
pinMode(ledPin, OUTPUT);
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //

void loop() {
Control_Surface.loop();

// Function that checks if a given button is pressed
auto checkButtonPressed = [](const Bankable::NoteButton &button) {
return button.getButtonState() == Button::Pressed;
};
// If any of the push buttons is pressed
bool pressed = std::any_of(std::begin(muteButtons), std::end(muteButtons),
checkButtonPressed);
// Turn on the LED
digitalWrite(ledPin, pressed);
}
13 changes: 13 additions & 0 deletions examples/examples.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,19 @@
* https://github.com/tttapa/Control-Surface/issues/66
*/

/**
* @example "MIDI_controller-97.ino"
*
* MIDI_controller-97
* ==================
*
* <https://github.com/tttapa/MIDI_controller/issues/97#issuecomment-564247602>
*
* Many bankable potentiometers and buttons.
*
* @boards Mega
*/

/**
* @example "Keyboard-Matrix-BCD.ino"
*
Expand Down

0 comments on commit 74ff052

Please sign in to comment.