01-11-2016, 21:54
(31-07-2016, 22:41)Lvsky napisał(a): Pomoże ktoś ?
Witam ma coś podobnego lecz do terarium sterowanie przekażnikami - diodami i wytwornicą mgły czas pobiera z DS3231 rtc może pomogłem ,wszystko opisane w codzie
Kod:
#include <Wire.h>
#include <DS3231.h>
#include <Adafruit_ILI9341.h>
#include <EEPROM.h>
#include <TimerOne.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
#define TFT_MISO 50
#define TFT_MOSI 51
#define TFT_SCK 52
// Colors for fonts
const uint16_t BLACK = 0x0000;
const uint16_t GREY = 0x7AEF;
const uint16_t BLUE = 0x001F;
const uint16_t RED = 0xF800;
const uint16_t GREEN = 0x07E0;
const uint16_t CYAN = 0x07FF;
const uint16_t MAGENTA = 0xF81F;
const uint16_t YELLOW = 0xFFE0;
const uint16_t WHITE = 0xFFFF;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
DS3231 clock;
RTCDateTime dt;
#include <dht.h>
dht DHT;
#define DHT11_PIN 2
#define RELAY1 A0 //przekaźniki 1
#define RELAY2 A1 2
#define RELAY3 A2 3
#define RELAY4 A3 4
float temperatura_zadana=23;
float wilgotnosc_zadana=75;
void setup() {
tft.begin();
tft.fillScreen(BLACK);
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
clock.begin();
pinMode(RELAY1, OUTPUT); // definicja przekaźników 1
pinMode(RELAY2, OUTPUT); 2
pinMode(RELAY3, OUTPUT); 3
pinMode(RELAY4, OUTPUT); 4
}
void loop(void) {
tft.setTextSize(1);
tft.setCursor(1,20);
tft.println(".....................................................");
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE,ILI9341_BLACK);
tft.setCursor(1,60);
tft.println("....................................................");
int chk = DHT.read11(DHT11_PIN);
tft.setTextSize(3);
tft.setCursor(5, 35);
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
tft.print(" Temp *C= ");
tft.println(DHT.temperature);
tft.setTextSize(3);
tft.setCursor(5, 75);
tft.setTextColor(ILI9341_BLUE, ILI9341_BLACK);
tft.print(" Wilg %= ");
tft.println(DHT.humidity);
delay(250);
tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE,ILI9341_BLACK);
tft.setCursor(1,100);
tft.println("....................................................");
tft.setTextSize(1);
tft.setCursor(1,200);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.println(".....................................................");
tft.setTextSize(2);
tft.setCursor(2, 1);
tft.setTextColor(ILI9341_YELLOW, ILI9341_BLACK);
tft.print("Temp*C");
tft.setTextSize(2);
tft.setCursor(170, 2);
tft.setTextColor(0x7E0); // Green
tft.setTextColor(ILI9341_GREEN, ILI9341_BLACK);
tft.setTextSize(2);
tft.print(clock.readTemperature());
tft.setTextSize(2);
tft.setCursor(0, 215);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.print(" ");
dt = clock.getDateTime(); // pobiera czas z zegara
tft.print("");
tft.print(dt.year);tft.print("-");
tft.print(dt.month); tft.print("-");
tft.print(dt.day); tft.print(" ");
tft.print(dt.hour); tft.print(":");
tft.print(dt.minute); tft.print(":");
tft.print(dt.second); tft.println(" ");
// regulacja temperatury
if(DHT.temperature >=22);{
digitalWrite(RELAY4,HIGH);//załączenie wentylatora
}
if(DHT.temperature +1 <=22);{
digitalWrite(RELAY4,LOW);
}
//regulacja mgły
if(DHT.humidity >=75){
}
if(DHT.humidity -5 >=75) { //mgła ON
digitalWrite(RELAY3,LOW);
}
if(DHT.humidity +2 <=75) { //mgła OFF
digitalWrite(RELAY3,HIGH);
}
if(dt.hour==07 && dt.minute==00){ //tu ustawiamy czas włączenia przekaźnika
digitalWrite(RELAY1, HIGH); // LED CiepłeB podświetlanie ON
}
if(dt.hour==19 && dt.minute==00){
digitalWrite(RELAY1, LOW); // LED CiepłeB podświetlanie OFF
}
if(dt.hour==19 && dt.minute==00){
digitalWrite(RELAY2, HIGH); // LED RED podświetlanie czerwone on
}
if(dt.hour==00 && dt.minute==00){
digitalWrite(RELAY2, LOW); // LED RED podświetlanie czerwone off
}
}