#include <Adafruit_GFX.h> //Display
#include <Adafruit_ST7735.h> //Display
#include <SPI.h> //Display
#include <OneWire.h>
#include <DS18B20.h>
#define TFT_CS 10 //Display
#define TFT_RST 8 //Display
#define TFT_DC 9 //Display
#define TFT_SCLK 13 //Display
#define TFT_MOSI 11 //Display
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); //Display
const byte ONEWIRE_PIN = 3;
const byte SENSORS_NUM = 2;
const byte sensorsAddress[SENSORS_NUM][8] PROGMEM =
{
0x28,0xFF, 0xC0, 0xAD, 0x86, 0x16, 0x5, 0x94,
0x28, 0xFF, 0x68, 0x5D, 0x85, 0x16, 0x3, 0xD1
};
float temperaturein;
float temperatureout;
volatile int flow_frequency; // Measures flow meter pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowmeter = 2; // Flow Meter Pin number
unsigned long currentTime;
unsigned long cloopTime;
unsigned long Wartezeit = 800;
unsigned long previousMillis = 0;
unsigned long Wartezeitrelai = 10000;
unsigned long previousMillis1 = 0;
int relaipin = 5;
bool relaiwartezeitmerker = false;
void flow ()
{
flow_frequency++;
}
OneWire onewire(ONEWIRE_PIN);
DS18B20 sensors(&onewire);
void setup(void)
{
while(!Serial);
Serial.begin(9600);
tft.initR(INITR_BLACKTAB); //Display
tft.setRotation(1);
uint16_t time = millis(); //Display
tft.fillScreen(ST7735_BLACK); //Display
time = millis() - time; //Display
sensors.begin();
sensors.request();
pinMode(flowmeter, INPUT);
attachInterrupt(0, flow, RISING);
sei();
currentTime = millis();
cloopTime = currentTime;
pinMode(relaipin, OUTPUT);
}
void loop()
{
if (millis() - previousMillis > Wartezeit)
{
tft.drawLine(0,0, 159, 0, 0x07FF); //Waagerechte Oben
tft.drawLine(0,159,128,159, 0x07FF); //Waagerechte unten
tft.drawLine(0,0,0,159, 0x07FF); //senkrechte links
tft.setTextSize(2);
tft.setCursor(10, 8);
testdrawtext("Lasercontrol", ST7735_GREEN);
tft.drawLine(0,30, 159, 30, 0x07FF); //Waagerechte unter Lasercontrol Oben
tft.setTextSize(1);
tft.setCursor(10,43);
testdrawtext("FLOW :", ST7735_YELLOW);
tft.setCursor(80,38);
tft.setCursor(128,43);
testdrawtext("l/min", ST7735_YELLOW);
tft.drawLine(0,62, 159, 62, 0x07FF); //Waagerechte unter flow
tft.setCursor(10,74);
testdrawtext("Temp in :", ST7735_YELLOW);
tft.setCursor(130,74);
testdrawtext("Grad", ST7735_YELLOW);
tft.drawLine(0,96, 159, 96, 0x07FF);
tft.setCursor(10,108);
testdrawtext("Temp out:", ST7735_YELLOW);
tft.setCursor(130,108);
testdrawtext("Grad", ST7735_YELLOW);
tft.setTextSize(2);
if (l_hour <6)
{
tft.setTextColor(ST7735_RED);
}
else
{
tft.setTextColor(ST7735_GREEN);
}
tft.fillRect(87,39,40,20, ST7735_BLACK);
tft.setCursor(87,39);
tft.print(l_hour);
if (temperaturein > temperatureout)
{
tft.setTextColor(ST7735_RED);
}
else
{
tft.setTextColor(ST7735_GREEN);
}
tft.fillRect(65,70,60,20, ST7735_BLACK);
tft.setCursor(65,70);
tft.print(temperaturein);
tft.fillRect(65,105,60,20, ST7735_BLACK);
tft.setCursor(65,105);
tft.print(temperatureout);
previousMillis = millis();
}
currentTime = millis();
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime;
l_hour = (flow_frequency / 7.5);
flow_frequency = 0;
}
if (sensors.available())
{
{
temperaturein = sensors.readTemperature(FA(sensorsAddress[0]));
temperatureout = sensors.readTemperature(FA(sensorsAddress[1]));
}
sensors.request();
}
if (((temperaturein > temperatureout) or (l_hour < 6)) & (relaiwartezeitmerker == false))
{
digitalWrite(relaipin, LOW);
relaiwartezeitmerker = true;
}
if (((temperaturein < temperatureout) or (l_hour > 6)) & (relaiwartezeitmerker == true))
{
if (millis() - previousMillis1 > Wartezeitrelai)
{
digitalWrite(relaipin, HIGH);
relaiwartezeitmerker = false;
previousMillis1 = millis();
}
}
}
void testdrawtext(char *text, uint16_t color) {
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
Alles anzeigen