Черный экран и больше ничего. Помогите советом
- Войдите на сайт для отправки комментариев
Пт, 05/05/2017 - 13:21
Всем привет! Есть скетч. Проект бортового компьютера для авто. Загружаю скетч в ардуино нано. Заливает черным экран и дальше ничего. Ни надписей, никаких действий. Подскажите где ошибка? Да и к машине пока не подключен.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Adafruit_ST7735.h>
#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
//#include <LiquidCrystal.h>
#include <OneWire.h>
#include <EEPROM.h>
#include "RTClib.h"
RTC_DS1307 rtc;
#define TFT_CS 10 //CS на дисплее
#define TFT_RST 9 //RESET на дисплее
#define TFT_DC 8 //AO на дисплее
#define TFT_SCLK 13 //SCK на дисплее
#define TFT_MOSI 11 //SDA на дисплее
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
OneWire ds(14); //датчик 18в20 на выводе А0
#define BUFFER_SIZE 100 // Буфер для хранения данных последовательного порта
#define buffer_errors_size 20 // Буфер для ошибок ЭБУ
#define buzz 12 // Вывод пищалки
#define backlight 11 // Вывод управления подсветкой дисплея
//--------------------------назначение ячеек в памяти EEPROM------------------------
#define eepautolightstat 10
#define eepautolightoff 11
#define eepautolighton 12
#define eepcoolfanstat 13
#define eepcoolfanoff 14
#define eepcoolfanon 15
#define eepheatfanon 16
#define eepheatfan1 17
#define eepheatfan2 18
#define eepbacklight 19
//-------------------------команды для обмена данными и управления ЭБУ-----------------------
unsigned char stopCommunication[] = {0x81, 0x10, 0xF1, 0x82, 0x04};
unsigned char startCommunication[] = {0x81, 0x10, 0xF1, 0x81, 0x03}; //старт диагностического сеанса
unsigned char readDataByLocalIdentifier_RLI_ASS[] = {0x82, 0x10, 0xF1, 0x21, 0x01, 0xA5}; //запрос диагностических данных
unsigned char readDTCByStatus[] = {0x84, 0x10, 0xF1, 0x18, 0x00, 0x00, 0x00, 0x9D}; //запрос кодов ошибок
unsigned char startcoolfan[] = {0x84, 0x10, 0xF1, 0x30, 0x0A, 0x06, 0x01, 0xC6};
unsigned char stopcoolfan[] = {0x83, 0x10, 0xf1, 0x30, 0x0A, 0x00, 0xBE};
unsigned char clearerrors[] = {0x83, 0x10, 0xF1, 0x14, 0x00, 0x00, 0x98};
unsigned char statusfan[] = {0x83, 0x10, 0xF1, 0x30, 0x0A, 0x01, 0xBF};
byte ds_check = 1;
byte val_heat = 1;
byte Spd = 1;
byte To = 1;
byte Toon = 0;
byte Gaz = 1;
short obr = 1;
float u = 1;
float FuelRateKm = 1;
float Fuelhoure = 1;
byte bot_long = 0;
int light_sensor = 0;
int lt_time = 0;
float celsius = 0;
byte eepromi;
byte eeprom1;
byte eeprom2;
int light_sensor_summ = 0;
byte val_coolfan_stat = 0;
byte kol_er = 0;
int yeartime;
byte monthtime;
byte daytime;
byte hourtime;
byte minutetime;
byte secondtime;
byte clockinit = 0;
byte clockfirst = 1;
byte eepromltst = 0;
byte eepromlton = 1;
byte eepromltoff = 1;
byte eeprombllight = 0;
byte eepromfan = 0;
byte eepromf1 = 0;
byte eepromf2 = 0;
byte eepromcool = 0;
byte eepromcooloff = 0;
byte eepromcoolon = 0;
byte bottom = 0;
byte Spd1 = 0;
byte To1 = 0;
byte Gaz1 = 0;
short obr1 = 0;
float u1 = 0;
float FuelRateKml = 0;
float Fuelhoure1 = 0;
byte i = 0;
unsigned char buffer[BUFFER_SIZE]; //буфер для приема сообщений с тачки
unsigned char buffer_errors [buffer_errors_size];
byte bufSize = 0;
uint8_t clr[8] = {B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000};
uint8_t l_h[8] = {B10000, B10001, B11010, B00100, B01000, B10101, B00111, B00101}; // Знак расход в час
uint8_t l1_100[8] = {B00100, B00100, B00100, B00111, B00000, B10111, B10101, B10111}; // Знак расхода на 100 старший
uint8_t l2_100[8] = {B00010, B00100, B01000, B10000, B00000, B11100, B10100, B11100}; // Знак расхода на 100 младший
// uint8_t load_5[8] = {B11100,B11100,B11100,B11111,B11111,B11111,B11111,B11111};
uint8_t temp[8] = {B11000, B11000, B00000, B00111, B00100, B00100, B00111, B00000}; // Знак температуры
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print("Инициализация....");
// Use this initializer if you're using a 1.8" TFT
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
Serial.println("Initialized");
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
tft.setRotation(3);
eeprominit();
/* // set up the LCD's number of columns and rows:
tft.begin(16, 2);
// tft.init();
// tft.backlight();*/
//pinMode(14, OUTPUT);
Serial.begin(10400);
Wire.begin();
rtc.begin();
/*tft.createChar(1, clr);
tft.createChar(3, l1_100);
tft.createChar(4, l2_100);
tft.createChar(5, l_h);
tft.createChar(6, temp); //Максимум до восьми пользовательских символов (0 - 7 нумерация)*/
if (! rtc.isrunning()) {
tft.setCursor(0, 0);
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(2);
tft.print("RTC is NOT");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(2015, 5, 29, 13, 55, 0));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
pinMode(backlight, OUTPUT);
// pinMode(FAN_HEAT, OUTPUT);
//pinMode(ON_LIGHT, OUTPUT);
// digitalWrite(FAN_HEAT, HIGH); // Выключить печку
// digitalWrite(ON_LIGHT, LOW); // Выключить автосвет
analogWrite(backlight, 150); //Начальный уровень подсветки дисплея
clockfirst = 1;
tft.fillScreen(ST7735_BLACK);
initcon();
// tft.fillScreen(ST7735_BLACK);
}
void loop()
{
// Serial.write(startCommunication, 5);
// delay(30);
Serial.write(readDataByLocalIdentifier_RLI_ASS, 6); // Запрос на прием диагностических данных
bott_150ms();
//-----------------------------------------------------------Чтение данных из порта---------------------------------//
readbuf();
if (buffer[10] == 0x61) { // Положительный ответ (buffer[10] == 0x61) //
Spd1 = buffer[29]; // Скорость авто //
Gaz1 = buffer[22]; // Положение дросельной заслонки //
To1 = buffer[20] - 40; // Температура ОЖ //
obr1 = buffer[23] * 40; // Обороты двигателя //
u1 = 5.2 + buffer[30] * 0.05; // Напряжение бортовой сети //
FuelRateKml = ((buffer[41] << 8) | buffer[40]) / 128.0; // Средний расход топлива на км //
Fuelhoure1 = ((buffer[39] << 8) | buffer[38]) / 50.0; // Средний расход топлива в час //
} //
//------------------------------------------------------------------------------------------------------------------//
//---------показания расхода топлива литров на 100км и скорости если скорость больше 0--------------------------
if (Spd1 > 0)
{
if (Spd1 != Spd)
{
Spd = Spd1;
tft.setCursor(11, 1);
tft.print(char(1));
if (Spd < 100) tft.print (char(1));
if (Spd < 10) tft.print (char(1));
tft.print(Spd);
tft.print("S");
}
if ( FuelRateKm != FuelRateKml)
{
FuelRateKm = FuelRateKml;
tft.setCursor(4, 1);
if (FuelRateKm < 100) tft.print(char(1));
if (FuelRateKm < 10) tft.print(char(1));
tft.print(FuelRateKm, 1);
tft.print(char(3));
tft.print(char(4));
tft.print(char(1));
}
}
//--------------------часы и расход топлива в час если скорость равно 0----------------
if (Spd1 == 0)
{
DateTime now = rtc.now();
tft.setCursor(11, 1);
if (now.hour() < 10) tft.print ("0");
tft.print(now.hour(), DEC);
tft.print(":");
if (now.minute() < 10) tft.print ("0");
tft.print(now.minute(), DEC);
/*
int val = analogRead(A1);
tft.setCursor(11, 1);
if (val < 1000) tft.print(char(1));
if (val < 100) tft.print(char(1));
tft.print(val);
*/
if (Fuelhoure != Fuelhoure1)
{
Fuelhoure = Fuelhoure1;
tft.setCursor(4, 1);
if (Fuelhoure < 100) tft.print(char(1));
if (Fuelhoure < 10) tft.print(char(1));
tft.print(Fuelhoure, 1);
tft.print(char(5));
tft.print(char(1));
}
}
//------------температура салона или положение дросельной заслонки если она больше 0%-----------------------------------
if (Gaz1 == 0)
{
dallas_read();
tft.setCursor(0, 1);
if ((celsius > -10) && (celsius < 100)) tft.print (char(1));
if ((celsius < 10) && (celsius >= 0)) tft.print (char(1));
tft.print(celsius, 0);
tft.print(char(6)); //Символ температуры
tft.print(char(1));
} else if (Gaz1 != Gaz)
{
Gaz = Gaz1;
tft.setCursor(0, 1);
tft.print(char(1));
if (Gaz < 10) tft.print (char(1));
tft.print(Gaz);
tft.print("%");
}
//-----------------------------------показания оборотов-----------------------------------------------------------
if (obr1 != obr)
{
obr = obr1;
tft.setCursor(6, 0);
if (obr < 1000) tft.print(char(1));
if (obr < 100)
{
tft.print(char(1));
tft.print(char(1));
obr = 0;
}
tft.print (obr);
}
//-------------------------------------показания температуры двигателя------------------------------------------------------
if ((To1 != To))
{
To = To1;
tft.setCursor(0, 0);
if ((To > -10) && (To < 100)) tft.print (char(1));
if ((To < 10) && (To >= 0)) tft.print (char(1));
tft.print(To);
tft.print(char(6)); //Символ температуры
tft.print(char(1));
}
//----------------------------------------------показания напряжения------------------------------------------
if (u1 != u)
{
u = u1;
tft.setCursor(11, 0);
if (u < 10) tft.print (char(1));
tft.print(u, 1);
tft.print("V");
}
//-----------------процедура включения вентилятора печки салона----------------------
// salon_fan_on(); //
//-----------------------------------------------------------------------------------
//-----------------процедура автосвета-----------------------------------------------
//auto_and_backlight(); //
//-----------------------------------------------------------------------------------
//----- процедура принудительного включения вентилятора радиатора ------------------
checkcoolfan(); //
//----------------------------------------------------------------------------------
//-------------------------------------опрос кнопок------------------------------------------
bottoms();
// if (bottom == 111) alarm_OIL(); //--Если лампочка масла горит длительное время-------------
if (bottom == 21) time_5sec(); //------------краткое нажатие кнопки вверх-------------------
if (bottom == 32) setupmenu(); //--------длительное нажатие кнопки ввниз---------------------
if (bottom == 31) control_stat(); //-----------краткое нажатие кнопки ввниз------------------
if (bottom == 22) check_errors(); //----------длительное нажатие кнопки вверх----------------
}
////////////////////////////////////////////////END LOOP///////////////////////////////////////
//---------------------показ часов продолжительностью 5 секунд-------------------------------
void time_5sec()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
for (int t_v = 0; t_v < 30; t_v++) //-----продолжительности показа часов при кратком нажатии вверх--------
{
clockRTC();
bott_150ms();
}
initcon();
}
void light_sensor_read()
{
for (int summ = 1; summ <= 10; summ ++)
{
light_sensor_summ = light_sensor_summ + (analogRead(A7));
delay(1);
}
light_sensor = light_sensor_summ / 10;
light_sensor_summ = 0;
}
/*void auto_and_backlight()
{
//-------------показания датчика освещенности и включение света и приглушение подсветки с интервалом 10 сек---------------------
eepromltst = EEPROM.read(eepautolightstat);
//light_sensor = analogRead(A7); //----чтение показания датчика освещенности---------
eepromlton = EEPROM.read(eepautolighton);
eepromltoff = EEPROM.read(eepautolightoff);
eeprombllight = EEPROM.read(eepbacklight);
/*
tft.setCursor(0, 1);
tft.print(eepromltoff);
tft.setCursor(6, 1);
tft.print(light_sensor);
tft.setCursor(11, 1);
tft.print(eepromlton);
tft.setCursor(0, 0);
tft.print(eepromltst);
light_sensor_read();
if (light_sensor > (eepromlton * 4))
{
lt_time = lt_time + 1;
if (lt_time == 25) //-------------задержка времени включения
{
// lt_time = 0;
analogWrite (backlight, eeprombllight); //-----притушить подсветку дисплея согласно переменной
beep();
if (eepromltst == 1 && obr1 > 600) digitalWrite(ON_LIGHT, HIGH); //-----включить свет
}
}
if (light_sensor < (eepromltoff * 4))
{
lt_time = lt_time + 1;
if (lt_time == 25) //-------------задержка времени выключения
{
// lt_time = 0;
beep();
analogWrite (backlight, 150); //----максимальная яркость дисплея
if (eepromltst == 1) digitalWrite(ON_LIGHT, LOW); //----выключить свет
}
}
if ((light_sensor > (eepromltoff * 4)) && (light_sensor < (eepromlton * 4))) lt_time = 0;
if (lt_time > 30000) lt_time = 0;
}
/*void salon_fan_on()
{
//-------- Если температура салона или температура двигателя выше заданных включить печку, ----
//--------------если это разрешено иначе включить печку постоянно---------------------
eepromfan = EEPROM.read(eepheatfanon);
if (eepromfan == 1)
{
eepromf1 = EEPROM.read(eepheatfan1);
eepromf2 = EEPROM.read(eepheatfan2);
val_heat = val_heat + 1;
if (val_heat == 20) val_heat = 1;
if (((celsius >= eepromf1 && celsius < 80) || To >= eepromf2) && val_heat == 1)
{
val_heat = 0;
digitalWrite(FAN_HEAT, LOW);
beep();
}
}
if (eepromfan == 0) digitalWrite (FAN_HEAT, LOW);
}
void alarm_OIL()
{
bottom = 0;
if ( obr1 > 500)
{
int alarm_n = 10; //---продолжительность сигнализации------------
do
{
tft.fillScreen(ST7735_BLACK);
tft.setCursor(2, 0);
tft.print("LOW Pressure");
tft.setCursor(6, 1);
tft.print("OIL");
analogWrite(backlight, 0);
long_beep();
analogWrite(backlight, 255);
delay(500);
alarm_n = alarm_n - 1;
} while (alarm_n != 0);
initcon();
}
}
*/
void long_beep()
{
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
}
void control_stat()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
// int val_light = digitalRead(ON_LIGHT); //----считывание выхода света--------------
tft.setCursor(0, 0);
tft.print("Salon");
tft.setCursor(6, 0);
if (val_heat == 0) tft.print("ON");
if (val_heat != 0) tft.print("OFF");
tft.setCursor(0, 1);
tft.print("Cool");
tft.setCursor(5, 1);
if (val_coolfan_stat == 1) tft.print("ON");
if (val_coolfan_stat == 0) tft.print("OFF");
tft.setCursor(11, 0);
tft.print("Light");
// tft.setCursor(12, 1);
light_sensor_read();
tft.setCursor(11, 1);
if (light_sensor < 1000) tft.print(char(1));
if (light_sensor < 100) tft.print(char(1));
tft.print(light_sensor);
// if (val_light == 1) tft.print("ON");
// if (val_light == 0) tft.print("OFF");
delay(5000); //-----продолжительность показа состояния выходов-------
initcon();
}
//--------------------включение/выключение вентилятора радиатора если разрешено----------------
void checkcoolfan()
{
eepromcool = EEPROM.read(eepcoolfanstat);
if ((eepromcool == 1) && (To1 != Toon))
{
eepromcooloff = EEPROM.read(eepcoolfanoff);
eepromcoolon = EEPROM.read(eepcoolfanon);
Toon = To1;
if (Toon >= eepromcoolon && val_coolfan_stat == 0)
{
val_coolfan_stat = 1;
Serial.write(startcoolfan, 8);
beep();
tft.setCursor(4, 0);
tft.print("*");
// delay(25);
}
if (Toon <= eepromcooloff && val_coolfan_stat == 1)
{
val_coolfan_stat = 0;
Serial.write(stopcoolfan, 7);
beep();
tft.setCursor(4, 0);
tft.print(char(1));
// delay(25);
}
}
}
//-----------------------снятие показаний датчика температуры------------------------------
void dallas_read()
{
byte i;
byte type_s = 0;
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
bott_150ms();
bott_150ms();
return;
}
ds.reset();
ds.select(addr); // Выбираем адрес
//ds.write (0xCC);
ds.write(0x44); // Производим замер
delay(50);
do
{
ds_check = digitalRead(14);
bottoms();
delay(50);
} while (ds_check == 0);
// bott_500ms();
// bott_500ms();
ds.reset();
ds.select(addr);
//ds.write (0xCC);
ds.write(0xBE); // Считываем оперативную память датчика
for ( i = 0; i < 9; i++) {
data[i] = ds.read(); // Заполняем массив считанными данными
}
// Данные о температуре содержатся в первых двух байтах, переведем их в одно значение и преобразуем в шестнадцатиразрядное число
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3;
if (data[7] == 0x10) {
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw & ~7;
else if (cfg == 0x20) raw = raw & ~3;
else if (cfg == 0x40) raw = raw & ~1;
}
celsius = (float)raw / 16.0;
}
void clockRTC()
{
DateTime now = rtc.now();
tft.setCursor(3, 0);
if (now.day() < 10) tft.print ("0");
tft.print(now.day(), DEC);
tft.print(".");
if (now.month() < 10) tft.print ("0");
tft.print(now.month(), DEC);
tft.print(".");
tft.print(now.year(), DEC);
tft.setCursor(4, 1);
if (now.hour() < 10) tft.print ("0");
tft.print(now.hour(), DEC);
tft.print(":");
if (now.minute() < 10) tft.print ("0");
tft.print(now.minute(), DEC);
tft.print(":");
if (now.second() < 10) tft.print ("0");
tft.print(now.second(), DEC);
if (bottom == 32) setupmenu();
}
//--------------------процедура установки связи с ЭБУ-------------------------------------
void initcon()
{
do
{
Serial.write(stopCommunication, 5);
bott_150ms();
Serial.write(startCommunication, 5);
bott_150ms();
readbuf();
if (clockfirst == 1)
{
/*
dallas_read();
tft.setCursor(12, 1);
if ((celsius > -10) && (celsius < 100)) tft.print (char(1));
if ((celsius < 10) && (celsius >= 0)) tft.print (char(1));
tft.print(celsius, 0);
tft.print(char(6)); //Символ температуры
*/
clockRTC();
}
} while (buffer[18] != 0xC1);
beep();
if (clockfirst == 1)
{
delay(500);
clockfirst = 2;
}
Spd = 1;
To = 1;
Gaz = 1;
obr = 1;
u = 1;
FuelRateKm = 1;
Fuelhoure = 1;
lt_time = 0;
// eepromltst = EEPROM.read(eepautolightstat);
// eepromlton = EEPROM.read(eepautolighton) * 4;
// eepromltoff = EEPROM.read(eepautolightoff) * 4;
// eeprombllight = EEPROM.read(eepbacklight);
// eepromfan = EEPROM.read(eepheatfanon);
// eepromf1 = EEPROM.read(eepheatfan1);
// eepromf2 = EEPROM.read(eepheatfan2);
// eepromcool = EEPROM.read(eepcoolfanstat);
// eepromcooloff = EEPROM.read(eepcoolfanoff);
// eepromcoolon = EEPROM.read(eepcoolfanon);
tft.fillScreen(ST7735_BLACK);
}
//----------------процедура чтения данных из буфера последовательного порта------------------
void readbuf()
{
bufSize = 0;
if (Serial.available() > 0)
{
bufSize = Serial.available(); //
for (i = 0; i < bufSize; i++)
buffer[i] = Serial.read();
}
}
// -------------------------процедура проверки на наличие ошибок------------------------------
void check_errors()
{
bottom = 0;
initcon();
Serial.write(readDTCByStatus, 8); // Запрос на прием диагностических данных
delay(200);
readbuf();
if (buffer[11] == 0x58);
{
kol_er = buffer[12];
tft.setCursor(0, 0);
tft.print("Err:");
if (kol_er != 0)
{
bottom = 0;
clockinit = 20;
int p = 10;
int h = 0;
for (i = 0; i < kol_er; i++)
{
p = p + 3;
buffer_errors[h] = buffer[p];
buffer_errors[h + 1] = buffer[p + 1];
h = h + 2;
}
tft.setCursor(4, 0);
tft.print(kol_er);
tft.setCursor(6, 0);
tft.print("P");
if (buffer_errors[0] < 16) tft.print("0");
tft.print(buffer_errors[0], HEX);
tft.print(buffer_errors[1], HEX);
if (kol_er > 1 )
{
tft.setCursor(0, 1);
tft.print("P");
if (buffer_errors[2] < 16) tft.print("0");
tft.print(buffer_errors[2], HEX);
tft.print(buffer_errors[3], HEX);
}
if (kol_er > 2)
{
tft.setCursor(6, 1);
tft.print("P");
if (buffer_errors[4] < 16) tft.print("0");
tft.print(buffer_errors[4], HEX);
tft.print(buffer_errors[5], HEX);
}
do
{ tft.setCursor(12, 0);
tft.print("Igno");
tft.setCursor(12, 1);
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(12, 1);
if (kol_er > 3) tft.print ("Next");
else tft.print(" Del");
tft.setCursor(12, 0);
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
bott_500ms();
if ((bottom == 32) && (kol_er > 3)) next_errors();
if ((bottom == 32) && (kol_er <= 3)) clear_errors();
// if (bottom == 31) clockinit = clockinit + 1;
//if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 20);
bottom = 0;
clockinit = 0;
}
else
{
tft.setCursor(5, 0);
tft.print(kol_er);
delay(2000);
}
}
initcon();
}
//---------------------процедура удаления ошибок--------------------------------
void clear_errors()
{
bottom = 0;
clockinit = 55;
initcon();
Serial.write(clearerrors, 7);
tft.fillScreen(ST7735_BLACK);
tft.setCursor(1, 0);
tft.print("Errors DELETE");
delay(1000);
}
void next_errors()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
if (kol_er > 3 )
{
tft.setCursor(0, 0);
tft.print("P");
if (buffer_errors[6] < 16) tft.print("0");
tft.print(buffer_errors[6], HEX);
tft.print(buffer_errors[7], HEX);
}
if (kol_er > 4 )
{
tft.setCursor(6, 0);
tft.print("P");
if (buffer_errors[8] < 16) tft.print("0");
tft.print(buffer_errors[8], HEX);
tft.print(buffer_errors[9], HEX);
}
if (kol_er > 5 )
{
tft.setCursor(0, 1);
tft.print("P");
if (buffer_errors[10] < 16) tft.print("0");
tft.print(buffer_errors[10], HEX);
tft.print(buffer_errors[11], HEX);
}
if (kol_er > 6 )
{
tft.setCursor(6, 1);
tft.print("P");
if (buffer_errors[12] < 16) tft.print("0");
tft.print(buffer_errors[12], HEX);
tft.print(buffer_errors[13], HEX);
}
do
{ tft.setCursor(12, 0);
tft.print("Igno");
tft.setCursor(12, 1);
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(12, 1);
tft.print(" Del");
tft.setCursor(12, 0);
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
bott_500ms();
if (bottom == 32) clear_errors();
// if (bottom == 31) clockinit = clockinit + 1;
//if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 20);
bottom = 0;
//clockinit = 0;
}
//---------------процедура короткого сигнала----------------------------------------
void beep()
{
digitalWrite(buzz, HIGH);
delay(50);
digitalWrite(buzz, LOW);
}
//-----------------процедура опроса кнопок и тревожного входа низкого давления масла----------
void bottoms()
{
int val = analogRead(A1);
if (val < 250)
{
bottom = 1;
if (bot_long == 1) beep();
if (bot_long == 20) long_beep();
bot_long = bot_long + 1;
}
if (val > 410 && val < 540) // для машины
// if (val > 320 && val < 420) // для программатора
{
bottom = 2;
if (bot_long == 1) beep();
if (bot_long == 20) long_beep();
bot_long = bot_long + 1;
}
if (val > 580 && val < 700) // для машины
// if (val > 430 && val < 530) // для программатора
{
bottom = 3;
if (bot_long == 1) beep();
if (bot_long == 20) long_beep();
bot_long = bot_long + 1;
}
if ((bottom == 1) && (bot_long > 25))
{
bot_long = 0;
bottom == 111;
}
if ((bottom == 1) && (val > 840))
{
if (bot_long < 20)
{
bot_long = 0;
bottom = 11;
}
if (bot_long >= 20)
{
bot_long = 0;
bottom = 12;
}
}
if ((bottom == 2) && (val > 840))
{
if (bot_long < 20)
{
bot_long = 0;
bottom = 21;
}
if (bot_long >= 20)
{
bot_long = 0;
bottom = 22;
}
}
if ((bottom == 3) && (val > 840))
{
if (bot_long < 20)
{
bot_long = 0;
bottom = 31;
}
if (bot_long >= 20)
{
bot_long = 0;
bottom = 32;
}
}
}
//----------------------выбор меню установки----------------------------------
void setupmenu()
{
clockinit = 1;
do
{
//bottoms();
if (clockinit == 1) setclock();
if (clockinit == 2) setdate();
/*if (clockinit == 3) autolight_on();
if (clockinit == 4) autolight_level();
*/
if (clockinit == 3) coolfan_on();
if (clockinit == 4) coolfan_engine();
/*
if (clockinit == 7) heatfan_on();
if (clockinit == 8) heatfan_level();
*/
if (clockinit == 5) backlight_level();
// if (clockinit == 10) beep_on();
if (bottom == 22) clockinit = 55;
if ((clockinit < 1) && (clockinit != 55)) clockinit = 9;
if ((clockinit > 9) && (clockinit != 55)) clockinit = 1;
bott_150ms();
} while (clockinit < 50);
initcon();
}
//-------------------меню установки часов-----------------------------------------
void setclock()
{
read_datetime();
bottom = 0;
tft.fillScreen(ST7735_BLACK);
do
{
tft.setCursor(0, 0);
tft.print ("Set Clock");
tft.setCursor (2, 1);
if (hourtime < 10) tft.print (char(1));
tft.print(hourtime, DEC);
tft.print(":");
if (minutetime < 10) tft.print ("0");
tft.print(minutetime, DEC);
bott_150ms();
if (bottom == 32) setclockon();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 1);
bottom = 0;
// tft.fillScreen(ST7735_BLACK);
// DateTime now = rtc.now();
}
//--------------------установка часов времени-----------------------------------------
void setclockon()
{
bottom = 0;
clockinit = 1;
do
{
tft.setCursor(2, 1);
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(2, 1);
if (hourtime < 10) tft.print("0");
tft.print(hourtime);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
hourtime = hourtime + 1;
if (hourtime > 24) hourtime = 0;
}
if (bottom == 21)
{
bottom = 0;
hourtime = hourtime - 1;
if (hourtime < 0) hourtime = 23;
}
if (bottom == 32) setminuteon();;
if (bottom == 22) clockinit = 55;
} while (clockinit < 50);
bottom = 0;
rtc.adjust(DateTime(yeartime, monthtime, daytime, hourtime, minutetime, 0));
clockinit = 1;
}
//---------------------установка минут времени-------------------------------------
void setminuteon()
{
bottom = 0;
clockinit = 1;
do
{
tft.setCursor(5, 1);
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(5, 1);
if (minutetime < 10) tft.print("0");
tft.print(minutetime);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
minutetime = minutetime + 1;
if (minutetime > 59) minutetime = 0;
}
if (bottom == 21)
{
bottom = 0;
minutetime = minutetime - 1;
if (minutetime < 0) minutetime = 59;
}
if ((bottom == 32) || (bottom == 22)) clockinit = 55;
} while (clockinit < 50);
bottom = 0;
}
//--------------------меню установки числа, месяца, года------------------------------
void setdate()
{
read_datetime();
bottom = 0;
tft.fillScreen(ST7735_BLACK);
do
{
tft.setCursor(0, 0);
tft.print ("Set Date");
tft.setCursor (2, 1);
if (daytime < 10) tft.print ("0");
tft.print(daytime, DEC);
tft.print(".");
if (monthtime < 10) tft.print ("0");
tft.print(monthtime, DEC);
tft.print(".");
tft.print(yeartime, DEC);
bott_150ms();
if (bottom == 32) setdateon();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 2);
bottom = 0;
// tft.fillScreen(ST7735_BLACK);
}
//----------------установка даты дня---------------------------------------------
void setdateon()
{
bottom = 0;
do
{
tft.setCursor(2, 1);
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(2, 1);
if (daytime < 10) tft.print("0");
tft.print(daytime);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
daytime = daytime + 1;
if (daytime > 31) daytime = 1;
}
if (bottom == 21)
{
bottom = 0;
daytime = daytime - 1;
if (daytime < 1)daytime = 31;
}
if (bottom == 32) setmonthon();
if (bottom == 22) clockinit = 55;
} while (clockinit < 50);
bottom = 0;
DateTime now = rtc.now();
hourtime = now.hour();
minutetime = now.minute();
secondtime = now.second();
rtc.adjust(DateTime(yeartime, monthtime, daytime, hourtime, minutetime, 0));
clockinit = 2;
}
//-----------------------установка месяца------------------------------
void setmonthon()
{
bottom = 0;
do
{
tft.setCursor(5, 1);
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(5, 1);
if (monthtime < 10) tft.print ("0");
tft.print(monthtime);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
monthtime = monthtime + 1;
if (monthtime > 12) monthtime = 1;
}
if (bottom == 21)
{
bottom = 0;
monthtime = monthtime - 1;
if (monthtime < 1) monthtime = 12;
}
if (bottom == 32) setyearon();
if (bottom == 22) clockinit = 55;
} while (clockinit < 50);
bottom = 0;
//clockinit = 2;
}
//----------------------установка года------------------
void setyearon()
{
bottom = 0;
do
{
tft.setCursor(8, 1);
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(8, 1);
tft.print(yeartime);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
yeartime = yeartime + 1;
}
if (bottom == 21)
{
bottom = 0;
yeartime = yeartime - 1;
if (yeartime < 2000) yeartime = 2000;
}
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
} while (clockinit < 50);
bottom = 0;
}
//-------------------------меню установки функции включения автосвет-------------------
/*void autolight_on()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.print ("Autolight");
tft.setCursor (13, 0);
tft.print("ON");
tft.setCursor(13, 1);
tft.print("OFF");
eepromi = EEPROM.read(eepautolightstat);
do
{
if (eepromi == 1)
{
tft.setCursor(12, 1);
tft.print(char(1));
tft.setCursor(12, 0);
tft.print(">");
}
if (eepromi == 0)
{
tft.setCursor(12, 0);
tft.print(char(1));
tft.setCursor(12, 1);
tft.print(">");
}
bott_500ms();
if (bottom == 32) set_autolight_stat();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 3);
bottom = 0;
if (eepromi == 0) digitalWrite(ON_LIGHT, LOW);
EEPROM.write(eepautolightstat, eepromi);
}
//------------------------установка включения функции автосвет--------------------
void set_autolight_stat()
{
bottom = 0;
do
{
tft.setCursor(12, 0);
tft.print(char(1));
tft.setCursor(12, 1);
tft.print(char(1));
bott_500ms();
if (eepromi == 1)
{
tft.setCursor(12, 0);
tft.print(">");
}
if (eepromi == 0)
{
tft.setCursor(12, 1);
tft.print(">");
}
bott_500ms();
if (bottom == 31) eepromi = 0;
if (bottom == 21) eepromi = 1;
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
} while (clockinit == 3);
bottom = 0;
clockinit = 3;
}
//----------------------------меню установки порога автосвет--------------------------------
void autolight_level()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.print ("Autolight LEVEL");
eeprom1 = EEPROM.read(eepautolightoff);
eeprom2 = EEPROM.read(eepautolighton);
tft.setCursor(0, 1);
if ((eeprom1 * 4) < 1000) tft.print (char(1));
if ((eeprom1 * 4) < 100) tft.print (char(1));
tft.print(eeprom1 * 4);
tft.setCursor(12, 1);
if ((eeprom2 * 4) < 1000) tft.print(char(1));
if ((eeprom2 * 4) < 100) tft.print(char(1));
tft.print(eeprom2 * 4);
do
{
//light_sensor = analogRead(A7);
light_sensor_read();
tft.setCursor(6, 1);
if (light_sensor < 1000) tft.print(char(1));
if (light_sensor < 100) tft.print(char(1));
tft.print(light_sensor);
bott_500ms();
if (bottom == 32) set_autolight_off();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 4);
bottom = 0;
EEPROM.write(eepautolightoff, eeprom1);
EEPROM.write(eepautolighton, eeprom2);
}
//--------------Установка порога выключения света----------------
void set_autolight_off()
{
bottom = 0;
do
{
//light_sensor = analogRead(A7);
light_sensor_read();
tft.setCursor(6, 1);
if (light_sensor < 1000) tft.print(char(1));
if (light_sensor < 100) tft.print(char(1));
tft.print(light_sensor);
// tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 1);
tft.print(char(1));
tft.setCursor(1, 1);
tft.print(char(1));
tft.setCursor(2, 1);
tft.print(char(1));
tft.setCursor(3, 1);
tft.print(char(1));
bott_500ms();
tft.setCursor(0, 1);
if ((eeprom1 * 4) < 1000) tft.print (char(1));
if ((eeprom1 * 4) < 100) tft.print (char(1));
tft.print(eeprom1 * 4);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
eeprom1 = eeprom1 + 5;
if (eeprom1 >= 250) eeprom1 = 250;
}
if (bottom == 21)
{
bottom = 0;
eeprom1 = eeprom1 - 5;
if (eeprom1 <= 5) eeprom1 = 5;
}
if (bottom == 32) set_autolight_on();
if (bottom == 22) clockinit = 55;
} while (clockinit == 4);
bottom = 0;
clockinit = 4;
}
void set_autolight_on()
{
bottom = 0;
if (eeprom1 >= eeprom2) eeprom2 = eeprom1 + 10;
do
{
//light_sensor = analogRead(A7);
light_sensor_read();
tft.setCursor(6, 1);
if (light_sensor < 1000) tft.print(char(1));
tft.print(light_sensor);
// tft.fillScreen(ST7735_BLACK);
tft.setCursor(12, 1);
tft.print(char(1));
tft.setCursor(13, 1);
tft.print(char(1));
tft.setCursor(14, 1);
tft.print(char(1));
tft.setCursor(15, 1);
tft.print(char(1));
bott_500ms();
tft.setCursor(12, 1);
if ((eeprom2 * 4) < 1000) tft.print(char(1));
if ((eeprom2 * 4) < 100) tft.print(char(1));
tft.print(eeprom2 * 4);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
eeprom2 = eeprom2 + 5;
if (eeprom2 >= 250) eeprom2 = 250;
}
if (bottom == 21)
{
bottom = 0;
eeprom2 = eeprom2 - 5;
if (eeprom2 <= 5) eeprom2 = 5;
if (eeprom1 >= eeprom2) eeprom2 = eeprom1 + 5;
}
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
} while (clockinit == 4);
bottom = 0;
}
*/
//-----------меню установки вентилятора радиатора-----------------------
void coolfan_on()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.print("Radiator");
tft.setCursor(2, 1);
tft.print("FAN");
tft.setCursor(13, 0);
tft.print("ON");
// tft.setCursor(15,0)
// tft.print(char(6));
tft.setCursor(13, 1);
tft.print("OFF");
// tft.setCursor(15,1);
// tft.print(char(6));
eepromi = EEPROM.read(eepcoolfanstat);
do
{
if (eepromi == 1)
{
tft.setCursor(12, 1);
tft.print(char(1));
tft.setCursor(12, 0);
tft.print(">");
}
if (eepromi == 0)
{
tft.setCursor(12, 0);
tft.print(char(1));
tft.setCursor(12, 1);
tft.print(">");
}
bott_500ms();
if (bottom == 32) set_coolfan_stat();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 5);
bottom = 0;
EEPROM.write(eepcoolfanstat, eepromi);
}
//-------------------Установка принудительного включения вентилятора радиатора ON OFF---------
void set_coolfan_stat()
{
bottom = 0;
do
{
tft.setCursor(12, 0);
tft.print(char(1));
tft.setCursor(12, 1);
tft.print(char(1));
bott_500ms();
if (eepromi == 1)
{
tft.setCursor(12, 0);
tft.print(">");
}
if (eepromi == 0)
{
tft.setCursor(12, 1);
tft.print(">");
}
bott_500ms();
if (bottom == 31) eepromi = 0;
if (bottom == 21) eepromi = 1;
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
} while (clockinit == 5);
bottom = 0;
clockinit = 5;
}
//--------------------меню установки порогов включения и выключения вентилятора радиатора--------
void coolfan_engine()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.print("Radiator");
tft.setCursor(2, 1);
tft.print("FAN");
tft.setCursor(9, 0);
tft.print("OFF");
tft.setCursor(15, 0);
tft.print(char(6));
tft.setCursor(10, 1);
tft.print("ON");
tft.setCursor(15, 1);
tft.print(char(6));
eeprom1 = EEPROM.read(eepcoolfanoff);
eeprom2 = EEPROM.read(eepcoolfanon);
tft.setCursor(13, 0);
tft.print(eeprom1);
tft.setCursor(12, 1);
if (eeprom2 < 100) tft.print(char(1));
tft.print(eeprom2);
do {
bott_150ms();
if (bottom == 32) coolfan_engine_off();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 6);
bottom = 0;
EEPROM.write(eepcoolfanoff, eeprom1);
EEPROM.write(eepcoolfanon, eeprom2);
}
//-----------------------------------------------------------------------------
void coolfan_engine_off()
{
bottom = 0;
do
{
tft.setCursor(13, 0);
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(13, 0);
tft.print(eeprom1);
bott_500ms();
if (bottom == 32) coolfan_engine_on();
if (bottom == 31)
{
bottom = 0;
eeprom1 = eeprom1 + 1;
if (eeprom1 > 99) eeprom1 = 99;
}
if (bottom == 21)
{
bottom = 0;
eeprom1 = eeprom1 - 1;
if (eeprom1 < 70) eeprom1 = 70;
}
if (bottom == 22) clockinit = 55;
} while (clockinit == 6);
bottom = 0;
clockinit = 6;
}
//------------------------------------------------------------------------------
void coolfan_engine_on()
{
bottom = 0;
if ((eeprom1 + 1) >= eeprom2) eeprom2 = eeprom1 + 1;
do
{
tft.setCursor(12, 1);
tft.print(char(1));
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(12, 1);
if (eeprom2 < 100) tft.print(char(1));
tft.print(eeprom2);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
eeprom2 = eeprom2 + 1;
if (eeprom2 > 105) eeprom2 = 105;
}
if (bottom == 21)
{
bottom = 0;
eeprom2 = eeprom2 - 1;
if (eeprom2 < 75) eeprom2 = 75;
if ((eeprom1 + 1) >= eeprom2) eeprom2 = eeprom1 + 1;
}
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
} while (clockinit == 6);
bottom = 0;
}
/*void heatfan_on()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.print("Salon");
tft.setCursor(1, 1);
tft.print("FAN");
tft.setCursor (13, 0);
tft.print("ON");
tft.setCursor(13, 1);
tft.print("OFF");
eepromi = EEPROM.read(eepheatfanon);
do
{
if (eepromi == 1)
{
tft.setCursor(12, 1);
tft.print(char(1));
tft.setCursor(12, 0);
tft.print(">");
}
if (eepromi == 0)
{
tft.setCursor(12, 0);
tft.print(char(1));
tft.setCursor(12, 1);
tft.print(">");
}
bott_150ms();
if (bottom == 32) set_heatfan_on();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 7);
bottom = 0;
EEPROM.write(eepheatfanon, eepromi);
}
void set_heatfan_on()
{
bottom = 0;
do
{
tft.setCursor(12, 0);
tft.print(char(1));
tft.setCursor(12, 1);
tft.print(char(1));
bott_500ms();
if (eepromi == 1)
{
tft.setCursor(12, 0);
tft.print(">");
}
if (eepromi == 0)
{
tft.setCursor(12, 1);
tft.print(">");
}
bott_500ms();
if (bottom == 31) eepromi = 0;
if (bottom == 21) eepromi = 1;
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
} while (clockinit == 7);
bottom = 0;
clockinit = 7;
}
void heatfan_level()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.print("Salon");
tft.setCursor(1, 1);
tft.print("FAN");
tft.setCursor(9, 0);
tft.print("Car");
tft.setCursor(15, 0);
tft.print(char(6));
tft.setCursor(6, 1);
tft.print("Engine");
tft.setCursor(15, 1);
tft.print(char(6));
eeprom1 = EEPROM.read(eepheatfan1);
eeprom2 = EEPROM.read(eepheatfan2);
tft.setCursor(13, 0);
if (eeprom1 < 10) tft.print(char(1));
tft.print(eeprom1);
tft.setCursor(13, 1);
tft.print(eeprom2);
do {
bott_150ms();
if (bottom == 32) heatfan_level_01();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 8);
bottom = 0;
EEPROM.write(eepheatfan1, eeprom1);
EEPROM.write(eepheatfan2, eeprom2);
}
void heatfan_level_01()
{
bottom = 0;
do
{
tft.setCursor(13, 0);
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(13, 0);
if (eeprom1 < 10) tft.print(char(1));
tft.print(eeprom1);
bott_500ms();
if (bottom == 32) heatfan_level_02();
if (bottom == 31)
{
bottom = 0;
eeprom1 = eeprom1 + 1;
if (eeprom1 > 35) eeprom1 = 35;
}
if (bottom == 21)
{
bottom = 0;
eeprom1 = eeprom1 - 1;
if (eeprom1 < 0) eeprom1 = 0;
}
if (bottom == 22) clockinit = 55;
} while (clockinit == 8);
bottom = 0;
clockinit = 8;
}
void heatfan_level_02()
{
bottom = 0;
do
{
tft.setCursor(13, 1);
tft.print(char(1));
tft.print(char(1));
bott_500ms();
tft.setCursor(13, 1);
tft.print(eeprom2);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
eeprom2 = eeprom2 + 1;
if (eeprom2 > 90) eeprom2 = 90;
}
if (bottom == 21)
{
bottom = 0;
eeprom2 = eeprom2 - 1;
if (eeprom2 < 10) eeprom2 = 10;
}
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
} while (clockinit == 8);
bottom = 0;
}
*/
void backlight_level()
{
bottom = 0;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 0);
tft.print ("Backlight LCD");
tft.setCursor(9, 1);
tft.print("%");
eepromi = EEPROM.read(eepbacklight);
tft.setCursor(5, 1);
if (eepromi < 100) tft.print(char(1));
if (eepromi < 10) tft.print(char(1));
tft.print(eepromi);
do
{
bott_150ms();
if (bottom == 32) set_backlight_level();
if (bottom == 31) clockinit = clockinit + 1;
if (bottom == 21) clockinit = clockinit - 1;
if (bottom == 22) clockinit = 55;
} while (clockinit == 9);
bottom = 0;
EEPROM.write(eepbacklight, eepromi);
}
void set_backlight_level()
{
bottom = 0;
do
{
// tft.fillScreen(ST7735_BLACK);
tft.setCursor(5, 1);
tft.print(char(1));
tft.setCursor(6, 1);
tft.print(char(1));
tft.setCursor(7, 1);
tft.print(char(1));
bott_500ms();
tft.setCursor(5, 1);
if (eepromi < 100) tft.print(char(1));
if (eepromi < 10) tft.print(char(1));
tft.print(eepromi);
bott_500ms();
if (bottom == 31)
{
bottom = 0;
eepromi = eepromi + 5;
if (eepromi > 100) eepromi = 100;
}
if (bottom == 21)
{
bottom = 0;
eepromi = eepromi - 5;
if (eepromi <= 5) eepromi = 5;
}
if ((bottom == 22) || (bottom == 32)) clockinit = 55;
analogWrite (backlight, eepromi);
} while (clockinit == 9);
bottom = 0;
clockinit = 9;
}
//-------------одноразовая запись исходных данных по умолчанию в EEPROM если он пуст------------
void eeprominit()
{
/* eepromi = EEPROM.read(eepautolightstat);
if ((eepromi == 0xFF)) EEPROM.write(eepautolightstat, 1);
eepromi = EEPROM.read(eepautolightoff);
if (eepromi == 0xFF) EEPROM.write(eepautolightoff, 150);
eepromi = EEPROM.read(eepautolighton);
if (eepromi == 0xFF) EEPROM.write(eepautolighton, 200);
*/
eepromi = EEPROM.read(eepcoolfanstat);
if ((eepromi == 0xFF)) EEPROM.write(eepcoolfanstat, 1);
eepromi = EEPROM.read(eepcoolfanoff);
if (eepromi == 0xFF) EEPROM.write(eepcoolfanoff, 93);
eepromi = EEPROM.read(eepcoolfanon);
if (eepromi == 0xFF) EEPROM.write(eepcoolfanon, 97);
/* eepromi = EEPROM.read(eepheatfanon);
if ((eepromi == 0xFF)) EEPROM.write(eepheatfanon, 1);
eepromi = EEPROM.read(eepheatfan1);
if (eepromi == 0xFF) EEPROM.write(eepheatfan1, 25);
eepromi = EEPROM.read(eepheatfan2);
if (eepromi == 0xFF) EEPROM.write(eepheatfan2, 70);
*/
eepromi = EEPROM.read(eepbacklight);
if (eepromi == 0xFF) EEPROM.write(eepbacklight, 10);
}
void read_datetime()
{
DateTime now = rtc.now();
yeartime = now.year();
monthtime = now.month();
daytime = now.day();
hourtime = now.hour();
minutetime = now.minute();
secondtime = now.second();
}
void bott_150ms()
{
bottoms();
delay(50);
bottoms();
delay(50);
bottoms();
delay(50);
}
void bott_500ms()
{
for ( int ms = 0; ms < 8; ms++)
{
bottoms();
delay(50);
}
}