CigarroPuro

Untitled

Mar 4th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Control_Surface.h>  //Program--include library-- then select "control surface" library..Vamos a programar el codigo con la librería Control Surface
  2. USBMIDI_Interface usbmidi;    //initializes device as usb_midi interface...see other examples like hardwareserial,hairles etc
  3. /* Instantiate a multiplexer with three address lines. */
  4.  
  5. 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
  6. /* The number of buttons and LEDs */
  7.  
  8.  
  9.  
  10.  
  11. #include <Adafruit_NeoPixel.h>
  12. #include <avr/power.h>
  13.  
  14. //Designamos nuestro pin de datos
  15. #define PIN 40
  16. //Designamos cuantos pixeles tenemos en nuestra cinta led RGB
  17. #define NUMPIXELS      6
  18.  
  19. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  20.  
  21.  
  22. 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
  23. CCPotentiometer potentiometer5 = { A5, {43, CHANNEL_6} };
  24. CCPotentiometer potentiometer6 = { A6, {44, CHANNEL_6} };
  25. CCPotentiometer potentiometer7 = { A7, {45, CHANNEL_6} };
  26. CCPotentiometer potentiometer8 = { A8, {46, CHANNEL_10} };
  27. CCPotentiometer potentiometer9 = { A9, {47, CHANNEL_11} };
  28. CCPotentiometer potentiometer10 = { A10, {48, CHANNEL_12} };
  29. CCPotentiometer potentiometer11 = { A11, {49, CHANNEL_13} };
  30. CCPotentiometer potentiometer12 = { A12, {50, CHANNEL_14} };
  31. CCPotentiometer potentiometer13 = { A13, {51, CHANNEL_15} };
  32. CCPotentiometer potentiometer14 = { A14, {MIDI_CC::Channel_Volume, CHANNEL_16} };
  33.  
  34.  
  35. //CCButton button12 = { 12, {MIDI_CC::General_Purpose_Controller_8, CHANNEL_1}, };
  36. CCButtonLatched button9 = { 9, {32, CHANNEL_1}, };  
  37. CCButtonLatched button10 = { 10, {33, CHANNEL_1}, };
  38. CCButtonLatched button22 = { 22, {37, CHANNEL_1}, };
  39. CCButtonLatched button23 = { 23, {38, CHANNEL_1}, };
  40. CCButtonLatched button24 = { 24, {39, CHANNEL_1}, };
  41. CCButtonLatched button25 = { 25, {60, CHANNEL_1}, };
  42. CCButtonLatched button26 = { 26, {61, CHANNEL_1}, };
  43. CCButtonLatched button27 = { 27, {62, CHANNEL_1}, };
  44. CCButtonLatched button28 = { 28, {63, CHANNEL_1}, };
  45. CCButtonLatched button29 = { 29, {64, CHANNEL_1}, };
  46. CCButtonLatched button30 = { 30, {65, CHANNEL_1}, };
  47. CCButtonLatched button31 = { 31, {15, CHANNEL_1}, };
  48. CCButtonLatched button32 = { 32, {14, CHANNEL_1}, };
  49. CCButtonLatched button33 = { 33, {13, CHANNEL_1}, };
  50. CCButtonLatched button34 = { 34, {12, CHANNEL_1}, };
  51. CCButtonLatched button35 = { 35, {11, CHANNEL_1}, };
  52.  
  53.  
  54. 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)
  55.  
  56.   {bank, A0, 66},
  57.   {bank, A1, 67},
  58.   {bank, A2, 68},
  59.   {bank, A3, 69}
  60.   };
  61. //IncrementSelector<2> selector { bank, 2, };
  62.  
  63.  
  64.  
  65. Bankable::CCButtonLatched<6>  bankbuttons [] = {
  66.   { 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
  67.   { bank, 6, 91, },
  68.  
  69.  };
  70. Bankable::CCButtonLatched<6> button6 { bank, 6, 91, };
  71.  
  72.  
  73.  
  74.  
  75. IncrementDecrementSelectorLEDs<6> bankSelector = {
  76.   bank,
  77.   {7, 8},         // button pins
  78.   {46, 48, 49, 50, 51, 52}, // LED pins
  79. };  //establecemos los pines 7 y 8 como los pines para crecer o decrecer el banco configurado (cuatro ajustes distintos para ese banco configurado)
  80.  
  81. constexpr pin_t ledPin = 22;
  82. void setup() {
  83.   Control_Surface.begin();
  84.   pixels.begin();
  85.   pinMode(ledPin, OUTPUT);
  86.  
  87. }
  88.     /*mux.begin();
  89.   sreg.begin();
  90.   for (Button &button : buttons)
  91.     button.begin();*/
  92.  
  93. void loop() {
  94.   Control_Surface.loop();
  95.  
  96.    uint32_t rojo = pixels.Color(150,0,0);
  97.  
  98.  pixels.setPixelColor(1, rojo); // Brillo moderado en rojo (el led numero dos de la tira de leds se queda encendido con color rojo)
  99.  
  100.  pixels.show();   // Mostramos y actualizamos el color del pixel de nuestra cinta led RGB
  101. /*lo siguiente es para los leds de los bancos*/
  102.     // Function that checks if a given button is pressed
  103.   auto checkButtonPressed = [](const Bankable::CCButtonLatched<6> &button) {
  104.     return button.getButtonState() == Button::Pressed;
  105.   };
  106.   // If any of the push buttons is pressed
  107.   bool pressed = std::any_of(std::begin(bankbuttons), std::end(bankbuttons),
  108.                              checkButtonPressed);
  109.   // Turn on the LED
  110.   digitalWrite(ledPin, pressed);
  111. }  
  112.  
Advertisement
Add Comment
Please, Sign In to add comment