#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //настройrи дисплея
#include <OneWire.h> //
#include <DallasTemperature.h>//
#include <Wire.h>
#include <iarduino_RTC.h> //часы реальног времени
//#include <ServoSmooth.h>
//#define AMOUNT 0 // кол-во серво
//#define AMOUNTONE 1
//ServoSmooth servos[AMOUNT];
//uint32_t servoTimer;
//uint32_t turnTimer;
//int servo_position1 = 0; // первое положение серв
#include <Servo.h>
//Servo myservo[AMOUNT]; // создаем объект Servo для управления первой сервой
Servo myservo0; // создаем объект Servo для управления второй сервой
Servo myservo1;
boolean flag;
// Data wire is plugged into port 12 on the Arduino
#define ONE_WIRE_BUS 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
#define BTN_UP 1
#define BTN_DOWN 2
#define BTN_LEFT 3
#define BTN_RIGHT 4
#define BTN_SELECT 5
#define BTN_NONE 10
int sensorValue = 0, valve = 0;
int valve_mission = 50;
float t_mission = 28.00;
int min_lvl = 18;
int ten = 0;
int naliv = 0;
//int selct_on = 0;
int submenu_on = 0;
int menu_n = 0;
uint32_t ms_next;
int watering_frequency = 1;
int int_start_h = 10;
int int_start_m = 00;
int dayx;
int poliv_on = 0;
int poliv = 0;
int poliv_pause = 0;
int duration_h = 0;
int duration_m = 1;
int watering_head = 30;
char* watering_modes[] = {"Het poliva", "Po raspisaniy", "Po datchky", "Ymnuy" };
int current_mode = 0;
char* on_off[] = {"On", "Off"}; // для включения контроля лампочки
int watering_by_time = 1; //можно сделать bool
int watering_by_sensor = 0; //bool
int humidity_on;
int humidity_off;
int bool_humidity_on = 0;
int bool_humidity_off = 0;
float off_save_time_h;
float off_save_time_m;
int all_time_hm_past = 0;
int all_time_hm_pause = 0;
int save_time_h;
int save_time_m;
int all_time_hm;
unsigned long time_pause = 0;
unsigned long time_past = 0;
iarduino_RTC time(RTC_DS1307);
//iarduino_RTC clockk(RTC_DS1307);
//Servo shower;
//Servo watering;
int p0 = 90;
int p1 = 90;
int p = 90;
int p0_old = 90;
int p1_old = 90;
int p_old = 90;
int pump = 0;
//int select_on = 0;
// переменная для хранения времени в формате unixtime
//long unixTime;
int ledState = 1;
unsigned long previousMillis = 0;
int detectButton() {
int keyAnalog = analogRead(A7);
if (keyAnalog < 100) {
// Значение меньше 100 – нажата кнопка right
return BTN_RIGHT;
} else if (keyAnalog < 200) {
// Значение больше 100 (иначе мы бы вошли в предыдущий блок результата сравнения, но меньше 200 – нажата кнопка UP
return BTN_UP;
} else if (keyAnalog < 400) {
// Значение больше 200, но меньше 400 – нажата кнопка DOWN
return BTN_DOWN;
} else if (keyAnalog < 600) {
// Значение больше 400, но меньше 600 – нажата кнопка LEFT
return BTN_LEFT;
} else if (keyAnalog < 800) {
// Значение больше 600, но меньше 800 – нажата кнопка SELECT
return BTN_SELECT;
} else {
// Все остальные значения (до 1023) будут означать, что нажатий не было
return BTN_NONE;
}
}
void setup() {
Serial.begin(9600);
pinMode(10, OUTPUT); //насос //14
pinMode(11, OUTPUT); //тэн //15
digitalWrite(10, LOW);
digitalWrite(11, LOW);
lcd.begin(16, 2); //иницмальзация матрицы дисплея
time.begin();// // Инициируем RTC модуль (часы реального времени)
time.settime(0, 00, 10, 12, 4, 19, 2);
sensors.begin();
pinMode(13, OUTPUT);
}
void loop() {
servo(0);
sensorValue = analogRead(A6);
valve = map(sensorValue, 20, 985, 0, 100);
sensors.requestTemperatures();// Отправляет команду, чтобы получить температуру
//НАСОС
if (naliv != 0 ) {
if ( valve >= valve_mission) {
naliv = 0;
lcd.setCursor(0, 1);
lcd.print("naliv zavershon ");
delay(1000);
lcd.clear();
}
else {
digitalWrite(10, HIGH);
p0 = 0;
}
}
else {
digitalWrite(10, LOW);
//тут закрыить и подождать// тут мотор будет тыркаться?
p0 = 90;
}
//delay(500);
//ТЕН
if (ten != 0) {
if (valve <= min_lvl) {
ten = 0; lcd.setCursor(0, 1); lcd.print("nizkoe davlenie");
delay(1000); lcd.clear();
}
if (ten == 1 or ten == 3) {
digitalWrite(11, HIGH);
if (ten == 3)
{
//lcd.print("podogrev");
//lcd.setCursor(13, 1); lcd.print("/T/");
}
else
{
//lcd.print("first ten");
//lcd.setCursor(13, 1); lcd.print("/T|");
}
//первый нагрев
if (sensors.getTempCByIndex(0) >= t_mission) {
if (ten == 1) {
lcd.setCursor(0, 1); lcd.print(" Dysh nagret ");
delay(1000); lcd.clear();
}
ten = 2;
}
}
else {
digitalWrite(11, LOW);
//lcd.print("nagret ");
///lcd.setCursor(13, 1);lcd.print("|T|");
if (sensors.getTempCByIndex(0) <= (t_mission - 0.90) and valve > min_lvl) {
ten = 3;
}
//26<=28
}
}
else {
ten = 0;
digitalWrite(11, LOW);
}
//начало полива
{
{
dayx = time.day; //+ watering_frequency;//расчет второго полива
}
///проверка дняX, часов и минут и ожидание душа
all_time_hm = (int_start_h * 60 + int_start_m) + (duration_h * 60 + duration_m) + all_time_hm_pause;
off_save_time_h = all_time_hm / 60;
off_save_time_m = all_time_hm % 60;
if (dayx == time.day && int_start_h == time.Hours && int_start_m == time.minutes) {
poliv_on = 1;
}
if (poliv_on == 1)
{
/* if (off_save_time_h == time.Hours and off_save_time_m == time.minutes) {
poliv = 0;
poliv_on = 0;
}*/
if (poliv == 2) { //джем заполнения бака
p1 = 90;
//if(time.seconds% 1 == 59){all_time_hm_pause++;}
//if (time.minutes- time_pause>=1)
//
//all_time_hm_pause++;
//if (millis() % 59000 == 0)
if (millis() - time_pause >= 59000)
{
all_time_hm_pause++;
time_pause = millis();
}
if (naliv == 0 )
{
poliv = 3; //переход в полив
}
}
if (poliv != 2 and naliv == 1) { //проверка доступности насоса
lcd.setCursor(0, 0);
lcd.print("Poliv bydet ");
lcd.setCursor(0, 1);
lcd.print("posle naliva ");
delay(2000); lcd.clear();
poliv = 2; //ожидание душа
}
else {
if (naliv == 0 )///по идее это условие ничего не проверяет
{
poliv = 3; //полив не мешает наливу и будет начат прямо сейчас
}
}
if (poliv == 3) {
//all_time_hm_past = (time.Hours * 60 + time.minutes)-all_time_hm;
///регулируется напора полива
p1 = watering_head;
digitalWrite(10, HIGH);
/*Serial.print(time.Hours);
Serial.print(":");
Serial.println(time.minutes);
Serial.println(all_time_hm);
Serial.print(off_save_time_h);
Serial.print(":");
Serial.println(off_save_time_m);*/
if (off_save_time_h == time.Hours and off_save_time_m == time.minutes) {
poliv = 4;// полив завешен или приостановлен по причине налива
}
}
if (poliv == 4)
{
p1 = 90;
digitalWrite(10, LOW); poliv = 0; //p1 = 0;
if (poliv_pause = 1) { //111
dayx = 0;
//рачет времени
} else {
dayx = time.day;;
}
lcd.setCursor(0, 1);
lcd.print("VIPOLNEN"); delay(1000); lcd.clear();
all_time_hm_pause=0;
poliv_on=0;
//poliv =0;
}
}
else {poliv = 0;}
}
//if (millis() % 1000 == 0)
{
/* Serial.print(save_time_h);
Serial.print(":");
Serial.println(save_time_m);
*/ Serial.println(all_time_hm);
Serial.print((int)off_save_time_h);
Serial.print(":");
Serial.println((int)off_save_time_m);
Serial.print(all_time_hm_pause);
Serial.println("pause");
Serial.print(all_time_hm_past);
Serial.println("past");
/* Serial.println("past");
Serial.print(poliv_on);
Serial.println("pause");
Serial.print(poliv);
Serial.println("past");*/
}
//конец полива
switch (menu_n) {
case 0: menu0(); break;
case 1: menu1(); break;
case 2: menu2(); break;
case 3: menu3(); break;
case 4: menu4(); break;
case 14: menu14(); break;
case 24: menu24(); break;
case 34: menu34(); break;
case 44: menu44(); break;
case 5: menu5(); break;
case 15: menu15(); break;
case 25: menu25(); break;
case 35: menu35(); break;
case 45: menu45(); break;
case 55: menu55(); break;
case 6: menu6(); break;
case 7: menu7(); break;
case 8: menu8(); break;
case 18: menu18(); break;
case 9: menu9(); break;
case 19: menu19(); break;
//case 555: menu555(); break;
}
next_menu(BTN_SELECT, 1, 1);
next_menu(BTN_LEFT, -1, 1);
//Serial.println(poliv);
}
void menu0() {
int button = detectButton();
//вывод времени
lcd.setCursor(11, 0);
lcd.print(time.gettime("H:i"));
//вывод темпетатуры
lcd.setCursor(0, 0); //постановка курсора // (номер ряда,номер строки) начало с (0, 0)
lcd.print(sensors.getTempCByIndex(0));
//вывод процента наполнения бака
lcd.setCursor(7, 0);
lcd.print(" ");
lcd.setCursor(7, 0);
lcd.print(valve);
//насос
if (button == BTN_UP) {
if (naliv == 0 ) //111
{
{
//тут открыть и подождать
naliv = 1;
//lcd.setCursor(13, 1);
//lcd.print("/H/");
if (poliv_pause == 1) {
/*продолжить полив */
}
delay(300);
}
}
else {
//тут закрыить и подождать
naliv = 0;
//lcd.setCursor(13, 1);
//lcd.print(" ");
delay(300);
if (poliv_pause == 1) {
/*продолжить полив */
}
}
}
//тен
if (button == BTN_DOWN) {
if (ten == 0) {
if (sensors.getTempCByIndex(0) >= t_mission ) {
//111//проверка температуры попробовать убрать
ten = 2;
}
else {
ten = 1;
delay(300);
}
}
else {
ten = 0;
digitalWrite(11, LOW);
delay(300);
}
}
if ( ten != 0 ) {
if (ten == 1) {
ten = 1;
lcd.setCursor(9, 1);
lcd.print("/C|");
}
if (ten == 2) {
ten = 2;
lcd.setCursor(9, 1);
lcd.print("|C|");
}
if (ten == 3) {
ten = 3;
lcd.setCursor(9, 1);
lcd.print("/C/");
}
}
else {
lcd.setCursor(9, 1);
lcd.print(" ");
}
if (naliv == 0 and poliv != 3)
{
lcd.setCursor(13, 1);
lcd.print(" ");
}
if (naliv == 1)
{
lcd.setCursor(13, 1);
lcd.print("/H/");
}
if (poliv == 3)
{
lcd.setCursor(13, 1);
lcd.print("[P]");
}
//полив по кнопке
if(button == BTN_RIGHT){
if(poliv_on==1) {poliv=4;}
else {poliv_on=1;}
}
lcd.setCursor(0, 1);
lcd.print("C");
lcd.setCursor(7, 1);
lcd.print("%");
///next_menu(BTN_LEFT, 0, 1);
}
void menu1() {
lcd.setCursor(0, 0); //постановка курсора // (номер ряда,номер строки) начало с (0, 0)
lcd.print("Uroven naliva");
lcd.setCursor(0, 1);
lcd.print("vody:");
lcd.setCursor(15, 1);
lcd.print("%");
blinking(valve_mission , 12, 1, 0);
valve_mission = change_variable2(valve_mission, 1,
9, 1, 5, 2,
0, 70);
}
void menu2() {
//int button = detectButton();
lcd.setCursor(0, 0);
lcd.print("Temperatura ");
lcd.setCursor(0, 1);
lcd.print("nagreva:");
blinking(t_mission , 9, 1, 2);
t_mission = change_variable2(t_mission, 0.25,
9, 1, 5, 2,
0, 70);
lcd.setCursor(15, 1);
lcd.print("%");
}
void menu3() {
time.blinktime(0);
//int button = detectButton();
lcd.setCursor(0, 0);
lcd.print("Min uroven naliv");
lcd.setCursor(0, 1);
lcd.print("a vody:");
blinking(min_lvl , 12, 1, 0);
min_lvl = change_variable2(min_lvl, 1,
12, 1, 3, 0,
0, 100);
lcd.setCursor(15, 1);
lcd.print("%");
// min_lvl = change_variable(BTN_UP, min_lvl, 1);
//min_lvl = change_variable(BTN_DOWN, min_lvl, -1);
}
void menu4() {
time.blinktime(3, 2);
lcd.setCursor(0, 0);
lcd.print("Vremya: ");
lcd.print(time.gettime("H:i"));
lcd.setCursor(0, 1);
lcd.print("Data: ");
lcd.print(time.gettime("d.m.Y"));
time.settime(-1, -1, change_variable2(time.Hours, 1,
0, 0, 0, 0,
0, 23));
next_menu(BTN_RIGHT, 10, 0);
}
void menu14() {
time.blinktime(2, 2);
lcd.setCursor(0, 0);
lcd.print("Vremya: ");
lcd.print(time.gettime("H:i"));
lcd.setCursor(0, 1);
lcd.print("Data: ");
lcd.print(time.gettime("d.m.Y"));
time.settime(-1, change_variable2(time.minutes, 1,
0, 0, 0, 0,
0, 59));
next_menu(BTN_RIGHT, 10, 0);
}
void menu24() {
time.blinktime(4, 2);
lcd.setCursor(0, 0);
lcd.print("Vremya: ");
lcd.print(time.gettime("H:i"));
lcd.setCursor(0, 1);
lcd.print("Data: ");
lcd.print(time.gettime("d.m.Y"));
time.settime(-1, -1, -1, change_variable2(time.day, 1,
0, 0, 0, 0,
1, 31));
next_menu(BTN_RIGHT, 10, 0);
}
void menu34() {
time.blinktime(5, 2);
lcd.setCursor(0, 0);
lcd.print("Vremya: ");
lcd.print(time.gettime("H:i"));
lcd.setCursor(0, 1);
lcd.print("Data: ");
lcd.print(time.gettime("d.m.Y"));
time.settime(-1, -1, -1, -1, change_variable2( time.month, 1,
0, 0, 0, 0,
1, 12));
next_menu(BTN_RIGHT, 10, 0);
}
void menu44() {
time.blinktime(6, 4);
lcd.setCursor(0, 0);
lcd.print("Vremya: ");
lcd.print(time.gettime("H:i"));
lcd.setCursor(0, 1);
lcd.print("Data: ");
lcd.print(time.gettime("d.m.Y"));
time.settime(-1, -1, -1, -1, -1, change_variable2(time.year, 1,
0, 0, 0, 0,
0, 3000));
next_menu(BTN_RIGHT, -40, 0);
}
void menu6() {
lcd.setCursor(0, 0);
lcd.print("Rejum poliva: ");
current_mode = change_variable2(current_mode, 1,
0, 0, 0, 0,
0, 3);
blinking2(watering_modes[current_mode], 0, 1, 0);
}
void blinking2(String variable, int mesto_cursora, int stroka_display , int format ) {
lcd.setCursor(mesto_cursora, stroka_display);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
if (ledState == 1) {
ledState = 0;
}
else {
ledState = 1;
}
}
if (ledState == 1) {
if (format == 0) { //мигание
lcd.print(variable);
}
if (format == 1) {
lcd.print(variable);// сделать проверку на нулл, те если передаётся "" то это мигать on/off,а int format можно удалить
}
}
if (ledState == 0) {
if (format == 0) { //мигание
clear2(mesto_cursora, stroka_display, 15);
}
if (format == 1) {
clear2(mesto_cursora, stroka_display, 4);
}
}
}
void menu5() {
lcd.setCursor(0, 0);
lcd.print("Poliv kajdyy");
lcd.setCursor(0, 1);
lcd.print("nachnay c");
watering_frequency = change_variable2(watering_frequency, 1,
13, 0, 2, 0,
0, 30);
blinking(watering_frequency , 13, 0, 0);
lcd.print("D");
blinking(int_start_h , 10, 1, 3);
lcd.print(":");
blinking(int_start_m , 13, 1, 3);
next_menu(BTN_RIGHT, 10, 0);
}
void menu15() {
lcd.setCursor(0, 0);
lcd.print("Poliv kajdyy");
lcd.setCursor(0, 1);
lcd.print("nachnay c");
lcd.setCursor(13, 0);
lcd.print(watering_frequency);
lcd.print("D");
int_start_h = change_variable2(int_start_h, 1,
10, 1, 2, 1,
0, 23);
blinking(int_start_h , 10, 1, 1);
lcd.print(":");
blinking(int_start_m , 13, 1, 3);
next_menu(BTN_RIGHT, 10, 0);
}
void menu25() {
lcd.setCursor(0, 0);
lcd.print("Poliv kajdyy");
lcd.setCursor(0, 1);
lcd.print("nachnay c");
lcd.setCursor(13, 0);
lcd.print(watering_frequency);
lcd.print("D");
blinking(int_start_h , 10, 1, 3);
lcd.print(":");
int_start_m = change_variable2(int_start_m, 5,
13, 1, 2, 1,
0, 55);
blinking(int_start_m , 13, 1, 1);
next_menu(BTN_RIGHT, 10, 1);
}
void menu35() {
lcd.setCursor(0, 0);
lcd.print("Dlitelnosc");
lcd.setCursor(0, 1);
lcd.print("poliva:");
duration_h = change_variable2(duration_h, 1,
9, 1, 2, 1,
0, 23);
blinking(duration_h , 9, 1, 1);
lcd.print(":");
blinking(duration_m , 12, 1, 3);
next_menu(BTN_RIGHT, 10, 0);
}
void menu45() {
lcd.setCursor(0, 0);
lcd.print("Dlitelnosc");
lcd.setCursor(0, 1);
lcd.print("poliva:");
blinking(duration_h , 9, 1, 3);
lcd.print(":");
blinking(duration_m , 12, 1, 1);
duration_m = change_variable2(duration_m, 1,
12, 1, 2, 1,
1, 59);
next_menu(BTN_RIGHT, 10, 1);
}
void menu55() {
lcd.setCursor(0, 0);
lcd.print("Napor vody pry");
lcd.setCursor(0, 1);
lcd.print("polive:");
lcd.setCursor(9, 1);
blinking(watering_head , 9, 1, 0);
watering_head = change_variable2(watering_head, 5,
9, 1, 3, 0,
0,85 );
lcd.setCursor(13, 1);
lcd.print("%");
//watering_head = map(int test, 90, 1, 1, 100);
next_menu(BTN_RIGHT, -50, 1);
}
void menu7() {
int light = analogRead(A0); //глоб переменная
Serial.println(light, "a0");
// Если значение light на входе A0 меньше 500, включаем светодиод
if (light < 700) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
//if (digitalRead(10) == HIGH){}
int val2 = analogRead(A1);
int val02;
val02 = map(val2, 0, 1023, 0, 100);
Serial.println(val02, "a1");
lcd.setCursor(0, 0);
lcd.print(" a0");
lcd.setCursor(0, 0);
lcd.print(light);
lcd.setCursor(0, 1);
lcd.print(" a1");
lcd.setCursor(0, 1);
lcd.print(val02);
delay(50);
}
void menu8() {
lcd.setCursor(0, 0);
lcd.print("Vklchenie poliva");
lcd.setCursor(0, 1);
lcd.print("pri vlajnst ");
blinking2(on_off[bool_humidity_on], 13, 1, 1);
bool_humidity_on = change_variable2(bool_humidity_on, 1,
0, 0, 0, 0,
0, 1);
next_menu(BTN_RIGHT, 10, 1);
}
void menu18() {
lcd.setCursor(0, 0);
lcd.print("Vklchenie poliva");
lcd.setCursor(0, 1);
lcd.print("pri vlajnst:");
lcd.setCursor(15, 1);
lcd.print("%");
blinking(humidity_on , 12, 1, 0);
humidity_on = change_variable2(humidity_on, 1,
12, 1, 4, 0,
0, 100);
next_menu(BTN_RIGHT, -10, 1);
}
void menu9() {
lcd.setCursor(0, 0);
lcd.print("Otklch-ie poliva");
lcd.setCursor(0, 1);
lcd.print("pri vlajnst ");
//ПОПРОБОВАТЬ ЧЕРЕЗ ТИП bool
blinking2(on_off[bool_humidity_off], 13, 1, 1);
bool_humidity_off = change_variable2(bool_humidity_off, 1,
0, 0, 0, 0,
0, 1);
next_menu(BTN_RIGHT, 10, 1);
}
void menu19() {
lcd.setCursor(0, 0);
lcd.print("Otklch-ie poliva");
lcd.setCursor(0, 1);
lcd.print("pri vlajnst:");
lcd.setCursor(15, 1);
lcd.print("%");
blinking(humidity_off , 12, 1, 0);
humidity_off = change_variable2(humidity_off, 1,
12, 1, 4, 0,
0, 100);
//humidity_off = change_variable2(BTN_UP, humidity_off, 10, 12, 1, 4, 0, 100);
//humidity_off = change_variable2(BTN_DOWN, humidity_off, -5, 12, 1, 4, 0, 100);
next_menu(BTN_RIGHT, -10, 1);
}
void clear2(int mesto_cursora, int stroka_display , int n_clear_text) {
lcd.setCursor(mesto_cursora, stroka_display);
for (int i = 0; i < n_clear_text; i++) {
lcd.print(" ");
}
}
void next_menu(int btn, int n, int clear_on) { //функция для перехода между menu
int button = detectButton();
if (button == btn) {
if (BTN_RIGHT == btn) {
if (submenu_on == 0) {
submenu_on = menu_n;
}
}
if (submenu_on != 0) {
if (BTN_SELECT == btn or BTN_LEFT == btn) {
menu_n = submenu_on;
submenu_on = 0;
}
}
if (clear_on == 1) {
//clear();
lcd.clear();
}
menu_n = menu_n + n;
if (menu_n == -1) {
menu_n = 0;
}
delay(300);
}
}
void blinking(float variable, int mesto_cursora, int stroka_display, int format ) {
int n_text_clear;
lcd.setCursor(mesto_cursora, stroka_display);
//String myString = String(variable);
unsigned long currentMillis = millis();
//сделать тут 3 формат а всё остальное в else
if (currentMillis - previousMillis >= 200) {
previousMillis = currentMillis;
if (ledState == 1) {
ledState = 0;
}
else {
ledState = 1;
}
}
if (ledState == 1) {
if (format == 0) { //просто int без доп. нуля
lcd.print((int)variable);
}
if (format == 1 or format == 3) { //int с дополнительным нулём для отображения часов
if (variable >= 0 && variable < 10) {
lcd.print("0");
lcd.print((int)variable);
}
else lcd.print((int)variable);
}
if (format == 2) { //float для отображения температуры
lcd.print(variable);
}
}
if (ledState == 0) {
if (format == 0) { //просто int без доп. нуля
int variable0 = (int)variable;
String variable1 = (String)variable0;
n_text_clear = variable1.length();
clear2(mesto_cursora, stroka_display, n_text_clear);
}
if (format == 1) { //int с дополнительным нулём для отображения часов
int variable0 = (int)variable;
String variable1 = (String)variable0;
n_text_clear = variable1.length();
if (n_text_clear == 1) {
n_text_clear = 2;
}
clear2(mesto_cursora, stroka_display, n_text_clear);
}
if (format == 2) { //float для отображения температуры
String variable1 = (String)variable;
n_text_clear = variable1.length();
clear2(mesto_cursora, stroka_display, n_text_clear);
}
if (format == 3) { //int с дополнительным нулём для отображения часов без мигания
if (variable >= 0 && variable < 10) {
lcd.print("0");
lcd.print((int)variable);
}
else lcd.print((int)variable);
}
}
}
float change_variable2(float variable, float n, //функция для изменения переменных в меню
int mesto_cursora, int stroka_display , int n_text_clear, int format,
float minn, float maxx) { //можно сделать из этого функцию
//int mesto_cursora , int stroka, int chslo_pystyx_tochk) {
;
//blinking(variable,mesto_cursora,stroka_display ,n_text_clear, format );
int button = detectButton();
if (button == BTN_UP or button == BTN_DOWN) {
if (millis() - ms_next >= 300) {
ms_next = millis();
float variable_old = variable;
//select_on = 1;
if (button == BTN_UP) {
variable = variable + n;
}
if (button == BTN_DOWN) {
variable = variable - n;
}
variable = constrain(variable, minn, maxx);
if (variable == variable_old) {
if (variable == maxx) {
variable = minn;
}
else {
variable = maxx;
}
}
if ( n_text_clear!=0)
{
clear2( mesto_cursora, stroka_display , n_text_clear + 1);
}
//else
{
// clear2( mesto_cursora, stroka_display , n_text_clear);
}
}
}
//blinking(variable, mesto_cursora, stroka_display , n_text_clear, format );
return variable;
}
/*float change_variable(int btn, float variable, float n) { //функция для изменения переменных в меню
//int stroka_display , int mesto_cursora, int chslo_pystyx_tochk) {
int button = detectButton();
if (button == btn) {
//select_on = 1;
variable = variable + n; delay(300);
}
return variable;
}*/
void servo(int i) {
{
///НУЛЕВОЙ
if (p0 != p0_old)
{
myservo0.attach(16);
//myservo0.write(p0);
servo_muve(0, p0, p0_old);
delay(1000);
p0_old = p0;
}
myservo0.detach();
//ПЕРВЫЙ
if (p1 != p1_old)
{
myservo1.attach(17);
//myservo1.write(p1);
servo_muve(1, p1, p1_old);
delay(1000);
p1_old = p1;
}
myservo1.detach();
}
}
void servo_muve(int i, int pi, int pi_old)
{
if (pi_old < pi) {
for (pi_old; pi_old <= pi; pi_old += 1) {
if (i == 0) {
myservo0.write(pi_old);
}
else {
myservo1.write(pi_old);
}
delay(15);
}
}
else {
for (pi_old; pi_old >= pi; pi_old -= 1) {
if (i == 0) {
myservo0.write(pi_old);
}
else {
myservo1.write(pi_old);
}
delay(15);
}
}
}