Hier eine leicht korrigierte und kommentierte Fassung:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define ONE_WIRE_BUS 30 // Temperatursensor pin 30
#define FADE_DELAY 3 // Verzögerung beim Faden
#define SENSOR_PERIODE 400 // wie oft werden die Sensoren ausgelesen
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 startButton = 34; // Startknopf an Pin 34
uint8_t pauseButton = 30; // Pauseknopf an Pin 30
uint8_t startButtonPushCounter = 0;
uint8_t pauseButtonPushCounter = 0;
uint8_t lastStartButtonState = 0;
uint8_t lastPauseButtonState = 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;
uint32_t sensorTime = 0;
uint32_t nextMillis = 0;
uint32_t thresholdMillis = 0;
uint32_t nmSave = 0;
uint32_t tmSave = 0;
void setup() {
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH);
lcd.begin(20, 4);
sensors.begin();
uint8_t i;
// all relays off (HIGH)
for (i = 0; i < 4; i++) {
pinMode(k[i], OUTPUT);
digitalWrite(k[i], HIGH);
}
// button pins must be inputs
pinMode(startButton, INPUT);
pinMode(pauseButton, INPUT);
status=0;
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
sensorTime = millis() + SENSOR_PERIODE;
}
void loop(){
// check if conversion is done
if (millis() > sensorTime && oneWire.read_bit()) {
uint8_t i;
sensorTime += SENSOR_PERIODE;
// display values of all 4 temp sensors
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();
// display pressure value
mpx = analogRead(mpxPin);
pkPa = (mpx/1023.0-0.04)/0.0018;
lcd.setCursor(10, 0);
lcd.print(pkPa);
lcd.print("mb ");
lcd.setCursor(10, 1);
lcd.print(fade);
}
// check start button
uint8_t buttonState = digitalRead(startButton);
if (buttonState != lastStartButtonState && buttonState == HIGH) {
startButtonPushCounter++;
}
lastStartButtonState = buttonState;
// check pause button
buttonState = digitalRead(pauseButton);
if (buttonState != lastPauseButtonState && buttonState == HIGH) {
pauseButtonPushCounter++;
}
lastPauseButtonState = buttonState;
if (pauseButtonPushCounter & 0x01) {
// activate paused state
nmSaved = nextMillis;
nextMillis = 0;
tmSaved = thresholdMillis;
thresholdMillis = 0;
} else {
// recover after paused state
nextMillis = nmSaved;
nmSaved = 0;
thresholdMillis = tmSaved;
tmSaved = 0;
}
if (startButtonPushCounter & 0x01 == 0) {
// deactivate all relays, turn off LED and reset status
status = 0;
analogWrite(ledPin, 0); // turn LED off
for (uint8_t i = 0; i < 4; i++) {
digitalWrite(k[i], HIGH); // turn all relays off
}
} else if (nmSaved == 0) { // run programm1 only if not in paused state
programm1();
}
}
void programm1() {
if (sensors.getTempC(Sensor[0]) >= 25.8 && status == 0) {
// temp above 25.8 degrees and heating, turn R1 off
digitalWrite(k[0], HIGH);
status = 1;
nextMillis = millis() + 60000L; // next state in 1 min
} else if (status == 0) {
// heat
digitalWrite(k[0], LOW); // turn R1 on
} else if (status == 1 && millis() > nextMillis) {
// turn R2-4 on
digitalWrite(k[1], LOW);
digitalWrite(k[2], LOW);
digitalWrite(k[3], LOW);
fade = 0;
analogWrite(ledPin, fade); // start fade loop
nextMillis += FADE_DELAY;
status = 2;
} else if (status == 2 && millis() > nextMillis) {
// fade loop
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 51) {
// fade value reached, next state
status = 3;
nextMillis = millis() + 120000L; // next state in 2 min
}
} else if (status == 3 && millis() > nextMillis) {
// start next fade loop
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
status = 4;
} else if (status == 4 && millis() > nextMillis) {
// fade loop
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 102) {
// fade value reached, next state
status = 5;
nextMillis = millis() + 180000L; // next state in 3 min
}
} else if (status == 5 && millis() > nextMillis) {
// start next fade loop
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
status = 6;
} else if (status == 6 && millis() > nextMillis) {
// fade loop
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 153) {
// fade value reached, next state
status = 7;
nextMillis = millis() + 240000L; // next state in 4 min
}
} else if (status == 7 && millis() > nextMillis) {
// start next fade loop
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
status = 8;
} else if (status == 8 && millis() > nextMillis) {
// fade loop
nextMillis += FADE_DELAY;
analogWrite(ledPin, ++fade);
if (fade >= 255) {
// fade value reached, next state and stay there
status = 9;
}
}
if (sensors.getTempC(Sensor[0]) >= 99.0 && thresholdMillis == 0) {
// temp over 99 degrees, turn off R2
digitalWrite(k[1], HIGH);
thresholdMillis = millis() + 300000L; // next action in 5 min
} else if (thresholdMillis && millis() > thresholdMillis) {
// turn off R3 and R4, turn off LED, reset all states
digitalWrite(k[2], HIGH);
digitalWrite(k[3], HIGH);
analogWrite(ledPin, 0);
thresholdMillis = 0;
nextMillis = 0;
status = 0;
}
}
Mit den Kommentaren solltest Du in der Lage sein, weitere Änderungen selbst vorzunehmen. Dieses Forum ist eigentlich kein Programmierservice, sondern soll Hilfestellungen geben.
Die Fade-Zeiten kannst Du, wie erwähnt mittels verändern der Konstante FADE_DELAY selbst verändern.
der pausenknopf, den ich an pin 36 angeschlossen habe und mit einem 10k wiederstand versehen habe, funktioniert auch nicht.
Der Knopf kommt an Pin 30 (nach meinem Sketch). Von wo nach wo geht denn der 10k Widerstand?
if(start < 2){
digitalWrite(k[0], LOW);
start++;
}
Dieser Code macht gar nichts, da die Variable start nicht definiert ist. Dies sollte einen Compiler-Fehler produzieren.