Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //laboratorio 7
  2. //DIEGO LANDAZURY DIAZ
  3. //universidad santiago de cali
  4. // version:1.0
  5.  
  6. #define PIN 3
  7. #define Pot A0// variables a utilizar
  8.  
  9. const int Latch = 2;
  10. const int Clock = 3;
  11. const int Data = 4;
  12.  
  13. int led[PIN] = {2,3,4}; // pines utilizados
  14.  
  15. // valor de numeros a mostrar en el display
  16. int Numeros[10]={63,6,91,79,102,109,125,7,127,111};
  17.  
  18. // Ciclo para activar los ocho pines como salida
  19. // y el pin A0 como entrada
  20. void setup() {
  21.  for (int i=0; i<PIN; i++){
  22.  pinMode(led[i], OUTPUT);
  23.  }
  24.  pinMode(Pot, INPUT);
  25. }
  26. void loop()
  27. {
  28.  int Pos = analogRead(Pot); // lee la posicion del potenciometro
  29.  int Mos = map(Pos, 0, 1023, 0,10); // realiza el mapeo
  30.  Casos(Mos);
  31. }
  32.  
  33. void Casos(int Valor)// elige un valor de acuerdo con la posicion del
  34. {                    // potenciometro
  35.  switch(Valor)
  36.  {
  37.  case 0:
  38.  On(Numeros[0]);
  39.  break;
  40.  case 1:
  41.  On(Numeros[1]);
  42.  break;
  43.  case 2:
  44.  On(Numeros[2]);
  45.  break;
  46.  case 3:
  47.  On(Numeros[3]);
  48.  break;
  49.  case 4:
  50.  On(Numeros[4]);
  51.  break;
  52.  case 5:
  53.  On(Numeros[5]);
  54.  break;
  55.  case 6:
  56.  On(Numeros[6]);
  57.  break;
  58.  case 7:
  59.  On(Numeros[7]);
  60.  break;
  61.  case 8:
  62.  On(Numeros[8]);
  63.  break;
  64.  case 9:
  65.  On(Numeros[9]);
  66.  break;
  67.  }
  68. }
  69.  
  70. void On(int Valor)// envia los datos alIntegrado
  71. {
  72.  digitalWrite(Latch, LOW);
  73.  shiftOut(Data, Clock, MSBFIRST, Valor);
  74.  digitalWrite(Latch, HIGH);
  75.  delay(8);
  76. }