/*
** Estudiante: Edwin Lobo Hernandez
** Profesor: Diego Fernando Marin
** Descripción: Capturar el nivel de iluminación a través de una fotocelda
** Programación de Sistemas Embebidos
** Tutorial Ejemplo para realizar el Laboratorio
** https://www.arduino.cc/en/Tutorial/ShiftOut
*/
/*********** Constantes ************/
#define PH_CELL A5
#define TOTLED 16
/*********** Variables *************/
int dataPin = 9;
int latchPin = 10;
int clockPin = 11;
int led [TOTLED] = {1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
/*********** Configuración ¨***********/
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(PH_CELL, INPUT);
// Se configura el modo de salida para los pines
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
/********* Ciclo **************/
void loop() {
// put your main code here, to run repeatedly:
int analogValue = analogRead(PH_CELL);
int pos = map(analogValue, 0, 450, 0, 15);
Serial.print(pos);
Serial.print(" ");
Serial.println(analogValue);
byte p1 = led[pos] & 0x00ff;
byte p2 = (led[pos] & 0xff00) >> 8;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, p2);
shiftOut(dataPin, clockPin, MSBFIRST, p1);
digitalWrite(latchPin, HIGH);
}
/************Fin *******************/