CigarroPuro

Untitled

Mar 19th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 10.17 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LcdBarGraphX.h>
  3. #include <LiquidCrystal.h>
  4. #include <LiquidCrystal_I2C.h>
  5. #include <Encoder.h>
  6. #include <Control_Surface.h>  /*Program--include library-- then select "control surface" library..Vamos a programar el codigo con la librería Control Surface*/
  7. USBMIDI_Interface usbmidi;    /*initializes device as usb_midi interface...see other examples like hardwareserial,hairles etc*/
  8. #include <Arduino_Helpers.h> // Include the Arduino Helpers library.
  9. #include <AH/Containers/ArrayHelpers.hpp>
  10. #include <AH/Hardware/Button.hpp>
  11. #include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp>
  12. //#include <AH/Hardware/ExtendedInputOutput/SPIShiftRegisterOut.hpp>
  13.  
  14.  
  15. const int speedMultiplier = 1;
  16.  
  17. byte lcdNumCols = 20; // -- number of columns in the LCD
  18.  
  19.  
  20.  
  21.  /* Caracteres personalizados */
  22. /*byte DIV_0_OF_5 [ 8 ] = {
  23.   B00000,
  24.   B00000,
  25.   B00000,
  26.   B00000,
  27.   B00000,
  28.   B00000,
  29.   B00000,
  30.   B00000
  31. }; // 0/5
  32.  
  33. byte DIV_1_OF_5 [ 8 ] = {
  34.   B10000,
  35.   B10000,
  36.   B10000,
  37.   B10000,
  38.   B10000,
  39.   B10000,
  40.   B10000,
  41.   B10000
  42. }; // 1/5
  43.  
  44. byte DIV_2_OF_5 [ 8 ] = {
  45.   B11000,
  46.   B11000,
  47.   B11000,
  48.   B11000,
  49.   B11000,
  50.   B11000,
  51.   B11000,
  52.   B11000
  53. }; // 2/5
  54.  
  55. byte DIV_3_OF_5 [ 8 ] = {
  56.   B11100,
  57.   B11100,
  58.   B11100,
  59.   B11100,
  60.   B11100,
  61.   B11100,
  62.   B11100,
  63.   B11100
  64. }; // 3/5
  65.  
  66. byte DIV_4_OF_5 [ 8 ] = {
  67.   B11110,
  68.   B11110,
  69.   B11110,
  70.   B11110,
  71.   B11110,
  72.   B11110,
  73.   B11110,
  74.   B11110
  75. }; // 4/5
  76.  
  77. byte DIV_5_OF_5 [ 8 ] = {
  78.   B11111,
  79.   B11111,
  80.   B11111,
  81.   B11111,
  82.   B11111,
  83.   B11111,
  84.   B11111,
  85.   B11111
  86. }; // 5/5*/
  87. /*
  88. * Función de configuración de la pantalla LCD para la barra de progreso.
  89. * Utilice caracteres personalizados de 0 a 5 (6 y 7 permanecen disponibles).
  90. */
  91.  
  92. /*void  setup_progressbar () {
  93.  
  94.    Guardar caracteres personalizados en la memoria de la pantalla LCD */
  95.  /* lcd.createChar ( 0 , DIV_0_OF_5);
  96.   lcd.createChar ( 1 , DIV_1_OF_5);
  97.   lcd.createChar ( 2 , DIV_2_OF_5);
  98.   lcd.createChar ( 3 , DIV_3_OF_5);
  99.   lcd.createChar ( 4 , DIV_4_OF_5);
  100.   lcd.createChar ( 5 , DIV_5_OF_5);
  101. }
  102. */
  103. /**
  104. * Función dibujando la barra de progreso.
  105. *
  106. * @param percent El porcentaje que se mostrará.
  107. */
  108.  
  109.  
  110.  
  111.  
  112.  
  113. Bank<8> bankpedal(4);  /*El bank tiene 8posiciones o 4 ajustes de banco posibles <4> y se llama bank y tiene un rango de cuatro (4) por lo
  114.                      tanto crecerá o decrecerá cuatro valores*/
  115. Bank<8> bankamp(4);  /*El bank tiene 8posiciones o 4 ajustes de banco posibles <4> y se llama bank2 y tiene un rango de cuatro (4) por lo
  116.                      tanto crecerá o decrecerá (4) valores*/
  117. /* Instantiate a multiplexer
  118. CD74HC4067 mux = {
  119.   15,            // input pin
  120.   {2, 3, 4, 14}, // Address pins S0, S1, S2, S3
  121.   // 7, // Optionally, specify the enable pin
  122. };
  123. // Instantiate a shift register with the SPI slave select pin as latch pin, most
  124. // significant bit first, and a total of 16 outputs.
  125. SPIShiftRegisterOut<mux.length()> sreg = {SS, MSBFIRST};
  126.  
  127. auto buttons = generateIncrementalArray<Button, mux.length()>(mux.pin(0));*/
  128.  
  129. // Instantiate a multiplexer
  130. CD74HC4067 mux2 = {
  131.   8,            // input pin
  132.   {9, 10, 11, 12}, // Address pins S0, S1, S2, S3
  133.   // 7, // Optionally, specify the enable pin
  134. };
  135.  
  136. CCButtonLatched futton [] = {          /*declarar los pines del multiplexer CD74HC4067 del tipo CCbuttonlatched y con nombre futton*/
  137.   { mux2.pin(0), { 77, CHANNEL_1 } },    /* pin C0 del multiplexer en canal uno y con CC77
  138.   { mux2.pin(1), { 81, CHANNEL_2 } },
  139.   { mux2.pin(2), { 85, CHANNEL_3 } },     /*todosESTOS BOTOones del multiplexer encienden o apagan cada uno de los 8 pedales que configuremos en nuestro DAW (cubase,amplitube,etc)*/                                              
  140.   { mux2.pin(3), { 89, CHANNEL_4 } },
  141.   { mux2.pin(4), { 93, CHANNEL_5 } },
  142.   { mux2.pin(5), { 97, CHANNEL_6 } },
  143.   { mux2.pin(6), { 101, CHANNEL_7 } },
  144.   { mux2.pin(7), { 105, CHANNEL_8 } },
  145.  };
  146.  
  147.  
  148. CCButtonLatched futton2 [] = {  
  149.   { mux2.pin(8), { 84, CHANNEL_1 } },    
  150.   { mux2.pin(9), { 86, CHANNEL_2 } },
  151.   { mux2.pin(10), { 87, CHANNEL_3 } },                                                  
  152.   { mux2.pin(11), { 88, CHANNEL_4 } },
  153.   { mux2.pin(12), { 90, CHANNEL_5 } },
  154.   { mux2.pin(13), { 91, CHANNEL_6 } },
  155.   { mux2.pin(14), { 92, CHANNEL_7 } },
  156.   { mux2.pin(15), { 94, CHANNEL_8 } },
  157.  
  158. };
  159.  
  160. // Instantiate a multiplexer
  161. CD74HC4067 mux3 = {
  162.   A15,            // input pin
  163.   {A14, A13, A12, A11}, // Address pins S0, S1, S2, S3
  164.   // 7, // Optionally, specify the enable pin
  165. };
  166.  
  167.  
  168.  
  169.  
  170. /*const int pinR4 = mux3.pin(8);
  171. const int pinR5 = mux3.pin(9);
  172. const int pinR6 = mux3.pin(10);
  173. const int pinR7 = mux3.pin(11);*/
  174.  
  175.  
  176. CCPotentiometer pots3 [] = {
  177.  
  178.   {mux3.pin(4), 74},
  179.   {mux3.pin(5), 75},
  180.   {mux3.pin(6), 76},
  181.   {mux3.pin(7), 78},
  182.   {mux3.pin(12), 79},
  183.   {mux3.pin(13), 80},
  184.   {mux3.pin(14), 82},
  185.   {mux3.pin(15), 83},
  186.  
  187.  
  188. };
  189.  
  190. Bankable::CCButtonLatched<8>  bankbuttons [] = {  /*declarar los botones que creceran o decreceran (4) valores dentro de cada cambio de banco.Serán del tipo ccbuttonlatched,se llamarán bankbuttons y los declaramos como bankables en los pines de salida 5 y 6 de arduino con los CC90 Y CC91 */
  191.   { bankpedal, 7, 77, },  
  192.   //{ bankpedal, 6, 91, },
  193.   };
  194.  
  195. Bankable::CCPotentiometer pots[] = {    /*declarar los potenciometros que creceran o decreceran (4) valores dentro de cada cambio de banco.Serán del tipo ccpotentiometer,se llamarán pots y los declaramos como bankables en los pines analogicos de salida A0,A1..ETC..de arduino con los CC66,CC67..ETC*/
  196.  
  197.   {bankamp, mux3.pin(8), 1},
  198.   {bankamp, mux3.pin(9), 3},
  199.   {bankamp, mux3.pin(10), 4},
  200.   {bankamp, mux3.pin(11), 6},
  201.  
  202.   };
  203.  
  204. Bankable::CCPotentiometer pots2[] = {    /*declarar los potenciometros que creceran o decreceran (4) valores dentro de cada cambio de banco.Serán del tipo ccpotentiometer,se llamarán pots y los declaramos como bankables en los pines analogicos de salida A0,A1..ETC..de arduino con los CC66,CC67..ETC*/
  205.  
  206.   {bankpedal, mux3.pin(0), 37},
  207.   {bankpedal, mux3.pin(1), 38},
  208.   {bankpedal, mux3.pin(2), 39},
  209.   {bankpedal, mux3.pin(3), 40},
  210.  
  211.   };
  212. IncrementDecrementSelectorLEDs<8> bankSelector = {   /*declarar lo botones que van a incrementar o decrecer la posicion del cambio de banco dentro del banco llamado bank..como tiene cuatro bancos posibles..declaramos cuatro led pins para saber la posición del banco en el que estamos. Los botones  que nos permitiran cambiar el banco serán los pines 2 y 3 en arduino*/
  213.   bankpedal,
  214.   {5, 6},         // button pins
  215.   {30, 31, 32, 33, 34, 35, 36, 37}, // LED pins
  216.   };
  217.  
  218. IncrementDecrementSelectorLEDs<8> bankSelector2 = {   /*declarar lo botones que van a incrementar o decrecer la posicion del cambio de banco dentro del banco llamado bank2..como tiene cuatro bancos  posibles..declaramos cuatro led pins para saber la posición del banco en el que  estamos. Los botones que nos permitiran cambiar el banco serán los pines 2 y 3 en  arduino*/
  219.   bankamp,
  220.   {14, 15},         // button pins
  221.   {38, 43, 44, 41, 42, 39, 40, 45}, // LED pins
  222.   };
  223.  
  224. CCRotaryEncoder enc = {
  225.  
  226.   {18, 19},                                // pins
  227.   77, // address
  228.   speedMultiplier,                       // multiplier
  229.   4,                                     // pulses per click
  230. };
  231.  
  232.  
  233.  
  234. /* Instantiate a CCAbsoluteEncoder object
  235. EncoderSelector<8> encoder = {
  236.   bankamp,
  237.   {18, 19},       // pins
  238.   1,
  239.   Wrap::Clamp,// optional multiplier if the control isn't fast enough
  240. };*/
  241.  
  242. const pin_t ledPins[] = { 22, 23, 24, 25, 26, 27, 28, 29 };
  243.  
  244. template <class T, size_t N> constexpr size_t length(T (&)[N]) { return N; }
  245.  
  246. static_assert(length(futton) == length(ledPins),
  247.               "Error: requires same number of buttons as LEDs");
  248.  
  249.  
  250.  
  251.  
  252.  
  253. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  254. LcdBarGraphX lbg(&lcd, lcdNumCols);  // -- creating
  255.  
  256.  
  257. void setup() {
  258.  
  259.     Control_Surface.begin();
  260.  for (auto pin : ledPins)  // Set the pinMode to output for all LEDs
  261.       pinMode(pin, OUTPUT);
  262. int status;
  263.  
  264.  lcd.begin(20, lcdNumCols);
  265.  
  266.   lcd.clear();
  267.   lcd.setCursor(0,1);
  268.   lcd.print ("Al loro.......");
  269.   delay(1000);
  270.   lcd.setCursor (5,3);
  271.   lcd.print ("NENES...NENAS..");
  272.   delay(800);
  273.   lcd.clear();
  274.   lcd.setCursor(1,2);
  275.   lcd.print ("ELSEREBRODELABESTIA");
  276.   delay(800);
  277.   lcd.clear();
  278.   lcd.setCursor(0,0);
  279.   lcd.print ("LA PEDALERA MIDI");
  280.   delay(500);
  281.   lcd.setCursor(1,3);
  282.   lcd.print ("Del Tio Elias");
  283.   delay(1000);
  284.   lcd.clear();
  285.   lcd.setCursor(2,0);
  286.   lcd.print ("YA ESTA AQUI!");
  287.   delay(800);
  288.   lcd.clear();
  289.    lcd.setCursor(12,0);
  290.   lcd.print ("jar");
  291.   delay(500);
  292.   lcd.clear();
  293.   // -- do some delay: some time I've got broken visualization
  294.   delay(100);
  295.  
  296.  
  297.   /*-- initializing the LCD
  298.   lcd.begin(4, lcdNumCols);
  299.   lcd.clear();
  300.  
  301.   lcd.setCursor(0, 0);
  302.   lcd.print("LcdProgressBar*2");
  303.  
  304.   //-- Set min and max values
  305.   //*** (0 is default minimum value)
  306.   //*** (1023 is maximum value for both bars)
  307.   lpg.setMaxValues(1023);
  308.      
  309.   delay(50);*/
  310. }
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.   /* Petit temps d'attente */
  318.  
  319.  
  320.  /* mux.begin();
  321.   sreg.begin();
  322.   for (Button &button : buttons)
  323.     button.begin();*
  324.  }*/
  325.  
  326.  
  327.  
  328. void loop() {
  329.  
  330.   /*int r4 = analogRead(pinR4);
  331.   int r5 = analogRead(pinR5);
  332.   int r6 = analogRead(pinR6);
  333.   int r7 = analogRead(pinR7);
  334.   //-- draw progress bars
  335.   lpg.draw(r4, r5, r6, r7);*/
  336.  
  337.   // -- do some delay: frequent draw may cause broken visualization
  338.  
  339.   // put your main code here, to run repeatedly:
  340.   Control_Surface.loop();
  341.  for (size_t i = 0; i < length(futton); ++i)
  342.       // Update the LED states to reflect the toggled switch states
  343.       digitalWrite(ledPins[i], futton[i].getState() ? LOW : HIGH);
  344.  
  345.   lbg.drawValue( analogRead(mux3.pin(9)), 1023);
  346.   // -- do some delay: frequent draw may cause broken visualization
  347.   delay(100);
  348.  
  349.  
  350.  
  351.  
  352. }
  353.  
  354.  
  355. /*lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
  356. lcd.print("SensorVal1: "); // Prints Sensor Val: to LCD
  357. lcd.print(analogRead(potPin1)); // Prints value on Potpin1 to LCD*/
  358.  
  359.  
  360.   /* Check if a button is pressed, if so toggle the LED
  361.   for (uint8_t i = 0; i < mux.length(); ++i)
  362.     if (buttons[i].update() == Button::Falling)
  363.       sreg.digitalWrite(i, sreg.digitalRead(i) ? LOW : HIGH);*/
Advertisement
Add Comment
Please, Sign In to add comment