// art100 to write encoder - arduino nano - i2c SDA-A4 SDL-A5 oled 0.9" 128x32
//#include <microLiquidCrystal_I2C.h> //i2c 0x27 LCD2004 encoder and i2c 0x27 LCD2004 ok
//#include <LiquidCrystal.h> //ArduinoShieldLcdButtons encoder and shield bed ???
#include "GyverEncoder.h" // only 4 pin s1, s2, sw, gnd,
//#include <SPI.h> //i2c SDA-A4 SDL-A5 oled 0.9" 128x32 нахрена в примере не понятно типо универсально может быть
#include <Wire.h> //i2c SDA-A4 SDL-A5 oled 0.9" 128x32 // стандартная arduino i2c
#include <Adafruit_GFX.h> //i2c SDA-A4 SDL-A5 oled 0.9" 128x32 // но обязательна но без ее нескольких функция бяда с адовыми фруктами
#include <Adafruit_SSD1306.h> //i2c SDA-A4 SDL-A5 oled 0.9" 128x32 // encoder and i2c 0x3c oled ok
//pins------------------------------------------
#define CLK 2
#define DT 3
#define SW 4
//#define PIN_SHIELD_BUTTON1 A0 //ArduinoShieldLcdButtons bed ???
//LiquidCrystal lcd(8,9,4,5,6,7); //ArduinoShieldLcdButtons bed ???
//consts---------------------------------------------
Encoder enc1(CLK, DT, SW);
int value = 0;
//LiquidCrystal_I2C lcd(0x27, 20, 4); //i2c 0x27 LCD2004
#define SCREEN_WIDTH 128 //i2c SDA-A4 SDL-A5 oled 0.9" 128x32
#define SCREEN_HEIGHT 32 //i2c SDA-A4 SDL-A5 oled 0.9" 128x32
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) //i2c SDA-A4 SDL-A5 oled 0.9" 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //i2c SDA-A4 SDL-A5 oled 0.9" 128x32
String string1;
//-------------------------------------------------
void DrawLCD132x32String1(String String1,int size1,int x1,int y1){// display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(size1);
display.setCursor(x1,y1);display.print(String1);
display.display();
}
//-------------------------------------------------
void DrawLcd132x32int1long1(int int1,String long1,int size1,int x1,int y1){// display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(size1);
//display.setCursor(x1,y1);display.print(F("0x"));// чстим поле для вывода
display.setCursor(x1,y1);display.print(int1); // выводим на почищенное место
display.display();
}
//-------------------------------------------------
void DrawLCD132x32Int1(int int1,int size1,int x1,int y1){// display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(size1);
//display.setCursor(x1,y1);display.print(long1);
display.setCursor(x1,y1);display.print(int1);
display.display();
}
//-------------------------------------------------
void DrawLcd132x32init1row123(int int1,int row1){
//DrawLCD132x32Int1("--------------------",1, 0, 0); // top small
//DrawLCD132x32Int1(" " ,2, 0, 9); // center normal
//DrawLCD132x32Int1("------------- art100",1, 0,25); // bottop small
// if(row1=1){
// DrawLCD132x32Int1(" ",1, 0, 0);//top clear
// DrawLCD132x32Int1(int1 ,1, 0, 0);
// }
if(row1=2){
DrawLCD132x32Int1(" ",2, 0, 9);
DrawLCD132x32Int1(int1 ,2, 0, 9);
}
// if(row1=3){
// DrawLCD132x32Int1(" ",1, 0,25);
// DrawLCD132x32Int1(int1 ,1, 0,25);
// }
}
//-------------------------------------------------
void DrawLcd132x32clear1int2(int int1,int size1,int x1,int y1){
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(size1);
display.setCursor(x1,y1);display.print(int1);
display.display();
}
//--------------------------------------------------------------
void isrCLK(){ enc1.tick(); } // отработка в прерывании
//--------------------------------------------------------------
void isrDT (){ enc1.tick(); } // отработка в прерывании
//---------------------------------------------------------
void setup() {
Serial.begin(9600);
attachInterrupt(0, isrCLK, CHANGE); // прерывание на 2 пине! CLK у энка
attachInterrupt(1, isrDT, CHANGE); // прерывание на 3 пине! DT у энка
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed")); //i2c SDA-A4 SDL-A5 oled 0.9" 128x32
for(;; // Don't proceed, loop forever //i2c SDA-A4 SDL-A5 oled 0.9" 128x32
}
display.display();
delay(2000); // Pause for 2 seconds
display.clearDisplay();// Clear the buffer
DrawLCD132x32String1("1________01________0",1, 0, 0);//DrawString1(String String1,int size1,int x1,int y1)
DrawLCD132x32String1("art100 ok" ,2, 0, 9);//DrawString1(String String1,int size1,int x1,int y1)
DrawLCD132x32String1("1________01________0",1, 0,25);//DrawString1(String String1,int size1,int x1,int y1)
//lcd.init();//i2c
//lcd.backlight();//i2c
//lcd.begin(16,2);//ArduinoShieldLcdButtons
//lcd.clear();//ArduinoShieldLcdButtons
//lcd.setCursor(3, 0); lcd.print("Hello, world!");
//lcd.setCursor(2, 1); lcd.print("Ywrobot Arduino!");
// lcd.setCursor(0, 2); lcd.print("Arduino LCM IIC 2004");
// lcd.setCursor(2, 3); lcd.print("Power By Ec-yuan!");
}
//--------------------------------------------------------------
//==============================================================
void loop() {
enc1.tick();
if (enc1.isRight ()){ value++; Serial.println("Right"); } //display.clearDisplay();DrawLCD132x32String1("Right ",1, 0,25); } // если был поворот
if (enc1.isLeft ()){ value--; Serial.println("Left"); } //display.clearDisplay();DrawLCD132x32String1(" Left ",1, 0,25); }
if (enc1.isRightH()){ value=+10; Serial.println("Right holded"); }// если было удержание + поворот
if (enc1.isLeftH ()){ value=-10; Serial.println("Left holded"); }
if (enc1.isPress ()){ Serial.println("Press"); }//display.clearDisplay(); }
//if (enc1.isRelease()) Serial.println("Release");
//if (enc1.isClick()) Serial.println("Click");
if (enc1.isHolded ()){ Serial.println("Holded");display.clearDisplay(); }
//if (enc1.isTurn()) { // если был совершён поворот (индикатор поворота в любую сторону)
// Serial.println(value); // выводим значение при повороте
// //lcd.setCursor(2, 1); lcd.print(value);//lcd.setCursor(2, 3); lcd.print(value);
//}
//lcd--------------------------------------------------------------------------
if (enc1.isTurn()) { // если был совершён поворот (индикатор поворота в любую сторону)------------------------------+++++++++ //display.clearDisplay();// Clear the buffer
Serial.println(value); // выводим значение при повороте
DrawLcd132x32clear1int2(value,4,0,0);//DrawLcd132x32clear1int2(int int1,int size1,int x1,int y1)
//DrawLcd132x32init1row123(value,2);//DrawLcd132x32init1row123(int int1,int row1)
//string1=IntToString(value);
//DrawLCD132x32String1("value",2,0,9);//DrawString1(String String1,int size1,int x1,int y1)
//DrawLCD132x32Int1(value,2,0,9);//DrawString1(String String1,int size1,int x1,int y1)
//DrawLcd132x32int1long1(value," ",2,0,9);//DrawLcd132x32int1long1(int int1,int long1,int size1,int x1,int y1)
// delay(2000); display.clearDisplay();
}
//lcd--------------------------------------------------------------------------
}
//==============================================================