// Termostat 5 temerature sensors DS18B20.
#include <EEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
OneWire oneWire(15); //
DallasTemperature ds(&oneWire);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const byte OUT[5] = {13, 12, 11, 3, 2};
byte pos;
byte tempOUTon[5];
float tempSensor[5];
byte qty;
//
DeviceAddress sensor1 = {0x28, 0xA8, 0x3E, 0xF9, 0x05, 0x0, 0x0, 0x12};
DeviceAddress sensor2 = {0x28, 0xE6, 0xBD, 0x3B, 0x05, 0x0, 0x0, 0xCF};
DeviceAddress sensor3 = {0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
DeviceAddress sensor4 = {0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
DeviceAddress sensor5 = {0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
byte gradus[8] = {
0b00110,
0b01001,
0b01001,
0b00110,
0b00000,
0b00000,
0b00000,
0b00000
};
byte on[8] = {
0b00110,
0b01111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11110,
0b01100
};
void readSet(){
for (byte i = 0; i < qty; i++) tempOUTon[i] = EEPROM.read(i);
}
void outOff(){
for (byte i = 0; i < qty; i++) digitalWrite(OUT[i], LOW);
}
void erorr(){
outOff();
lcd.clear();
lcd.print("sensor error");
while(1){
analogWrite(10, 100);
delay(500);
analogWrite(10, 255);
delay(500);
}
}
////
byte key(){
int val = analogRead(0);
if (val < 50) return 5;
else if (val < 150) return 3;
else if (val < 350) return 4;
else if (val < 500) return 2;
else if (val < 800) return 1;
else return 0;
}
////
void setMenu(byte pos){
outOff();
lcd.clear();
while(1){
byte KEY = key();
lcd.setCursor(2, 0);
lcd.print("Out:");
lcd.print(pos+1);
lcd.setCursor(9, 0);
lcd.print("Pin:");
lcd.print(OUT[pos]);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" PinON: ");
lcd.print(tempOUTon[pos]);
lcd.write(1);
lcd.print("C <>");
if (KEY == 2) {
tempOUTon[pos]--;
if (tempOUTon[pos] > 125) tempOUTon[pos] = 0;
EEPROM.write(pos, tempOUTon[pos]);
}
else if (KEY == 5){
tempOUTon[pos]++;
if (tempOUTon[pos] > 125) tempOUTon[pos] = 0;
EEPROM.write(pos, tempOUTon[pos]);
}
delay(200);
}/////
}//
void getTemp(){
ds.requestTemperatures();
tempSensor[0] = ds.getTempC(sensor1);
tempSensor[1] = ds.getTempC(sensor2);
tempSensor[2] = ds.getTempC(sensor3);
tempSensor[3] = ds.getTempC(sensor4);
tempSensor[4] = ds.getTempC(sensor5);
}
void sensorTest(){
ds.begin();
if(ds.getDeviceCount() != qty) erorr();
}
void setup() {
// Serial.begin(9600);
ds.begin();
qty = ds.getDeviceCount();
for (int i = 0; i < qty; i++) pinMode(OUT[i], OUTPUT);
for (int i = 0; i < qty; i++) digitalWrite(OUT[i], LOW);
lcd.createChar(1, gradus);
lcd.createChar(2, on);
lcd.begin(16, 2);
lcd.clear();
readSet();
}
void loop() {
if (key() == 1) setMenu(pos); // если нажата селект, уходим в настройки
else if (key() == 4 && pos < qty-1) pos++; // крутим позицию
else if (key() == 3 && pos != 0) pos--;
sensorTest();
getTemp();
for (int i = 0; i < qty; i++) {
if (tempSensor[i] < tempOUTon[i]) digitalWrite(OUT[i], HIGH);
else digitalWrite(OUT[i], LOW);
}
////
lcd.setCursor(0, 0);
lcd.print(pos+1);
lcd.print(". ");
lcd.print(tempSensor[pos], 1);
lcd.write(1);
lcd.print("C ");
lcd.setCursor(2, 1);
lcd.print(tempOUTon[pos]);
lcd.write(1);
lcd.print("C ");
lcd.setCursor(11, 0);
for (int i = 0; i < qty; i++){
if (digitalRead(OUT[i])) lcd.write(2);
else lcd.print(" ");
}
lcd.setCursor(11, 1);
for (int i = 0; i < qty; i++) lcd.print(i+1);
}
HI ALL!!!.. This code writes " Error Compiling " what a mistake here, you can tell me?- I can not fill in the Arduino!!!..