Hardware
Sorfware
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD to address 0x27, 16 chars, and 2 lines.
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
lcd.init();
lcd.backlight();
}
void loop()
{
char str[16];
double degC, degF;
// Read the LM35 sensor on A3.
int adu = analogRead(A3);
// Calculate the temperature.
degC = adu * 0.488;
degF = (adu * 0.8784) + 32;
// Turn it into a string.
memset(str, 0, sizeof(str));
dtostrf(degC,1,2,str);
strcat(str, " C ");
dtostrf(degF,1,2,str+(strlen(str)));
strcat(str, " F");
// Display the header and the string.
lcd.setCursor(0,0);
lcd.print("Temperature");
lcd.setCursor(0,1);
lcd.print(str);
delay(1000);
}
ความคิดเห็น
แสดงความคิดเห็น