Digital termometer med Arduino (3 / 4 steg)
Steg 3: kod
Här är koden för att köra Arduino:
Kopiera/klistra in bör fungera.
Libraires
#include < LiquidCrystal.h >
#include < DallasTemperature.h >
#include < OneWire.h >
Pinut lcd (RS, E, D4, D5, D6, DlcdLight)
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
DS18B20 signal stift till Arduino stift 6
#define ONE_WIRE_BUS 6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensorer (& oneWire);
Tecknet för små "C", för Celcius, ta bort "/ *"'s och ta bort "F"
/ * byte customChar [8] = {
0b11100,
0b10000,
0b11100,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
*/
Karaktär för små "F"
byte customChar [8] = {
0b11100,
0b10000,
0b11000,
0b10000,
0b00000,
0b00000,
0b00000,
0b00000
};
CONST int lcdLight = 7.
void setup() {
pinMode(lcdLight,OUTPUT);
Init sensor och lcd
sensors.BEGIN();
lcd.createChar(1,customChar);
LCD.BEGIN (16, 2);
LCD.Print("temperature:");
lcd.setCursor(9,1);
LCD.Print("\337");
LCD.write(1);
}
void loop() {
digitalWrite(lcdLight,HIGH);
sensors.requestTemperatures();
lcd.setCursor(5,1);
Ändra "F" till ett "C" att byta till Celsius istället
LCD.Print(sensors.getTempFByIndex(0),1);
Delay(1000);
}