• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Zaokrąglenie wyniku pomiaru temperatury do jednego miejsca po przecinku ds18b20
#1
Poszukuję już kilka dni w necie jak w moim kodzie zaokrąglić wynik pomiaru z czujnika ds18b20 do jednego miejsca po przecinku, bardzo bym prosił o pomoc.

Kod:
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int backLight = 3;


#define ONE_WIRE_BUS 2


// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);


DeviceAddress a = { 0x28, 0xFF, 0x84, 0x3B, 0xB1, 0x15, 0x1, 0x1A };
DeviceAddress b = { 0x28, 0xFF, 0xEC, 0x22, 0xB0, 0x15, 0x3, 0x89 };
DeviceAddress c = { 0x28, 0xFF, 0x92, 0x22, 0xB0, 0x15, 0x3, 0x46 };
DeviceAddress d = { 0x28, 0xFF, 0x4E, 0x4C, 0xB1, 0x15, 0x1, 0xAB };
DeviceAddress e = { 0x28, 0xFF, 0x1, 0x22, 0xB0, 0x15, 0x3, 0xBF };
DeviceAddress f = { 0x28, 0xFF, 0x4D, 0x23, 0xB0, 0x15, 0x3, 0xF8 };
DeviceAddress g = { 0x28, 0xFF, 0x3D, 0x4E, 0xB1, 0x15, 0x1, 0x8F };
DeviceAddress h = { 0x28, 0xFF, 0x8B, 0x47, 0xB1, 0x15, 0x1, 0xCF };


void setup(void)
{
// Start up the library
sensors.begin();// set the resolution to 10 bit (good enough?)

sensors.setResolution(a, 12);
sensors.setResolution(b, 12);
sensors.setResolution(c, 12);
sensors.setResolution(d, 12);
sensors.setResolution(e, 12);
sensors.setResolution(f, 12);
sensors.setResolution(g, 12);
sensors.setResolution(h, 12);


pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(20,4); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen


}

void printTemperature(DeviceAddress deviceAddress)


{
float tempC = sensors.getTempC(deviceAddress);

if (tempC == -127.00) {
lcd.print("----");
} else {
lcd.print(tempC);


}
}

void loop(void)
{
delay(1000);
sensors.requestTemperatures();


lcd.setCursor(0,0);
lcd.print(" A ");
printTemperature(a);

lcd.setCursor(0,1);
lcd.print(" B ");
printTemperature(b);

lcd.setCursor(0,2);
lcd.print(" C ");
printTemperature(c);

lcd.setCursor(0,3);
lcd.print(" D ");
printTemperature(d);

lcd.setCursor(11,0);
lcd.print(" E ");
printTemperature(e);

lcd.setCursor(11,2);
lcd.print(" F ");
printTemperature(f);

lcd.setCursor(11,1);
lcd.print(" G ");
printTemperature(g);

lcd.setCursor(11,3);
lcd.print(" H ");
printTemperature(h);

}
 
#2
Coś takiego w zależności jak działa lcd.print(tempC,1);
 
#3
(28-02-2016, 14:30)-adamek napisał(a): Coś takiego w zależności jak działa lcd.print(tempC,1);

To jest niemożliwe że to było takie proste. Zmarnowe dwa dni urlopu na szukanie w necie informacji a wystarczyło zapytać. Bardzo dziękuje zadziałało.
 
#4
Zamykam. Smile
[Obrazek: Sygnatura1-w60.jpg]
 
  


Skocz do:


Przeglądający: 1 gości