This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
// Debemos leer cada 2 segundos | |
if(ultimaVezLeido > milisegundosDeEsperaParaLeer) { | |
humedad = sensor.readHumidity(); | |
temperaturaEnGradosCelsius = sensor.readTemperature(); | |
// En ocasiones puede devolver datos erróneos; por eso lo comprobamos | |
if (isnan(temperaturaEnGradosCelsius) || isnan(humedad)) { | |
Serial.println("Error leyendo valores"); | |
ultimaVezLeido = 0; | |
return; | |
} | |
// En caso de que todo esté correcto, imprimimos los valores | |
Serial.print("Humedad: "); | |
Serial.print(humedad); | |
Serial.print(" %\t"); | |
Serial.print("Temperatura: "); | |
Serial.print(temperaturaEnGradosCelsius); | |
Serial.println(" *C"); | |
ultimaVezLeido = 0; | |
} | |
// Aquí podemos hacer otras cosas... | |
// Esperamos 100 milisegundos y también los aumentamos al contador, de este | |
// modo evitamos un delay de 2000 milisegundos y podemos hacer otras cosas | |
// por aquí | |
delay(100); | |
ultimaVezLeido += 100; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment