/***************************************************
This is our GFX example for the Adafruit ILI9341 Breakout and Shield
----> http://www.adafruit.com/products/1651
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
//#include <FastLED_NeoPixel.h>
#include <Adafruit_NeoPixel.h>
#define LED_PIN 8
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 16
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
//#define DATA_PIN 6
//#define NUM_LEDS 60
//#define BRIGHTNESS 50
//FastLED_NeoPixel<NUM_LEDS, DATA_PIN, NEO_GRB> strip;
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
#define CLK 3
#define DT 4
#define SW 5
#include "GyverEncoder.h"
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
Encoder enc1(CLK, DT, SW, TYPE2); // для работы c кнопкой и сразу выбираем тип
int stat = 0;
int stat1 = 0;
int stat2 = 0;
int stat3 = 0;
int stat4 = 0;
int stat5 = 0;
int stat6 = 0;
int change = 0;
int iris =0;
int level = 0;
int tmpkl = 0;
int lable = 0;
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(250); // Set BRIGHTNESS to about 1/5 (max = 255)
strip.setPixelColor(0, 10, 12, 255,50);
tft.begin();
Serial.begin(9600);
//enc1.setType(TYPE2);
//tft.init(240, 320, SPI_MODE2); // init ST7789 display 240x240 pixel
//tft.setRotation(1); //0 - -180, 1 -90, 2 - 0 , 3- +90 градусов
//strip.begin(); // initialize strip (required!)
//strip.setBrightness(BRIGHTNESS);
/*
tft.fillScreen(ILI9341_BLACK); // Фон
tft.setTextSize(2);
tft.setCursor(5, stat*20);
tft.print("->");
tft.setCursor(40, 0);
tft.print("Main menu");
tft.setCursor(40, 20);
tft.print("Second menu");
tft.setCursor(40, 40);
tft.print("Third menu");
tft.setCursor(40, 60);
tft.print("Four menu");
tft.setCursor(40, 80);
tft.print("Fifs menu");
tft.setCursor(40, 100);
tft.print("Display menu");
tft.setCursor(40, 120);
tft.print("Camera menu");
*/
// read diagnostics (optional but can help debug problems)
//uint8_t x = tft.readcommand8(ILI9341_RDMODE);
//Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
// x = tft.readcommand8(ILI9341_RDMADCTL);
//Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
//x = tft.readcommand8(ILI9341_RDPIXFMT);
//Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
//x = tft.readcommand8(ILI9341_RDIMGFMT);
//Serial.print("Image Format: 0x"); Serial.println(x, HEX);
//x = tft.readcommand8(ILI9341_RDSELFDIAG);
//Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
tft.fillRect(0, 0, 40, 310, ILI9341_YELLOW); // отступ право, отступ низ, ширина, высота, цвет
tft.fillRect(200, 0, 40, 310, ILI9341_YELLOW); // отступ право, отступ низ, ширина, высота, цвет
delay(2500);
/*
Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
Serial.println(F("Benchmark Time (microseconds)"));
delay(10);
Serial.print(F("Screen fill "));
Serial.println(testFillScreen());
delay(500);
Serial.print(F("Text "));
Serial.println(testText());
delay(3000);
Serial.print(F("Lines "));
Serial.println(testLines(ILI9341_CYAN));
delay(500);
Serial.print(F("Horiz/Vert Lines "));
Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
delay(500);
Serial.print(F("Rectangles (outline) "));
Serial.println(testRects(ILI9341_GREEN));
delay(500);
Serial.print(F("Rectangles (filled) "));
Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
delay(500);
Serial.print(F("Circles (filled) "));
Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
Serial.print(F("Circles (outline) "));
Serial.println(testCircles(10, ILI9341_WHITE));
delay(500);
Serial.print(F("Triangles (outline) "));
Serial.println(testTriangles());
delay(500);
Serial.print(F("Triangles (filled) "));
Serial.println(testFilledTriangles());
delay(500);
Serial.print(F("Rounded rects (outline) "));
Serial.println(testRoundRects());
delay(500);
Serial.print(F("Rounded rects (filled) "));
Serial.println(testFilledRoundRects());
delay(500);
Serial.println(F("Done!"));
*/
}
void loop() {
//strip.setPixelColor(0, 0, 0, 255);
//strip.setPixelColor(1, 0, 255, 0);
//strip.setPixelColor(2, 255, 0, 0);
//strip.setPixelColor(0, strip.Color(0, 0, 255));
//change = 0;
tmpkl = 0;
// обязательная функция отработки. Должна постоянно опрашиваться
enc1.tick();
if (enc1.isTurn()) {
//Serial.println("TTTTTTTT"); // если был совершён поворот (индикатор поворота в любую сторону)
// ваш код
}
// if (enc1.isRight()) Serial.println("Right"); // если был поворот
// +++++++++++++++++++++++++++++++++++ R I G H T +++++++++++++++++++++++++++++++++++++++++++++++
if (enc1.isRight()){
Serial.println("Right");
lable += 1;
Serial.println(lable);
//if (lable )
change = 1;
}
// +++++++++++++++++++++++++++++++++++ L E F T ++++++++++++++++++++++++++++++
if (enc1.isLeft()) {
Serial.println("Left");
lable -= 1;
Serial.println(lable);
change = 1;
}
// +++++++++++++++++++++++++++++++++ K L I K ++++++++++++++++++++++++++++++++++++
if (enc1.isSingle()){
Serial.println("OK ");
change = 1;
if (lable == 0){
lable = 7;
}
}
if (enc1.isRightH()) Serial.println("Right holded"); // если было удержание + поворот
if (enc1.isLeftH()) Serial.println("Left holded");
//if (enc1.isPress()) Serial.println("Press"); // нажатие на кнопку (+ дебаунс)
//if (enc1.isRelease()) Serial.println("Release"); // то же самое, что isClick
if (enc1.isClick()) Serial.println("Click"); // одиночный клик
//if (enc1.isSingle()) Serial.println("Single"); // одиночный клик (с таймаутом для двойного)
//if (enc1.isDouble()) Serial.println("Double"); // двойной клик
if (enc1.isHolded()) {
Serial.println("Holded"); // если была удержана и энк не поворачивался
lable = 0;
change = 1;
}
//if (enc1.isHold()) Serial.println("Hold"); // возвращает состояние кнопки
switch (lable) {
case 0:
{
if (change == 1){
tft.fillScreen(ILI9341_BLACK); // Фон
tft.setTextSize(2);
tft.setCursor(5, lable);
tft.print("->");
//tft.fillRect(40, 0, 160, 320, ILI9341_BLACK);
tft.setCursor(40, 0);
tft.print("Leds color");
tft.setCursor(40, 20);
tft.print("Second menu");
tft.setCursor(40, 40);
tft.print("Third menu");
tft.setCursor(40, 60);
tft.print("Four menu");
tft.setCursor(40, 80);
tft.print("Fifs menu");
tft.setCursor(40, 100);
tft.print("Display menu");
tft.setCursor(40, 120);
tft.print("Camera menu");
change = 0;
}
}
break;
case 1 ... 6: {
if (change == 1){
tft.fillRect(0, 0, 40, 320, ILI9341_BLACK); // отступ право, отступ низ, ширина, высота, цвет
tft.setCursor(5, lable*20);
tft.print("->");
change = 0;
}
}
break;
case 7 ... 13:
{
if (change == 1){
Serial.println("Main OPEN");
//tft.fillScreen(ILI9341_BLACK); // Фон
tft.setTextSize(2);
//tft.setCursor(5, stat1*20);
//tft.print("->");
tft.fillRect(40, 0, 160, 320, ILI9341_BLACK);
tft.setCursor(40, 0);
tft.println(" NOMER");
//tft.setCursor(40, 20);
tft.println(" R");
//tft.setCursor(40, 40);
tft.println(" G");
//tft.setCursor(40, 60);
tft.println(" B");
//tft.setCursor(40, 80);
tft.println(" XXXXXX");
//tft.setCursor(40, 100);
tft.println(" YYYYYYY");
//tft.setCursor(40, 120);
tft.println(" Return");
change = 0;
}
} break;
case 14 ... 20:
{
if (change == 1){
Serial.println(" AAAHHHTTTUUUNNNGGG");
var();
change = 0;
}
} break;
case 21 ... 27: break;
case 28 ... 34: break;
case 35 ... 41:
{
if (change == 1){
Serial.println("Main OPEN");
//tft.fillScreen(ILI9341_BLACK); // Фон
tft.setTextSize(2);
//tft.setCursor(5, stat1*20);
//tft.print("->");
tft.fillRect(40, 0, 160, 320, ILI9341_BLACK);
tft.setCursor(40, 0);
tft.print("IRIS");
tft.setCursor(200, 0);
tft.print(iris);
tft.setCursor(40, 20);
tft.print("BLK LVL :");
tft.setCursor(40, 40);
tft.print("FColor :");
tft.setCursor(40, 60);
tft.print("R :");
tft.setCursor(40, 80);
tft.print("G :");
tft.setCursor(40, 100);
tft.print("B :");
tft.setCursor(40, 120);
tft.print("Return");
change = 0;
}
}
break;
}
if (enc1.isDouble()){
Serial.print("level ");
Serial.println(level);
}
}
void var(){
Serial.println("KUKU");
tft.fillScreen(ILI9341_BLACK); // Фон
tft.setTextSize(2);
tft.setCursor(5, stat1*20);
tft.print("->");
tft.setCursor(40, 0);
tft.print("sdfrtfhsdrth");
tft.setCursor(40, 20);
tft.print("Sdsfg");
tft.setCursor(40, 40);
tft.print("Thisdghnu");
tft.setCursor(40, 60);
tft.print("Fosdfhgmenu");
tft.setCursor(40, 80);
tft.print("Fisdfghenu");
tft.setCursor(40, 100);
tft.print("Dispsdfgmenu");
tft.setCursor(40, 120);
tft.print("Resdfgrn");
}