Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS 5
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- DeviceAddress thermometer = {
- // 0x28, 0xFF, 0x26, 0xA7, 0x35, 0x16, 0x4, 0xCF };
- 0x28, 0xFF, 0xCA, 0xE2, 0x35, 0x16, 0x3, 0xD6};
- unsigned long interval1 = 2000;
- unsigned long interval2 = 6000; // tesversioon
- //unsigned long interval2 = 600000; // tuleb arvestada, et interval2 tegelikuks
- unsigned long prevTime = 0; //pikkuseks jaab interval2 - interval1
- unsigned long curTime;
- const int kollaPin = 4;
- const int siniPin = 3;
- int kollaState = LOW;
- int siniState = LOW;
- int val = 0;
- int INtempPin = A0;
- float tempC;
- float SET = 25.0;
- float setk = 0.0;
- const int buttonPin = 2;
- const int button2Pin = 6;
- int buttonPushCounter =0;
- int button2PushCounter =0;
- int buttonState =0;
- int button2State =0;
- int lastButtonState =0;
- int lastButton2State =0;
- // BS E D4 D5 D6 D7
- LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
- void setup()
- {
- lcd.begin(16, 2);
- pinMode(kollaPin, OUTPUT);
- pinMode(siniPin, OUTPUT);
- pinMode(buttonPin, INPUT);
- pinMode(button2Pin,INPUT);
- Serial.begin(9600);
- sensors.begin();
- sensors.setResolution(thermometer, 12);
- }
- void printlnTemperature(DeviceAddress deviceAddress) {
- tempC = sensors.getTempC(deviceAddress);
- Serial.println(tempC);
- val = analogRead(INtempPin);
- Serial.print("setTemp: ");
- Serial.println(val * 0.45);
- }
- void loop() {
- unsigned long curTime = millis();
- sensors.requestTemperatures();
- Serial.print("Temperature is: ");
- printlnTemperature(thermometer);
- Serial.print("\n\r");
- Serial.println(tempC);
- delay(1);
- //int INtempReading = analogRead(INtempPin);
- //delay(5);
- //float INtempVolts = INtempReading * 5.0 / 1024.0;
- //float INtempC = (INtempVolts - 0.5) * 100.0 + 50;
- lcd.print("I");
- lcd.setCursor(1, 0);
- lcd.print(val * 0.45);
- //int BACKtempReading = analogRead(BACKtempPin);
- //delay(1);
- //float BACKtempVolts = BACKtempReading * 5.0 / 1024.0;
- //float BACKtempC = (BACKtempVolts - 0.5) * 100.0 + 50;
- lcd.setCursor(5, 0);
- lcd.print("B");
- lcd.setCursor(6, 0);
- lcd.print(tempC);
- lcd.setCursor(10, 0);
- lcd.print((char)223);
- buttonState = digitalRead(buttonPin);
- if (buttonState != lastButtonState){
- if (buttonState ==HIGH) {
- setk++;
- }
- }
- button2State = digitalRead(button2Pin);
- if (button2State != lastButton2State){
- if (button2State == HIGH) {
- setk--;
- // Serial.println(setk/10 + SET);
- }
- }
- lastButtonState = buttonState;
- lastButton2State = button2State;
- lcd.setCursor(11, 0);
- lcd.print("S");
- lcd.setCursor(12, 0);
- lcd.print(setk/10 + SET);
- lcd.setCursor(14, 1);
- if (setk/10 + SET +1 < tempC) {
- lcd.print("CO");
- }
- else if (setk/10 + SET > 1+ tempC){
- lcd.print("WO");
- }
- else if ((setk/10 + SET - tempC) <1 > -1){
- lcd.print("OK");
- }
- lcd.setCursor(0, 1);
- lcd.print("ERTEC");
- lcd.setCursor(6, 1);
- lcd.print(700*4.19*(val * 0.45-tempC)/3600);
- lcd.setCursor(10, 1);
- lcd.print(" KW ");
- //could down
- if (val * 0.45 + 1 < tempC) {
- if (curTime - prevTime < interval1) {
- digitalWrite(4, LOW);
- digitalWrite(3, HIGH);
- }
- if (curTime - prevTime >= interval1) {
- digitalWrite(3, LOW);
- }
- if (curTime - prevTime > interval2) { //peale teist intervali voib ka led
- // digitalWrite(4, HIGH); // korgeks panna, kui progega edasi minna
- prevTime = curTime;
- }
- }
- //warm up
- if (val * 0.45 - 1 > tempC) {
- //if (val*0.065+5 - tempC <= 1 && val*0.065+5 - tempC > 0){
- if (curTime - prevTime < interval1) {
- digitalWrite(3, LOW);
- digitalWrite(4, HIGH);
- delay(10);
- }
- if (curTime - prevTime >= interval1) {
- digitalWrite(4, LOW);
- }
- if (curTime - prevTime > interval2) { //peale teist intervali voib ka led
- //digitalWrite(6, HIGH); // korgeks panna, kui progega edasi minna
- prevTime = curTime;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement