#include "ASOLED.h"
#include "mice.c"
byte currBrightness = 255; //0-255 Задает яркость дисплейя;
//-------------------------------------------------------
#include "GyverButton.h"
GButton myButt1;
GButton myButt2;
GButton myButt3;
GButton myButt4;
GButton myButt5;
//----------------------------------------------------
int menuLevel = 0;
int item = 0;
int Led1 = 0;
int Led2 = 0;
int Led1On = 0;
int Led2On = 0;
int Led1Intens = 0;
int Led2Intens = 0;
int vrema = 0;
uint8_t mode_viev = 0;
int zt = 23;
//---------------------------------------------------
#include "DHT.h"
#define DHTPIN 4 // контакт, к которому подключаемся
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
//---------------------------------------------------
#include <Wire.h>
#include <Rtc_Pcf8563.h>
Rtc_Pcf8563 rtc; //инициализация модуля реального времени
//------------------------------------------------------
void setup() {
Serial.begin(9600);
LD.init(); //инициализация дисплея
LD.clearDisplay(); //первичная очистка дисплея
// pinMode(A7, INPUT_PULLUP);
myButt1.setType(LOW_PULL); //ок
myButt2.setType(LOW_PULL); //ввер
myButt3.setType(LOW_PULL); //вниз
myButt4.setType(LOW_PULL); //лево
myButt5.setType(LOW_PULL); //право
dht.begin();
//===========================
#define EVERY_MS(x) \
static uint32_t tmr;\
bool flag = millis() - tmr >= (x);\
if (flag) tmr += (x);\
if (flag)
//===========================
//rtc.initClock();
//rtc.setDate(26, 6, 7, 0, 20); //day, weekday, month, century(1=1900, 0=2000), year(0-99)
//rtc.setTime(18, 20, 0); //hr, min, sec
}
byte Key()
{
if (myButt5.isSingle()) return 6;// вправо 0
else if (myButt2.isSingle()) return 2;// вверх 144
else if (myButt3.isSingle()) return 3;// вниз 164
else if (myButt4.isSingle()) return 4;// влево 416
else if (myButt1.isSingle()) return 1;// выбрать 718
else if (analogRead(7) < 0) return 0;// ничего не нажато
//else if (digitalRead(4) == LOW) return 5;
/*
if (analogRead(7) < 190) return 6;// вправо 0
else if (analogRead(7) < 1040) return 2;// вверх 144
else if (analogRead(7) < 340) return 3;// вниз 164
else if (analogRead(7) < 500) return 4;// влево 416
else if (analogRead(7) < 705) return 1;// выбрать 718
else if (analogRead(7) < 0) return 0;// ничего не нажато
else if (digitalRead(4) == LOW) return 5;
*/
}
//-----------------------------------------------------------
void loop()
{
LD.setBrightness(currBrightness);
int analog = analogRead(7);
//Serial.println(analog);
myButt1.tick(analog < 720 && analog > 680);
myButt2.tick(analog < 1040 && analog > 1000);
myButt3.tick(analog < 340 && analog > 300);
myButt4.tick(analog < 500 && analog > 470);
myButt5.tick(analog < 190 && analog > 150);
menuGraf();
menuSwitch();
// menuLed();
// cicl();
}
void menuGraf()
{
// считывание данных температуры и влажности
float h = dht.readHumidity();
// температура в Цельсиях:
float th = dht.readTemperature();
// температура в Фаренгейте:
float f = dht.readTemperature(true);
// проверяем, корректно ли прочитались данные,
// и если нет, то пробуем еще раз:
if (isnan(h) || isnan(th) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
// "Не данных с DHT!"
return;
}
if (menuLevel == 0 && item == 0)
{
if(Led1On == 0 && Led2On == 0)
{
// LD.clearDisplay();
LD.printString_6x8("Температура дом |",1,0);
LD.printString_6x8("---------------------",0,1);
LD.printNumber(zt,0,118,0);
LD.printString_12x16("", 0, 6);
LD.printNumber((float)th,1,40,3);
LD.printString_6x8(" ",12,2);
LD.printNumber(rtc.getHour(),0,1,7);
LD.printString_6x8(":",12,7);
LD.printNumber(rtc.getMinute(),0,17,7);
LD.printString_6x8(":", 30,7);
LD.printNumber(rtc.getSecond(),0,35,7);
LD.printString_6x8(" ",60,7);
LD.printNumber(rtc.getDay(),0,85,7);
LD.printString_6x8(".",97,7);
LD.printNumber(rtc.getMonth(),0,101,7);
LD.printString_6x8(".",113,7);
LD.printNumber(rtc.getYear(),0,118,7);
/*
LD.printNumber((float)RTC.getHours(),0,0,2);
LD.printString_12x16(":",2,0);
LD.printNumber((float)RTC.getMinutes(),0,0,7);
LD.printString_12x16(":",2,5);
LD.printNumber((float)RTC.getSeconds(),0,0,12);
LD.printString_12x16("",2,10);
*/
//LD.printNumber(Led1Intens,5,2,10);
// LD.printString_6x8(" Led 2 | Off | ",0,10);
//LD.printNumber(Led2Intens,0,0,10);
//---
}
else if(Led1On == 1 && Led2On == 1)
{
LD.clearDisplay();
LD.printNumber(Led2Intens,0,0,10);
//LD.printString_6x8("Влажность",0,0);
//LD.printNumber(h,0,0,0);
//LD.printString_6x8(" Led 2 | On | ",0,10);
//---
}
else if(Led1On == 1 && Led2On == 0)
{
LD.clearDisplay();
LD.printString_6x8("->Led 1 | On | ",0,0);
LD.printNumber(Led1Intens,0,0,0);
LD.printString_6x8(" Led 2 | Off | ",0,10);
LD.printNumber(Led2Intens,0,0,10);
//---
}
else if(Led1On == 0 && Led2On == 1)
{
LD.clearDisplay();
LD.printString_6x8("->Led 1 | Off | ",0,0);
LD.printNumber(Led1Intens,0,0,0);
LD.printString_6x8(" Led 2 | On | ",0,10);
LD.printNumber(Led2Intens,0,0,10);
//---
}
Led1 = 1;
Led2 = 0;
}
else if (menuLevel == 0 && item == 1)
{
if(Led1On == 0 && Led2On == 0)
{
LD.clearDisplay();
LD.printString_6x8("Влажность1",0,0);
LD.printNumber(h,1,0,10);
//LD.printString_6x8("->Led 2 | Off | ",0,10);
//LD.printNumber(Led2Intens,0,0,10);
//---
}
else if(Led1On == 1 && Led2On == 1)
{
LD.clearDisplay();
LD.printString_6x8(" Led 1 | On | ",0,0);
LD.printNumber(Led1Intens,0,0,0);
LD.printString_6x8("->Led 2 | On | ",0,0);
LD.printNumber(Led2Intens,0,0,10);
//---
}
else if(Led1On == 1 && Led2On == 0)
{
LD.clearDisplay();
LD.printString_6x8(" Led 1 | On | ",0,0);
LD.printNumber(Led1Intens,0,0,0);
LD.printString_6x8("->Led 2 | Off | ",0,10);
LD.printNumber(Led2Intens,0,0,10);
//---
}
else if(Led1On == 0 && Led2On == 1)
{
LD.clearDisplay();
LD.printString_6x8(" Led 1 | Off | ",0,0);
LD.printNumber(Led1Intens,0,0,0);
LD.printString_6x8("->Led 2 | On | ",0,10);
LD.printNumber(Led2Intens,0,0,10);
//---
}
Led1 = 0;
Led2 = 1;
}
else if (menuLevel == 1 && item == 0 && Led1 == 1)
{
if(Led1On == 0)
{
int ah = 25;
LD.clearDisplay();
LD.printString_6x8("Настройка температуры",0,0);
//LD.printString_6x8(" Intensity:",0,10);
LD.printNumber(ah,0,0,10);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,20);
LD.printNumber(vrema,0,1,10);
}
//---
}
else if(Led1On == 1)
{
LD.clearDisplay();
LD.printString_6x8("->Led 1: On",0,0);
LD.printString_6x8(" Intensity:",0,10);
LD.printNumber(Led1Intens,0,1,10);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,20);
LD.printNumber(vrema,0,1,10);
}
//---
}
}
else if (menuLevel == 1 && item == 1 && Led1 == 1)
{
if(Led1On == 0)
{
LD.clearDisplay();
LD.printString_6x8(" Led 1: Off",0,0);
LD.printString_6x8("->Intensity:",0,10);
LD.printNumber(Led1Intens,0,1,10);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,0);
LD.printNumber(vrema,0,0,10);
}
//---
}
else if(Led1On == 1)
{
LD.clearDisplay();
LD.printString_6x8(" Led 1: On",0,0);
LD.printString_6x8("->Intensity:",1,0);
LD.printNumber(Led1Intens,1,2,0);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,20);
LD.printNumber(vrema,0,0,20);
}
//---
}
}
else if (menuLevel == 1 && item == 0 && Led2 == 1)
{
if(Led2On == 0)
{
LD.clearDisplay();
LD.printString_6x8("->Led 2: Off",0,0);
LD.printString_6x8(" Intensity:",0,10);
LD.printNumber(Led2Intens,0,0,20);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,20);
LD.printNumber(vrema,0,0,10);
}
//---
}
else if(Led2On == 1)
{
LD.clearDisplay();
LD.printString_6x8("->Led 2: On",0,0);
LD.printString_6x8(" Intensity:",0,10);
LD.printNumber(Led2Intens,0,0,10);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,20);
}
//---
}
}
else if (menuLevel == 1 && item == 1 && Led2 == 1)
{
if(Led2On == 0)
{
LD.clearDisplay();
LD.printString_6x8(" Led 2: Off",0,0);
LD.printString_6x8("->Intensity:",0,10);
LD.printNumber(Led2Intens,0,1,0);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,20);
LD.printNumber(vrema,0,1,0);
}
//---
}
else if(Led2On == 1)
{
LD.clearDisplay();
LD.printString_6x8(" Led 2: On",0,0);
LD.printString_6x8("->Intensity:",0,10);
LD.printNumber(Led2Intens,0,0,20);
if(mode_viev == 1)
{
LD.printString_6x8("R | Change",0,20);
LD.printNumber(vrema,0,1,20);
}
//---
}
}
}
void menuSwitch()
{
switch (Key())
{
case 1:
if (mode_viev == 1)
{
}
else
{
menuLevel = 1;
item = 0;
}
break;
case 2:
if(mode_viev == 1 && Led1 == 1 && item == 0)
{
Led1On = 1;
}
else if(mode_viev == 1 && Led1 == 1 && item == 1)
{
Led1Intens = Led1Intens + 1;
}
else if(mode_viev == 1 && Led2 == 1 && item == 0)
{
Led2On = 1;
}
else if(mode_viev == 1 && Led2 == 1 && item == 1)
{
Led2Intens = Led2Intens + 1;
}
else
{
item = 0;
}
break;
case 3:
if(mode_viev == 1 && Led1 == 1 && item == 0)
{
Led1On = 0;
}
else if(mode_viev == 1 && Led1 == 1 && item == 1)
{
Led1Intens = Led1Intens - 1;
}
else if(mode_viev == 1 && Led2 == 1 && item == 0)
{
Led2On = 0;
}
else if(mode_viev == 1 && Led2 == 1 && item == 2)
{
Led2Intens = Led2Intens - 1;
}
else
{
item = 1;
}
break;
case 4:
menuLevel = 0;
item = 0;
mode_viev = 0;
break;
case 6:
mode_viev = 0;
Led1On = 0;
Led2On = 0;
Led1Intens = 0;
Led2Intens = 0;
break;
}
}
void menuLed()
{
if (Led1On == 1)
{
analogWrite(10, Led1Intens);
}
else
{
analogWrite(10, 0);
}
if (Led2On == 1)
{
analogWrite(11, Led2Intens);
}
else
{
analogWrite(11, 0);
}
}
void cicl()
{
vrema = 0;
while(digitalRead(4) == LOW)
{
if(vrema == 1)
{
mode_viev = 1;
}
else if(mode_viev == 1)
{
mode_viev = 0;
}
vrema++;
Serial.println(vrema);
//delay(1000);
}
}