CigarroPuro

Untitled

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