CigarroPuro

Untitled

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