Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Control_Surface.h> //Program--include library-- then select "control surface" library..Vamos a programar el codigo con la librería Control Surface
- USBMIDI_Interface usbmidi; //initializes device as usb_midi interface...see other examples like hardwareserial,hairles etc
- /* Instantiate a multiplexer with three address lines. */
- Bank<6> bank(4); // A bank with three channels, and 6 bank settings..creamos 6 bancos con 6 ajustes posibles distintos con tres canales..el intervalo de cambio entre los valores sera de +-3, Cada vez que cambiemos de un banco a otro sumara o decrecera +-3 MIDI CC
- /* The number of buttons and LEDs */
- #include <Adafruit_NeoPixel.h>
- #include <avr/power.h>
- //Designamos nuestro pin de datos
- #define PIN 40
- //Designamos cuantos pixeles tenemos en nuestra cinta led RGB
- #define NUMPIXELS 6
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- CCPotentiometer potentiometer4 = { A4, {42, CHANNEL_6} }; //establecemos el pin analogico A4 para un potenciometro analogico 10k al que llamaremos potentiometer4..la salida analogica A4 mandara mensajes MIDI 42 CC en el canal 6
- CCPotentiometer potentiometer5 = { A5, {43, CHANNEL_6} };
- CCPotentiometer potentiometer6 = { A6, {44, CHANNEL_6} };
- CCPotentiometer potentiometer7 = { A7, {45, CHANNEL_6} };
- CCPotentiometer potentiometer8 = { A8, {46, CHANNEL_10} };
- CCPotentiometer potentiometer9 = { A9, {47, CHANNEL_11} };
- CCPotentiometer potentiometer10 = { A10, {48, CHANNEL_12} };
- CCPotentiometer potentiometer11 = { A11, {49, CHANNEL_13} };
- CCPotentiometer potentiometer12 = { A12, {50, CHANNEL_14} };
- CCPotentiometer potentiometer13 = { A13, {51, CHANNEL_15} };
- CCPotentiometer potentiometer14 = { A14, {MIDI_CC::Channel_Volume, CHANNEL_16} };
- //CCButton button12 = { 12, {MIDI_CC::General_Purpose_Controller_8, CHANNEL_1}, };
- CCButtonLatched button9 = { 9, {32, CHANNEL_1}, };
- CCButtonLatched button10 = { 10, {33, CHANNEL_1}, };
- CCButtonLatched button22 = { 22, {37, CHANNEL_1}, };
- CCButtonLatched button23 = { 23, {38, CHANNEL_1}, };
- CCButtonLatched button24 = { 24, {39, CHANNEL_1}, };
- CCButtonLatched button25 = { 25, {60, CHANNEL_1}, };
- CCButtonLatched button26 = { 26, {61, CHANNEL_1}, };
- CCButtonLatched button27 = { 27, {62, CHANNEL_1}, };
- CCButtonLatched button28 = { 28, {63, CHANNEL_1}, };
- CCButtonLatched button29 = { 29, {64, CHANNEL_1}, };
- CCButtonLatched button30 = { 30, {65, CHANNEL_1}, };
- CCButtonLatched button31 = { 31, {15, CHANNEL_1}, };
- CCButtonLatched button32 = { 32, {14, CHANNEL_1}, };
- CCButtonLatched button33 = { 33, {13, CHANNEL_1}, };
- CCButtonLatched button34 = { 34, {12, CHANNEL_1}, };
- CCButtonLatched button35 = { 35, {11, CHANNEL_1}, };
- Bankable::CCPotentiometer pots[] = { //los potenciometros conectados A0;A1 y A2 empiezan en 67,68 y 69 respectivamente de CC y cada vez que pulsemos el boton 8 incrementaran un valor de CC hasta 4 veces (el potenciometro con CC 67 llegara al CC 71 y luego volvera a 67 en la siguiente pulsacion del boton 8)
- {bank, A0, 66},
- {bank, A1, 67},
- {bank, A2, 68},
- {bank, A3, 69}
- };
- //IncrementSelector<2> selector { bank, 2, };
- Bankable::CCButtonLatched<6> bankbuttons [] = {
- { bank, 5, 90, }, //los botones de los pines 5 y 6 empiezan en 90 y 91 respectivamente de CC y cada vez que pulsemos el boton 8 incrementaran un valor de CC hasta 4 veces (el 90 llegara al 94 y luego volvera a 90 en la siguiente pulsacion del boton 8).el boton 7 es lo contrario del 8
- { bank, 6, 91, },
- };
- Bankable::CCButtonLatched<6> button6 { bank, 6, 91, };
- IncrementDecrementSelectorLEDs<6> bankSelector = {
- bank,
- {7, 8}, // button pins
- {46, 48, 49, 50, 51, 52}, // LED pins
- }; //establecemos los pines 7 y 8 como los pines para crecer o decrecer el banco configurado (cuatro ajustes distintos para ese banco configurado)
- constexpr pin_t ledPin = 22;
- void setup() {
- Control_Surface.begin();
- pixels.begin();
- pinMode(ledPin, OUTPUT);
- }
- /*mux.begin();
- sreg.begin();
- for (Button &button : buttons)
- button.begin();*/
- void loop() {
- Control_Surface.loop();
- uint32_t rojo = pixels.Color(150,0,0);
- pixels.setPixelColor(1, rojo); // Brillo moderado en rojo (el led numero dos de la tira de leds se queda encendido con color rojo)
- pixels.show(); // Mostramos y actualizamos el color del pixel de nuestra cinta led RGB
- /*lo siguiente es para los leds de los bancos*/
- // Function that checks if a given button is pressed
- auto checkButtonPressed = [](const Bankable::CCButtonLatched<6> &button) {
- return button.getButtonState() == Button::Pressed;
- };
- // If any of the push buttons is pressed
- bool pressed = std::any_of(std::begin(bankbuttons), std::end(bankbuttons),
- checkButtonPressed);
- // Turn on the LED
- digitalWrite(ledPin, pressed);
- }
Advertisement
Add Comment
Please, Sign In to add comment