Erst mal vielen Dank an alle die mitgedacht und mitgeholfen haben.
Dann fehlt vermutlich ein "status = 20;" in Deiner Setup-Routine, wenn 20 jetzt Dein "aus" Status ist.
Ja 20 ist jetzt mein aus status und du hattest recht im setup war status noch auf 0 gesetzt.
Hab jetzt noch mal ein bisschen durchprobiert und jetzt klappt es erst mal endlich wie gewollt.
Hier mal jetzt das gesamtergebnis:
#include <Bounce.h>
#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
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;
Bounce bouncer = Bounce( knopf1, 5 );
uint32_t previousMillis = 0;
int mpxPin = 5; //drucksensor
int mpx;
float pkPa;
uint8_t ledPin = 9; // (kemo)
uint8_t fade;
uint8_t status;
uint32_t nextMillis = 0;
uint32_t thresholdMillis = 0;
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=20; // 20 = aus
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 ");
lcd.setCursor(10, 1);
lcd.print(fade);
}
if ( bouncer.update() ) {
if ( bouncer.read() == HIGH) {
if ( buttonState == LOW ) {
uint8_t i;
for (i = 0; i < 4; i++) {
digitalWrite(k[i], HIGH);
}
analogWrite(ledPin, 0);
thresholdMillis = 0;
nextMillis = 0;
status = 0;
buttonState = HIGH;
} else {
status = 20; // programm1 aus
uint8_t i;
for (i = 0; i < 4; i++) {
digitalWrite(k[i], HIGH);
}
analogWrite(ledPin, 0);
thresholdMillis = 0;
nextMillis = 0;
buttonState = LOW;
}
}
}
programm1();
} // endklammer des loops
void programm1() {
if (status == 0){
digitalWrite(k[0], LOW);
status = 1;
} else if (sensors.getTempC(Sensor[0]) >= 23.0 && status == 1) {
digitalWrite(k[0], HIGH);
status = 2;
nextMillis = millis() + 30000L;
} else if (status == 2 && millis() > nextMillis) {
digitalWrite(k[1], LOW);
digitalWrite(k[2], LOW);
digitalWrite(k[3], LOW);
fade = 0;
analogWrite(ledPin, fade);
fade = 51;
analogWrite(ledPin, fade);
status = 3;
nextMillis = millis() + 30000L;
} else if (status == 3 && millis() > nextMillis) {
fade = 102;
analogWrite(ledPin, fade);
status = 4;
nextMillis = millis() + 30000L;
} else if (status == 4 && millis() > nextMillis) {
fade = 153;
analogWrite(ledPin, fade);
status = 5;
nextMillis = millis() + 30000L;
} else if (status == 5 && millis() > nextMillis) {
fade = 255;
status = 6;
}
if (sensors.getTempC(Sensor[0]) >= 25.0 && thresholdMillis == 0) {
digitalWrite(k[1], HIGH);
thresholdMillis = millis() + 30000L;
} else if (thresholdMillis && millis() > thresholdMillis) {
digitalWrite(k[2], HIGH);
digitalWrite(k[3], HIGH);
analogWrite(ledPin, 0);
thresholdMillis = 0;
nextMillis = 0;
fade = 0;
status = 20;
}
}
Als nächstes will ich noch einen pausenknopf, um programm1 anhalten und fortführen zu können, einbauen, aber das versuch ich erstmal selbst zu machen.
Noch mal vielen Dank, besonders an jurs der sehr aktiv und interesiert mitgewirkt hat.
Mfg
strohhirn