// Program odczytuje temperaturę z czujnika #include #include #include // dolaczenie pobranej biblioteki I2C dla LCD LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Ustawienie adresu ukladu na 0x27 //////////////////////wyjścia i wejścia///////////////////////// // Numer pinu do którego podłaczasz czujnik #define ONEWIRE_PIN 7 int DATA = 8; int CLK = 9; int latch = 13; int D[] = {1, 4, 5, 6, 3}; int DP = 2; int zielona = 11; int czerwona = 12; int wentylator = 10; int SW1 = A3; int SW2 = A2; int SW3 = A1; int POT = A0; int CYFRA[] = {1, 159, 34, 6, 140, 84, 64, 15, 16, 4}; /////////////////////////////////////////////////////////////////// ////////////zmienne////////////// float temperature = 0; int Rtemp = 0; int tempzadana = 0; int warhisterezy = 40; int cyfra0 = 0; int tempRZ[] = {0, 0, 0}; int tempZA[] = {0, 0, 0}; int i = 0; int drganiestykow = 150; int tempzadanaLCD = 0; int coilepomiar = 20; int pomiarbyl = coilepomiar + 1; int nowa = 11; // Adres czujnika byte address[8] = {0x28, 0xFF, 0x82, 0xCF, 0x64, 0x15, 0x1, 0xD5}; OneWire onewire(ONEWIRE_PIN); DS18B20 sensors(&onewire); void setup() { while (!Serial); Serial.begin(9600); lcd.begin(16, 2); // Inicjalizacja LCD 2x16 lcd.backlight(); // zalaczenie podwietlenia sensors.begin(9); sensors.request(address); pinMode(wentylator, OUTPUT); pinMode(DATA, OUTPUT); pinMode(CLK, OUTPUT); pinMode(latch, OUTPUT); pinMode(D[1], OUTPUT); pinMode(D[2], OUTPUT); pinMode(D[3], OUTPUT); pinMode(D[4], OUTPUT); pinMode(DP, OUTPUT); pinMode(zielona, OUTPUT); pinMode(czerwona, OUTPUT); pinMode(SW1, INPUT); pinMode(SW2, INPUT); pinMode(SW3, INPUT); pinMode(POT, INPUT); } //////////////ODCZYT TEMPERATURY ////////////// void odczyttemp() { if (sensors.available()) { if (pomiarbyl > coilepomiar) { temperature = (sensors.readTemperature(address)) * 10; //Rtemp = temperature; Rtemp = 123; sensors.request(address); pomiarbyl = 0; } } pomiarbyl++; //Serial.println(pomiarbyl); } ////////////// USTAWIENIE TEMPERATURY ////////////// void ustawienietemp() { int odczytSW1 = analogRead(SW1); int odczytSW2 = analogRead(SW2); if (odczytSW1 > 800) { delay(drganiestykow); tempzadana = tempzadana + 5; } if (odczytSW2 > 800) { delay(drganiestykow); tempzadana = tempzadana - 5; } tempzadanaLCD = tempzadana; //if(tempzadana%10<5) //tempzadanaLCD = tempzadana - tempzadana%10; //else //tempzadanaLCD = tempzadana +(10-tempzadana%10); } ////////////// URUCHOMIENIE WENTYLATORA ////////////// void uruchomieniewent() { if (tempzadana > Rtemp) { digitalWrite(wentylator, HIGH); } if (tempzadana < Rtemp - warhisterezy) { digitalWrite(wentylator, LOW); } } ////////////// WYŚWIETLENIE TEMPERATURY ////////////// void wyswietlanietemp() { ///////////////wyodrębnienie cyf//////////////// tempZA[0] = Rtemp % 100; tempZA[0] = (Rtemp - tempZA[0]) / 100; tempZA[1] = Rtemp % 10; tempZA[1] = (Rtemp - (tempZA[0] * 100) - tempZA[1]) / 10; tempZA[2] = Rtemp - (tempZA[0] * 100) - (tempZA[1] * 10); tempRZ[0] = tempzadanaLCD % 100; tempRZ[0] = (tempzadanaLCD - tempRZ[0]) / 100; tempRZ[1] = tempzadanaLCD % 10; tempRZ[1] = (tempzadanaLCD - (tempRZ[0] * 100) - tempRZ[1]) / 10; tempRZ[2] = tempzadanaLCD - (tempRZ[0] * 100) - (tempRZ[1] * 10); //////////////////wyswietlenie na 7 seg///////////// int czas = 5; digitalWrite(D[1], LOW); digitalWrite(D[2], LOW); digitalWrite(D[3], LOW); digitalWrite(D[4], LOW); digitalWrite(latch, LOW); shiftOut(DATA, CLK, LSBFIRST, CYFRA[tempRZ[0]]); digitalWrite(latch, HIGH); digitalWrite(D[1], LOW); digitalWrite(D[2], HIGH); digitalWrite(D[3], LOW); digitalWrite(D[4], LOW); delay(czas); digitalWrite(D[1], LOW); digitalWrite(D[2], LOW); digitalWrite(D[3], LOW); digitalWrite(D[4], LOW); digitalWrite(latch, LOW); shiftOut(DATA, CLK, LSBFIRST, CYFRA[tempRZ[1]]); digitalWrite(latch, HIGH); digitalWrite(D[1], LOW); digitalWrite(D[2], LOW); digitalWrite(D[3], HIGH); digitalWrite(D[4], LOW); delay(czas); digitalWrite(D[1], LOW); digitalWrite(D[2], LOW); digitalWrite(D[3], LOW); digitalWrite(D[4], LOW); digitalWrite(latch, LOW); shiftOut(DATA, CLK, LSBFIRST, CYFRA[tempRZ[2]]); digitalWrite(latch, HIGH); digitalWrite(D[1], LOW); digitalWrite(D[2], LOW); digitalWrite(D[3], LOW); digitalWrite(D[4], HIGH); delay(czas); ////////////////////wyświetlanie na lcd////////////// if ( nowa > 40) { lcd.setCursor(0, 0); lcd.print("tem zad"); lcd.setCursor(10, 0); lcd.print(tempZA[0]); lcd.print(tempZA[1]); lcd.print("."); lcd.print(tempZA[2]); lcd.setCursor(14, 0); lcd.print((char)223); lcd.print("C"); lcd.setCursor(0, 1); lcd.print("tem fakty"); lcd.setCursor(10, 1); lcd.print(tempRZ[0]); lcd.print(tempRZ[1]); lcd.print("."); lcd.print(tempRZ[2]); lcd.setCursor(14, 1); lcd.print((char)223); lcd.print("C"); nowa = 1; } nowa = nowa + 1; Serial.println(nowa); } //////////////GŁÓWNA FUNKCJA ////////////// void loop() { odczyttemp(); ustawienietemp(); uruchomieniewent(); wyswietlanietemp(); }