#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
OneWire oneWire( 2 );
DallasTemperature sensors( &oneWire );
LiquidCrystal_I2C lcd( 0x27, 16, 2 );
void setup()
{
Serial.begin( 115200 );
sensors.begin();
lcd.init();
lcd.backlight();
lcd.print( F( "Sd1 Sd3" ) );
lcd.setCursor( 0, 1 );
lcd.print( F( "Sd2 Sd4" ) );
afficherTemperatures();
}
void loop()
{
const uint32_t horodatage_actuel = millis();
static uint32_t horodatage_precedent = horodatage_actuel;
if ( horodatage_actuel - horodatage_precedent >= 3000 )
{
horodatage_precedent = horodatage_actuel;
afficherTemperatures();
}
}
void afficherTemperatures()
{
Serial.println();
sensors.requestTemperatures();
for ( uint8_t i = 0; i < 4; ++i )
{
const float temperature = sensors.getTempCByIndex( i );
char str[5];
snprintf_P( str, sizeof( str ), PSTR( "%4hd" ), (int16_t)round( temperature ) );
lcd.setCursor( i < 2 ? 3 : 12, i % 2 );
lcd.print( str );
Serial.print( F( "Sd" ) );
Serial.print( i + 1 );
Serial.print( F( " = " ) );
Serial.println( temperature );
}
}Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20