Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.8 kB
1
Indexable
Never
#include <microDS18B20.h>
#include <LCD_I2C.h>
MicroDS18B20<27> sensor;


LCD_I2C lcd(0x27, 16, 2);

byte stopnie[8] = {
  B00110,
  B01001,
  B01001,
  B00110,
  B00000,
  B00000,
  B00000,
  B00000
};


void setup() {
  Serial.begin(9600);

  lcd.begin();
  lcd.backlight();
  lcd.createChar(0, stopnie);

}

void loop() {

  static uint32_t tmr;
  if (millis() - tmr >= 800) {
    tmr = millis();


    // if (sensor.readTemp()) Serial.println(sensor.getTemp());
    // else Serial.println("error");

    if (sensor.readTemp()) {
      lcd.print(sensor.getTemp());
      lcd.write(byte(0));
      lcd.print('C');
    } else Serial.println("error");


    sensor.requestTemp();
  }

  delay(1000);
  lcd.clear();
}


--------------

#include <microDS18B20.h>
#include <LCD_I2C.h>
MicroDS18B20<27> sensor;
uint8_t address[8];


LCD_I2C lcd(0x27, 16, 2);

byte stopnie[8] = {
  0b00110,
  0b01001,
  0b01001,
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};


void setup() {
  Serial.begin(9600);

  lcd.begin();
  lcd.backlight();
  lcd.createChar(0, stopnie);

}

void loop() {

  lcd.setCursor(0, 0);
  static uint32_t tmr;
  if (millis() - tmr >= 800) {
    tmr = millis();

    if (sensor.readTemp()) {
      lcd.print(sensor.getTemp());
      lcd.write(byte(0));
      lcd.print('C');
    } else Serial.println("error");

    sensor.requestTemp();
  }

  delay(1000);
  lcd.clear();


  lcd.setCursor(0, 1);
  if (sensor.readAddress(address)) {
    for (uint8_t i = 1; i < 7; i++) {
      lcd.print(address[i], HEX);
    }
  }

}


---------------

#include <microDS18B20.h>
#include <LCD_I2C.h>
MicroDS18B20<27> sensor;
uint8_t address[8];


LCD_I2C lcd(0x27, 16, 2);

byte stopnie[8] = {
  0b00110,
  0b01001,
  0b01001,
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

double table[10];
int counter = 0;
double srednia = 0;
double sum = 0;

void setup() {
  Serial.begin(9600);

  lcd.begin();
  lcd.backlight();
  lcd.createChar(0, stopnie);

}

void loop() {

  // AKTUALNA TEMPERATURA
  lcd.setCursor(0, 0);
  static uint32_t tmr;
  if (millis() - tmr >= 800) {
    tmr = millis();

    if (sensor.readTemp()) {
      lcd.print("temp: ");
      lcd.print(sensor.getTemp());
      lcd.write(byte(0));
      lcd.print('C');
    }

    sensor.requestTemp();
  }

  
  // ŚREDNIA TEMPERATURA
  lcd.setCursor(0, 1);
  if (sensor.readTemp()) {

      table[counter] = sensor.getTemp();
      counter++;
      if (counter == 10) counter = 0;

      for (int i = 0; i < 10; i++) {
        sum += table[i];
        Serial.print(table[i]);
        Serial.print(' ');
      }
      Serial.println();
      srednia = sum / 10;
      sum = 0;

      lcd.print("avg:  ");
      lcd.print(srednia);
      lcd.write(byte(0));
      lcd.print('C');
    
    }


  delay(2000);
  lcd.clear();
}
Leave a Comment