Wenn Du die aktuelle Version der DallasTemperatue-Bibliothek (372Beta) einsetzt, dann könnte der folgende Code funktionieren:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define ONE_WIRE_BUS 30 // Temperatursensor pin 30
#define FADE_DELAY 30 // Verzögerung beim Faden
LiquidCrystal lcd(22, 23, 24, 25, 26, 27, 28);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress Sensor[] = {{0x28, 0xCD, 0x9B, 0xDA, 0x03, 0x00, 0x00, 0xF2},
{0x28, 0x1F, 0xA3, 0xDA, 0x03, 0x00, 0x00, 0xE2},
{0x28, 0x2D, 0xB9, 0xDA, 0x03, 0x00, 0x00, 0xA0},
{0x28, 0x37, 0x88, 0xDA, 0x03, 0x00, 0x00, 0x7D}};
int backLight = 29;
uint8_t k[] = {31, 32, 33, 35}; //relais HIGH = Aus; LOW = An
uint8_t knopf1 = 34;
uint8_t buttonState = 0; //knopf
int buttonPushCounter = 0;
uint8_t lastButtonState = 0;
uint32_t previousMillis = 0;
uint32_t interval = 31000;
uint32_t zeit = 31000;
int mpxPin = 5; //drucksensor
int mpx;
float pkPa;
uint8_t ledPin = 9; // (kemo)
uint8_t fade;
uint8_t status;
void setup() {
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH);
lcd.begin(20, 4);
sensors.begin();
uint8_t i;
for (i = 0; i < 4; i++) {
pinMode(k[i], OUTPUT);
digitalWrite(k[i], HIGH);
}
pinMode(knopf1, INPUT);
status=0;
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
}
void loop(){
// check if conversion is done
if (oneWire.read_bit()) {
uint8_t i;
for (i = 0; i < 4; i++) {
lcd.setCursor(0, i);
lcd.print("T");
lcd.print(i+1, DEC);
lcd.print(":");
if (sensors.isConnected(Sensor[i])) {
lcd.print(sensors.getTempC(Sensor[i]));
lcd.print("C");
} else {
lcd.print("AUS ");
}
}
// start next conversion
sensors.requestTemperatures();
mpx = analogRead(mpxPin);
pkPa = (mpx/1023.0-0.04)/0.0018;
lcd.setCursor(10, 0);
lcd.print(pkPa);
lcd.print("mb ");
}
buttonState = digitalRead(knopf1);
if (buttonState != lastButtonState && buttonState == HIGH) {
buttonPushCounter++;
}
lastButtonState = buttonState;
if (buttonPushCounter % 2 == 0 && status == 0) {
digitalWrite(k[0], HIGH);
} else {
programm1();
}
}
void programm1() {
static uint32_t nextMillis = 0;
static uint32_t thresholdMillis = 0;
if (sensors.getTempC(Sensor[0]) >= 25.8 && status == 0) {
digitalWrite(k[0], HIGH);
status = 1;
nextMillis = millis() + 60000L;
} else if (status == 1 && millis() > nextMillis) {
digitalWrite(k[1], LOW);
digitalWrite(k[2], LOW);
digitalWrite(k[3], LOW);
fade = 0;
analogWrite(ledPin, fade);
nextMillis += FADE_DELAY;
status = 2;
} else if (status == 2 && millis() > nextMillis) {
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 51) {
status = 3;
nextMillis = millis() + 120000L;
}
} else if (status == 3 && millis() > nextMillis) {
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
status = 4;
} else if (status == 4 && millis() > nextMillis) {
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 102) {
status = 5;
nextMillis = millis() + 180000L;
}
} else if (status == 5 && millis() > nextMillis) {
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
status = 6;
} else if (status == 6 && millis() > nextMillis) {
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 153) {
status = 7;
nextMillis = millis() + 240000L;
}
} else if (status == 7 && millis() > nextMillis) {
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
status = 8;
} else if (status == 8 && millis() > nextMillis) {
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 255) {
status = 9;
}
}
if (sensors.getTempC(Sensor[0]) >= 99.0 && thresholdMillis == 0) {
digitalWrite(k[1], HIGH);
thresholdMillis = millis() + 300000L;
} else if (thresholdMillis && millis() > thresholdMillis) {
digitalWrite(k[2], HIGH);
digitalWrite(k[3], HIGH);
analogWrite(ledPin, 0);
thresholdMillis = 0;
nextMillis = 0;
status = 0;
}
}
Hier wird die im Datenblatt beschriebene Möglichkeit ausgenutzt, Read-Slots abzusetzen, nachdem der Convert T-Befehl gesendet wurde. Es sollte erst eine 1 zurückkommen, wenn die Konversion abgeschlossen ist. Damit wird die maximal mögliche Anzahl der Temperatur-Lesungen vorgenommen, ohne die restliche Ausführung merklich zu bremsen.
Sollte obiges Programm nicht wie gewollt funktionieren, kannst Du mal versuchen, die Zeile
if (oneWire.read_bit()) {
durch
if (sensors.isConversionAvailable(0)) {
zu ersetzen. Das könnte gehen (ist der von der Bibliothek gewählte Weg), ist aber deutlich langsamer (ca. 10ms anstatt 100us) als die erste Variante und widerspricht dem Datenblatt.