//Настройка всего, что есть
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
pinMode(8, OUTPUT);
tft.begin();
on();//включение модуля
}
bool ison=false;//Включен ли модуль
void onPos1(){//Включение позиции 1
tft.fillRect(10, 10, 220, 50,ILI9341_MAGENTA);
tft.setCursor(90,25);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println("off");
}
void offPos1(){//Выключение позиции 1
tft.fillRect(10, 10, 220, 50,ILI9341_PURPLE);
tft.setCursor(90,25);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println("off");
}
void onPos2(){//Включение позиции 2
tft.fillRect(10, 100, 220, 50,ILI9341_MAGENTA);
tft.setCursor(15,115);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println("don't using");
}
void offPos2(){//Выключение позиции 2
tft.fillRect(10, 100, 220, 50,ILI9341_PURPLE);
tft.setCursor(15,115);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println("don't using");
}
void offAll(){//Отключение позиций
offPos1();
offPos2();
}
int pos=1;
void on(){//Функция включения
tone(8,523,300);//Заставка
delay(400);
tone(8,622,300);
delay(400);
tft.fillScreen(ILI9341_RED);
tft.setTextColor(ILI9341_DARKGREEN);
tft.setTextSize(4.5);
tft.setCursor(50,130);
tone(8,466,1500);
tft.println("I");
delay(1000);
tft.setCursor(75,130);
tft.println("v");
delay(200);
tft.setCursor(100,130);
tft.println("e");
delay(200);
tft.setCursor(125,130);
tft.println("t");
delay(200);
tft.setCursor(150,130);
tft.println("s");
delay(700);
tft.setCursor(60,170);
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(2);
tft.println("techology");
delay(1200);
tft.fillScreen(ILI9341_LIGHTGREY);//Включение модуля
ison=true;
offAll();
pos=1;//Начальня позиция 1
}
void off(){//Функция отключения модуля
tft.fillScreen(ILI9341_RED);
tft.setTextColor(ILI9341_DARKGREEN);
tft.setTextSize(4.5);
tft.setCursor(30,100);
tft.println("Goodbye!");
tone(8,440,750);
delay(750);
tone(8,587,750);
delay(1500);
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
if (digitalRead(2)==HIGH && ison && pos==1){//Включение позиции 1, если кнопка нажата
offPos2();
onPos1();
pos=2;
delay(3000);
if(digitalRead(2)==HIGH && ison) {//Если кнопка удержана более, чем 3сек
off();
ison=false;
}
}
if (digitalRead(2)==HIGH && pos==2 && ison){//Включение позиции 2, если кнопка нажата
onPos2();
offPos1();
pos=1;
}
if(digitalRead(2)==HIGH && ison==false){//Если модуль выключен, то включаем
on();
ison=true;
}
}