13-06-2019, 19:24
Witam.
Robię sterownik j.w. i mam problem z millis.
Proszę o radę jak zastąpić delay, które teraz do testów jest małe a docelowo musi być ok 2min ,funkcją millis.
Robię sterownik j.w. i mam problem z millis.
Proszę o radę jak zastąpić delay, które teraz do testów jest małe a docelowo musi być ok 2min ,funkcją millis.
Kod:
int POMPA = A1;
int FILTR = A2;
int TEMP_POMPY = 0;
int TB = 0;
int TD = 0;
int to = 0;
unsigned long ACZ = 0;
unsigned long PCZ = 0;
unsigned long RCZ = 0;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress TempBas = {0x28, 0xAA, 0xD3, 0x73, 0x18, 0x13, 0x2, 0xD7 };
DeviceAddress TempDach = {0x28, 0xAA, 0x2F, 0xB8, 0x1A, 0x13, 0x2, 0xB2 };
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 20 chars and 4 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
sensors.begin();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("BASEN |PH");
lcd.setCursor(0, 1);
lcd.print("DACH |REDOX");
lcd.setCursor(0, 2);
lcd.print("DOMEK |POMPA");
lcd.setCursor(0, 3);
lcd.print("ZEWN. |FILTR -");
pinMode(POMPA, OUTPUT);
pinMode(FILTR, OUTPUT);
digitalWrite(POMPA, HIGH);
digitalWrite(FILTR, HIGH);
}
void loop()
{
sensors.requestTemperatures();
lcd.setCursor(6, 0);
lcd.print(sensors.getTempC(TempBas), 1);
int TB = sensors.getTempCByIndex(0);
lcd.setCursor(6, 1);
lcd.print(sensors.getTempC(TempDach), 1);
int TD = sensors.getTempCByIndex(1);
TEMP_POMPY = TD - TB;
lcd.setCursor(16, 0);
lcd.print(TEMP_POMPY);
lcd.setCursor(16, 1);
//lcd.print(TD),1;
ACZ = millis();
if (TEMP_POMPY >= 3) {
digitalWrite(POMPA, LOW);
lcd.setCursor(18, 2);
lcd.print("*");
RCZ = ACZ - 5000UL;
}
if (TEMP_POMPY <= 2) {
digitalWrite(POMPA, HIGH);
lcd.setCursor(18, 2);
lcd.print("-");
}
if (TEMP_POMPY >= 3) {
delay(5000);
digitalWrite(FILTR, LOW);
lcd.setCursor(18, 3);
lcd.print("*");
to = 1;
}
if ((TEMP_POMPY <= 2) && (to == 1)) {
delay(5000);
digitalWrite(FILTR, HIGH);
lcd.setCursor(18, 3);
lcd.print("-");
to = 0;
}
}