Ho collegato un display lcd insieme ad un sensore DHT11 ad un arduino UNO. Volevo sulla prima riga del display che si vedesse l'ora e nella seconda volelevo far vedere umidità e temperatura. Una volta compilato lo sketch ho notato compariva solo l'ora. Ho fatto delle prove per vedere se fosse un problema del sensore, ma escludendo il programma dell'orologio compariva correttamente la temp. e l'umid. e viceversa. Qualcuno sarebbe in grado di dirmi cosa ho sbagliato nel programma?
Grazie a tutti.
Il programma:
#include <LiquidCrystal.h>
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
int h=19; //cambiare per settare le ore.
int m=58; //cambiare per settare i min.
int s;
int flag;
int TIME;
const int hs=8;
const int ms=9;
void setup()
{
Serial.begin( 9600);
lcd.begin(16,2);
}
/*
* Poll for a measurement, keeping the state machine alive. Returns
* true if a measurement is available.
*/
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
void loop()
{
lcd.setCursor(0,0);
s=s+1;
lcd.print(h);
lcd.print(":");
lcd.print(m);
lcd.print(":");
lcd.print(s);
if(h<12)lcd.print("AM");
if(h==12)lcd.print("PM");
if(h>12)lcd.print("PM");
if(h==24)h=0;
delay(1000);
lcd.clear();
if(s==60){
s=0;
m=m+1;
}
if(m==60)
{
m=0;
h=h+1;
flag=flag+1;
}
if(h==13)
{
h=1;
}
//lcd.setCursor(0,1);
//temperatura e umidità//
float temperature;
float humidity;
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if( measure_environment( &temperature, &humidity ) == true )
{
lcd.setCursor(0,1);
lcd.print( "T=" );
lcd.print( temperature, 1 );
lcd.print( "C" );
lcd.print(" H=");
lcd.print( humidity, 1 );
lcd.print( "%" );
}
}