sábado, 17 de mayo de 2014

LABORATORIO 8

LABORATORIO 8

DESCRIPCIÓN DEL LABORATORIO :


Controlaré a través de Arduino un Display LED de 7-Segmentos puestos en una protoboard, por medio de un IC 74HC595, para mostrar un número de 0 a 9, dependiendo de la posición del Potenciómetro.

MATERIALES UTILIZADOS

(1) Protoboard


Cable utp


(1) Arduino uno


(2) Resistencias
     

(1) Display LED de 7-Segmentos 


(3) potenciometros

                                                        




DIAGRAMA DEL MONTAJE EN LA PROTOBOARD


DIAGRAMA DEL MONTAJE EN EL CIRCUITO


FOTOS DEL MONTAJE










CÓDIGO ARDUINO


  1. // Se definen la cantidad de pines que vamos a usar como PIN
  2. // y la entrada analoga A0 como la que se va a usar por el
  3. // potenciómetro
  4. #define PIN 3
  5. #define Pot A0
  6.  
  7. // Se le dan nombres a los pines (7-9) del arduino
  8. // que van a ser usados por el integrado respectivamente
  9. // además el pin SH_CP osea Clock debe ser PWM(~)
  10. const int Latch = 8;
  11. const int Clock = 9;
  12. const int Data = 7;
  13.  
  14. int led[PIN] = {
  15.   7,8,9};
  16.  
  17. // El valor de cada uno de los numeros que voy
  18. // a mostrar en mi Display
  19. int Numeros[10]={63,6,91,79,102,109,125,7,127,111};
  20.  
  21. // Ciclo para activar los ocho pines como salida
  22. // y el pin A0 como entrada
  23. void setup() {
  24.   for (int i=0; i<PIN; i++){
  25.     pinMode(led[i], OUTPUT);
  26.   }
  27.   pinMode(Pot, INPUT);
  28. }
  29.  
  30. // Recibe la info de la posición del potenciómetro
  31. void loop()
  32. {
  33.   int Pos = analogRead(Pot);
  34.   Pos = map(Pos, 010230,9);
  35.   Casos(Pos);
  36. }
  37.  
  38. // Según la posición del potenciómetro escoge un caso
  39. // osea un numero
  40. void Casos(int Valor)
  41. {
  42.   switch(Valor)
  43.   {
  44.   case 0:
  45.      On(Numeros[0]);
  46.     break;
  47.   case 1:
  48.      On(Numeros[1]);
  49.     break;
  50.   case 2:
  51.      On(Numeros[2]);
  52.     break;
  53.   case 3:
  54.      On(Numeros[3]);
  55.     break;
  56.   case 4:
  57.      On(Numeros[4]);
  58.     break;
  59.   case 5:
  60.      On(Numeros[5]);
  61.     break;
  62.   case 6:
  63.      On(Numeros[6]);
  64.     break;
  65.   case 7:
  66.      On(Numeros[7]);
  67.     break;
  68.   case 8:
  69.      On(Numeros[8]);
  70.     break;
  71.   case 9:
  72.      On(Numeros[9]);
  73.     break;
  74.   }        
  75. }
  76.  
  77. // Función para enviar los datos al Integrado IC 74HC595
  78. void On(int Valor)
  79. {
  80.   digitalWrite(Latch, LOW);
  81.   shiftOut(Data, Clock, MSBFIRST, Valor);
  82.   digitalWrite(Latch, HIGH);
  83.   delay(10);
VÍDEO DEL FUNCIONAMIENTO

LABORATORIO 7

LABORATORIO 7

DESCRIPCIÓN DEL LABORATORIO :


Controlaré a través de Arduino ocho (8) LEDs puestos en una protoboard, por medio de un IC 74HC595, controlando individualmente vía una interfaz gráfica en Processing/ControlP5 que LED está encendido o apagado.

MATERIALES UTILIZADOS

(1) Protoboard


(8) Led


Cable utp


(1) Arduino uno


(8) Resistencias
     

(1) Un IC 74HC595

                                                          


DIAGRAMA DEL MONTAJE EN LA PROTOBOARD




DIAGRAMA DEL MONTAJE EN EL CIRCUITO






FOTOS DEL MONTAJE














CÓDIGO ARDUINO


  1. // Se definen la cantidad de pines que vamos a usar como PIN
  2. // y la entrada analoga A0 como la que se va a usar por el
  3. // potenciómetro
  4. #define PIN 3
  5. #define Pot A0
  6.  
  7. // Se le dan nombres a los pines (7-9) del arduino
  8. // que van a ser usados por el integrado respectivamente
  9. // además el pin SH_CP osea Clock debe ser PWM(~)
  10. const int Latch = 8;
  11. const int Clock = 9;
  12. const int Data = 7;
  13.  
  14. int led[PIN] = {
  15.   7,8,9};
  16.  
  17. // Ocho secuencias
  18. int Serie1[7]={
  19.   129,66,36,24,24,36,66};
  20. int Serie2[9]={
  21.   0,128,192,224,240,248,252,254,255};
  22. int Serie3[12]={
  23.   255,126,60,24,16,8,16,8,24,60,126,255};
  24. int Serie4[2]={
  25.   240,15};
  26. int Serie5[14]={
  27.   129,0,131,133,137,145,161,0,193,161,145,137,133,131};
  28. int Serie6[2]={
  29.   195,60};
  30. int Serie7[11]={
  31.   1,0,1,0,15,0,15,0,255,255,0};
  32. int Serie8[50]={
  33.  1,2,4,8,16,32,64,128,64,32,16,8,4,2,1,2,4,8,16,32,64,128,192,160,144,136,132,130,129,131,133,137,145,161,193,225,209,201,197,195,199,203,211,227,243,235,231,239,255,0};
  34.  
  35. // Ciclo para activar los tres pines como salida
  36. // y el pin A0 como entrada
  37. void setup() {
  38.   for (int i=0; i<PIN; i++){
  39.     pinMode(led[i], OUTPUT);
  40.   }
  41.   pinMode(Pot, INPUT);
  42. }
  43.  
  44. // Recibe la info de la posición del potenciómetro
  45. void loop()
  46. {
  47.   int Pos = analogRead(Pot);
  48.   Pos = map(Pos, 010230,7);
  49.   Casos(Pos);
  50. }
  51.  
  52. // Según la posición del potenciómetro escoge un caso
  53. void Casos(int Valor)
  54. {
  55.   switch(Valor)
  56.   {
  57.   case 0:
  58.     for(int j=0;j<7;j++)
  59.     {
  60.       On(Serie1[j]);
  61.     }
  62.     break;
  63.   case 1:
  64.     for(int j=0;j<9;j++)
  65.     {
  66.       On(Serie2[j]);
  67.     }
  68.     break;
  69.   case 2:
  70.     for(int j=0;j<12;j++)
  71.     {
  72.       On(Serie3[j]);
  73.     }
  74.     break;
  75.   case 3:
  76.     for(int j=0;j<2;j++)
  77.     {
  78.       On(Serie4[j]);
  79.     }
  80.     break;
  81.   case 4:
  82.     for(int j=0;j<14;j++)
  83.     {
  84.       On(Serie5[j]);
  85.     }
  86.     break;
  87.   case 5:
  88.     for(int j=0;j<2;j++)
  89.     {
  90.       On(Serie6[j]);
  91.     }
  92.     break;
  93.   case 6:
  94.     for(int j=0;j<11;j++)
  95.     {
  96.       On(Serie7[j]);
  97.     }
  98.     break;
  99.   case 7:
  100.     for(int j=0;j<50;j++)
  101.     {
  102.       On(Serie8[j]);
  103.     }
  104.     break;
  105.   }        
  106. }
  107.  
  108. // Función para enviar los datos al Integrado IC 74HC595
  109. void On(int Valor)
  110. {
  111.   digitalWrite(Latch, LOW);
  112.   shiftOut(Data, Clock, MSBFIRST, Valor);
  113.   digitalWrite(Latch, HIGH);
  114.   delay(100);
  115. }



    CODIGO PROCESSING

    / Se utiliza las librerias ControlP5 y Serial del Processing
    import controlP5.*;
    import processing.serial.*;
     
    // Se define la variable cP5 del tipo ControlP5
    ControlP5 cP5;
     
    // Se le da nombres al Serial
    Serial serial;
     
    int[] led = new int[] {
      0, 0, 0, 0, 0, 0, 0, 0
    };
     
    // Configuración inicial
    void setup() {
      size(590, 250);  //Tamaño de la ventana
      noStroke();
     
      cP5 = new ControlP5(this);  //Crea el objeto ControlP5
     
      // Crea el Knob del color Rojo
      for (int i=0; i<led.length; i++)
      {
        cP5.addToggle("led"+i, 35+i*70, 140, 30, 30)
          .setMode(ControlP5.SWITCH);
      }
     
      String puerto = Serial.list()[0];
      //Comunicación serial a 9600bps
      serial = new Serial(this, puerto, 9600);
    }
     
    // Cada uno de los circuilos hecho toma el color determinado
    // del Led que se tiene en la protoboard
    void draw() {
      background(0xFF444444);
      fill(led[0] == 0 ? 0xFF222222 : color(255, 255, 0));
      ellipse(50, 100, 50, 50);
      for (int i=1; i<4; i++) {
        fill(led[i] == 0 ? 0xFF222222 : color(255, 0, 0));
        ellipse(50+i*70, 100, 50, 50);
      }
      for (int i=4; i<led.length; i++) {
        fill(led[i] == 0 ? 0xFF222222 : color(0, 255, 0));
        ellipse(50+i*70, 100, 50, 50);
      }
       fill(255);
       textFont(createFont("Gill Sans Ultra Bold", 50));
       text("Enciende un LED", 40, 50);
       fill(255);
       textSize(25);
       text("Juan Camilo Fernández López", 120, 230);
    }
     
    // Como se va a actuar cuando ocurra un evento con los botones
    void controlEvent(ControlEvent evento) {
      String nombre = evento.getController().getName();
      int valor = int(evento.getController().getValue());
     
      // Guarda el valor de cada boton
      for (int i=0; i<led.length; i++) {
        if (nombre.equals("led"+i)) {
          led[i] = valor;
          serial.write(i);
          serial.write(valor);
          println("evento: " + i + " / valor: "+valor);
        }
      }
    }

    VÍDEO DEL FUNCIONAMIENTO