/*
Proyecto 7b
Enciende un LED cuando oscurece y lo apaga si hay luz
*/
// Usamos el pin analógico A0 para leer el voltaje
const int PinVoltaje = A1;
const int PinLed = 13;
const float VoltajeOscuro = 4.5;
void setup()
{
pinMode(PinLed, OUTPUT);
}
void loop()
{
float Voltaje;
Voltaje = LeerVoltaje(PinVoltaje);
if (Voltaje >= VoltajeOscuro)
// En caso que el voltaje supere el umbral enciende el LED
{
digitalWrite(PinLed, HIGH);
}
else
// Si el voltaje no supera el umbral apaga el LED
{
digitalWrite(PinLed, LOW);
}
}
float LeerVoltaje(int Pin)
{
// Definimos la función LeerVoltaje()
return (analogRead(Pin) * 5.0 / 1024.0);
}