Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. ** Estudiante: Edwin Lobo Hernandez
  3. ** Profesor: Diego Fernando Marin
  4. ** Descripción: Capturar el nivel de iluminación a través de una fotocelda
  5. ** Programación de Sistemas Embebidos
  6. ** Tutorial Ejemplo para realizar el Laboratorio
  7. ** https://www.arduino.cc/en/Tutorial/ShiftOut
  8. */
  9. /*********** Constantes ************/
  10.  
  11. #define PH_CELL A5
  12. #define TOTLED 16
  13.  
  14. /*********** Variables *************/
  15.  
  16. int dataPin  = 9;
  17. int latchPin = 10;
  18. int clockPin = 11;
  19.  
  20. int led [TOTLED] = {1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
  21.  
  22. /*********** Configuración ¨***********/
  23. void setup() {  
  24.   Serial.begin(9600);
  25.   // put your setup code here, to run once:
  26.   pinMode(PH_CELL, INPUT);
  27.   // Se configura el modo de salida para los pines
  28.   pinMode(latchPin, OUTPUT);
  29.   pinMode(clockPin, OUTPUT);
  30.   pinMode(dataPin, OUTPUT);
  31. }
  32.  
  33. /********* Ciclo **************/
  34.  
  35. void loop() {
  36.   // put your main code here, to run repeatedly:
  37.   int analogValue = analogRead(PH_CELL);
  38.   int pos = map(analogValue, 0, 450, 0, 15);
  39.  
  40.   Serial.print(pos);
  41.   Serial.print("  ");
  42.   Serial.println(analogValue);
  43.  
  44.   byte p1 = led[pos] & 0x00ff;
  45.   byte p2 = (led[pos] & 0xff00) >> 8;
  46.   digitalWrite(latchPin, LOW);
  47.   shiftOut(dataPin, clockPin, MSBFIRST, p2);
  48.   shiftOut(dataPin, clockPin, MSBFIRST, p1);
  49.   digitalWrite(latchPin, HIGH);
  50. }
  51.  
  52. /************Fin *******************/