Problem with animating in u8g2

I having a problem i need to program a scrolable menu but have a 128*64 st7920 display that has contability with u8g/u8g2 libery and  i have problem with that libery. 
So the problem is this i need to animate frame and move it from one side of screen to another.
you think thats easy just do this and you are done   


#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif



U8G2_IST7920_128X128_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);  // Round display



void u8g2_r_frame(uint8_t a) {
  u8g2.drawStr( 0, 0, "drawRFrame/Box");
  u8g2.drawRFrame(5, 10, 40, 30, a + 1);
  u8g2.drawRBox(50, 10, 25, 40, a + 1);
}








uint8_t draw_state = 0;

void draw(void) {
  u8g2_prepare();

  u8g2_r_frame(draw_state & 7); ak;
}


void setup(void) {
  u8g2.begin();
}

void loop(void) {
  // picture loop
  u8g2.clearBuffer();
  draw();
  u8g2.sendBuffer();

  // increase the state
  draw_state++;
  if ( draw_state >= 12 * 8 )
    draw_state = 0;

  // deley between each page
  delay(100);

}

Wrong  I need to do this and run my OS on top of this 
and if I will need to move more elements in one time. its like card house it breaks fast.

SO I created this 

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif



U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 14, /* data=*/ 27, /* CS=*/ 12, /* reset=*/ 8);
bool obnova = false;
int x = 0;
void setup() {
  // put your setup code here, to run once:
 u8g2.begin();
 u8g2.clearBuffer();
 pinMode(13, OUTPUT);
digitalWrite(13, LOW);
  digitalWrite(13, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
u8g2.clearBuffer();
   // kreslit();

for (int a =0;a >10;a++){
u8g2.drawFrame(a, 18, 40, 40);
 u8g2.sendBuffer();

delay(100);
}

delay(1000);
   

}

Hold on your horses,DUH you doesnt understand what is picure loop.
 Thats is the problem i dont understand why i cant use picure loop in loop while or for.
and even stranger is that why u8g2 doesnt have some that is same or even better than Adafruit GFX. WHY? I now but about 8x8 mode but that is very VERY limited.   
Strange is also that you can do picure loops after picure loops and in documation is sendBuffer defined as it updates display from internal buffer so WHY? You cant you use it multiple times to update the DAMM screen and clear screen also.
If Adafruit GFX with ssd1...whatever can do it why cant u8g2 can do it even better.

Tell us more.

And please keep your code tags separate from your comments - it makes stuff hard to read.

Hello there,
tell more about it
ok here is my story

i want to do a device based on esp32
that is portable,wifi and bluetoth capable,...
Main funcion is a multi tool like smartphone but in other ways.

And i need a good OS on top of it all.
So i know that esp32 2 core mirocontroller
so 1 core is assigned display manager "GPU"
and another is assigned like brains of this all "CPU"

so CPU calls a subrotine that changes variables that changes what GPU is doing
but each subrotine can be on display at one time only one with is limiting.
But even worse it is SLOoooow to code because you must do two funcions and many changes to do one extra screen

BUT that is not all because you canot animated (WELL because i that it can be done but it would be paifully implemented)

so i rethinked the strategy and now what i want to do is make all this drawing process on cpu an second core leave like koproprocesor for ather tasks

CODE IS HERE :

//Lcd display
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//SD karta
#include "FS.h"
#include "SD.h"

//PINY

//piny lcd dislay
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=/ 14, / data=/ 27, / CS=/ 12, / reset=*/ 8);

//piny joystick 1
int xjoy1pin = 36;
int yjoy1pin = 39;
int tlacjoy1pin = 33;
//piny joystick 2
int xjoy2pin = 0;
int yjoy2pin = 0;
int tlacjoy2pin = 33;

//triger 1
int triger1pin = 0;
//triger 2
int triger2pin = 0;

//ROYDELENI JADER
TaskHandle_t CPU;
TaskHandle_t GPU;

//OS promene

//PROMENE VSTUPU
//joystick 2
int xjoy1h = 0;
int yjoy1h = 0;

int xjoy1 = 0;
int yjoy1 = 0;
int tlacjoy1 = 0;

//joystick 1
int xjoy2h = 0;
int yjoy2h = 0;

int xjoy2 = 0;
int yjoy2 = 0;
int tlacjoy2 = 0;

//CPU GRAFICKE PROMENE
int obrazky = 0;
int casobrazky = 0;
//menu
int menu2aktivace = 0;
int stavmenu1 = 0;
const char* volba11 = "";
const char * volba21 = "";
const char* volba31 = "";
const char* volba41 = "";

int stavmenu2 = 0;
const char* volba12 = "";
const char * volba22 = "";
const char* volba32 = "";
const char* volba42 = "";
void menu(int stavmenu3, const charvolba13, const charvolba23, const charvolba33, const charvolba43);
//podmenu
int podmenuaktivace = 0;
int stavhlavnihomenu2 = 0;
const char* vlevo2 = "";
const char* vlevostred2 = "";
const char* pravostred2 = "";
const char* pravo2 = "";

//text
int textaktivace = 0;
int pozicex2 = 0;
int pozicey2 = 0;
int fonty2 = 0;
const char* text2 = "";
void text3(int pozice3x, int pozice3y, int fonty3, const char* text3);
//bitmenu
int predchozivyber3 = 0;
int animacebitmenu = 0;
int vyber2 = 0;
int bitmenuaktivace = 0;
void bitmenu(int vyber1);
void bitmenu3(int vyber2);

//oznameni
int silawifi2 = 0;
int stavbluetooth2 = 0;
int stavbaterie2 = 0;
const char* oznameni2 = "";
int oznameni2aktivace = 0;
void oznameni(int silawifi = 0, int stavbluetooth = 0, int stavbaterie = 0, const char* oznameni="");
void oznameni2(int silawifi3 = 0, int stavbluetooth3 = 0, int stavbaterie3 = 0, const char* oznameni3);

//OS

int cas1 = 0;
int casobnovy = 10;

int cas2 = 0;

//stavy
//triger 1
int triger1 = 0;

//triger 2
int triger2 = 0;

//stav josticku 1
int stavjoy1 = 0;
int predchozistavjoy1 = 0;
//stav josticku 2
int stavjoy2 = 0;
int predchozistavjoy2 = 0;
int nulaX, nulaY;

int couter = 0;
int menux = 0;
int menuy = 0;
int menuuroven [64][64];

void setup() {

//INICIALIZACE

//seriaval linka
Serial.begin(9600);

//lcd display
u8g2.begin();
u8g2.setDisplayRotation(U8G2_R2);
//joystick 1
pinMode(xjoy1pin, INPUT);
pinMode(yjoy1pin, INPUT);
pinMode(tlacjoy1pin, INPUT);
//joystick 2
pinMode(xjoy2pin, INPUT);
pinMode(yjoy2pin, INPUT);
pinMode(tlacjoy2pin, INPUT);

//triger 1
pinMode(triger1pin, INPUT);

//triger 2
pinMode(triger2pin, INPUT);

pinMode(13, OUTPUT);
nulaX = analogRead(39);
nulaY = analogRead(36);

//ROZDELENI PRO JADRA
xTaskCreatePinnedToCore(
Task1code, /* Function to implement the task /
"CPU", /
Name of the task /
10000, /
Stack size in words /
NULL, /
Task input parameter /
1, /
Priority of the task /
&CPU, /
Task handle. /
1); /
Core where the task should run /
delay(100);
xTaskCreatePinnedToCore(
Task2code, /
Task function. /
"GPU", /
name of task. /
10000, /
Stack size of task /
NULL, /
parameter of the task /
1, /
priority of the task /
&GPU, /
Task handle to keep track of created task /
0); /
pin task to core 0 */
delay(100);

}

void Task1code( void * pvParameters ) {
//INTRUPT NA TLACITKA

//Trigery
attachInterrupt(triger1pin, zmertlacitka, RISING);
attachInterrupt(triger2pin, zmertlacitka, RISING);
//joystick tlacitka
attachInterrupt(tlacjoy1pin, zmertlacitka, RISING);
attachInterrupt(tlacjoy2pin, zmertlacitka, RISING);

Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
digitalWrite(13, LOW);
digitalWrite(13, HIGH);
for (;:wink: {
cas2 = cas1 = millis();

joystickyzmer ();
if (stavjoy1 != predchozistavjoy1) {

  if (stavjoy1 != 0) {
    if (stavjoy1 == 1) {
      menuy++;
    }
    if (stavjoy1 == 3) {
      menuy--;
    }
    if (stavjoy1 == 2) {
      menux++;
    }
    if (stavjoy1 == 4) {
      menux--;
    }

    if (menux < 0) {
      menux = 0;
    }
    if (menuy < 0) {
      menuy = 0;
    }
    if (menux >= 64) {
      menux = 64;
    }
    if (menuy >= 64) {
      menuy = 64;
    }
  }
}





bitmenu(menuy);


// menu(menuy, "nazdar", "kup", "1", "2");



bitmenu3(1);


oznameni(1, 1, 1,"ahoj");







//podmenu(, "ahoj", "cus", "zdar", "juu");









if (cas1 - millis() >= 1000) {
  podmenuaktivace = 0;
  menu2aktivace = 0;
  textaktivace = 0;
  oznameni2aktivace = 0;
  bitmenuaktivace = 1;
}
predchozistavjoy1 = stavjoy1;
predchozistavjoy2 = stavjoy2;

}
}

void Task2code( void * pvParameters ) {

for (;:wink: {
// Serial.println("Task2 running on core ");
// Serial.println(xPortGetCoreID());

u8g2.clearBuffer();
kreslit();
u8g2.sendBuffer();

obrazky++;
if ( millis() - casobrazky >= 17) {
  if (obrazky >= 60) {
    obrazky = 0;
    casobrazky = millis();
  }
}

}
}
void loop() {
delay(10000000);
}

void podmenu(int stavhlavnihomenu3, const char* vlevo3, const char* vlevostred3, const char* pravostred3, const char* pravo3) {

stavhlavnihomenu2 = stavhlavnihomenu3;
vlevo2 = vlevo3;
vlevostred2 = vlevostred3;
pravostred2 = pravostred3;
pravo2 = pravo3;
podmenuaktivace = 1;
}

//Grafika pod funkce pro cpu
void menu(int stavmenu3, const charvolba13, const charvolba23, const charvolba33, const charvolba43) {
stavmenu1 = stavmenu3;
volba11 = volba13;
volba21 = volba23;
volba31 = volba33;
volba41 = volba43;
menu2aktivace = 1;
}

void text(int pozicex, int pozicey, int fonty, const char* text) {
pozicex2 = pozicex;
pozicey2 = pozicey;
fonty2 = fonty;
text2 = text;
textaktivace = 1;
}

void bitmenu(int vyber1 = 0) {
vyber2 = vyber1;
bitmenuaktivace = 1;

}
void oznameni(int silawifi, int stavbluetooth, int stavbaterie, const char* oznameni) {

silawifi2 = silawifi;
stavbluetooth2 = stavbluetooth;
stavbaterie2 = stavbaterie;
oznameni2 = oznameni;
oznameni2aktivace = 1;

}

//měreni ovladani
void ICACHE_RAM_ATTR zmertlacitka() {
triger1 = digitalRead(triger1pin);
triger2 = digitalRead(triger2pin);

tlacjoy1 = digitalRead(tlacjoy1pin);
tlacjoy2 = digitalRead(tlacjoy2pin);
}

void joystickyzmer () {
xjoy1h = 0;
yjoy1h = 0;
xjoy2h = 0;
yjoy2h = 0;

xjoy1h = analogRead(39) - nulaX;
yjoy1h = analogRead(36) - nulaY;
// načtení stavu tlačítka

if (xjoy1h > 0) {
xjoy1h = map(xjoy1h, 0, 4095 - nulaX, 0, 100);
}
else {
xjoy1h = map(xjoy1h, 0, -nulaX, 0, -100);
}
if (yjoy1h > 0) {
yjoy1h = map(yjoy1h, 0, 4095 - nulaY, 0, 100);
}
else {
yjoy1h = map(yjoy1h, 0, -nulaY, 0, -100);
}

if (20 > xjoy1h && 20 > yjoy1h && -20 < xjoy1h && -20 < yjoy1h) {
stavjoy1 = 0;
}
if (xjoy1h > 90 && 20 > yjoy1h && -20 < yjoy1h) {
stavjoy1 = 1;
}
if (xjoy1h < -90 && 20 > yjoy1h && -20 < yjoy1h) {
stavjoy1 = 3;
}

if (20 > xjoy1h && -20 < xjoy1h && yjoy1h > 90 ) {
stavjoy1 = 2;
}
if ( 20 > xjoy1h && -20 < xjoy1h && yjoy1h < -90 ) {
stavjoy1 = 4;
}

if (90 < xjoy1h && 90 < yjoy1h) {
stavjoy1 = 5;
}
if (-90 > xjoy1h && -90 > yjoy1h) {
stavjoy1 = 7;
}

if (-90 > xjoy1h && 90 < yjoy1h) {
stavjoy1 = 6;
}

if (90 < xjoy1h && -90 > yjoy1h) {
stavjoy1 = 8;
}

}

//GRAFICKE FUNKCE

void kreslit () {
pripravitdisplay();

if (podmenuaktivace == 1) {
podmenu2(stavhlavnihomenu2 , vlevo2, vlevostred2, pravostred2, pravo2);
}
if (menu2aktivace == 1) {
menu2( stavmenu1, volba11, volba21, volba31, volba41);
}
if (textaktivace == 1) {
text3(pozicex2, pozicey2, fonty2, text2);
}
if (bitmenuaktivace == 1) {
bitmenu3(vyber2);
}
if (oznameni2aktivace == 1) {
oznameni2( silawifi2, stavbluetooth2, stavbaterie2, oznameni2);
}
}

void pripravitdisplay() {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setFontRefHeightExtendedText();
u8g2.setFontPosTop();
u8g2.setFontDirection(0);
}

//PODMENU
void podmenu2(int stavhlavnihomenu1, const char* vlevo1, const char* vlevostred1, const char* pravostred1, const char* pravo1) {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setDrawColor(1);

u8g2.drawLine(0, 48, 128, 48);
u8g2.drawLine(32, 48, 32, 64);
u8g2.drawLine(64, 48, 64, 64);
u8g2.drawLine(96, 48, 96, 64);

u8g2.drawStr(0, 50, vlevo2);
u8g2.drawStr(34, 50, vlevostred2);
u8g2.drawStr(66, 50, pravostred2);
u8g2.drawStr(98, 50, pravo2);

u8g2.setDrawColor(2);

switch (stavhlavnihomenu2) {

case 1:
  u8g2.drawBox(0, 48, 32, 48);
  break;

case 2:
  u8g2.drawBox(32, 48, 64, 48);
  break;

case 3:
  u8g2.drawBox(64, 48, 96, 48);
  break;

case 4:
  u8g2.drawBox(96, 48, 128, 48);
  break;

default:
  break;

}
u8g2.setDrawColor(1);
u8g2.drawLine(0, 48, 128, 48);

}

//MENU

void menu2(int stavmenu2, const char* volba12, const char * volba22, const char* volba32, const char* volba42) {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setDrawColor(0);
u8g2.drawBox(0, 0, 128, 64);
u8g2.setDrawColor(1);

/* u8g2.drawFrame(0, 16, 128, 16);
u8g2.drawFrame(0, 32, 128, 32);
u8g2.drawFrame(0, 48, 128, 48);
u8g2.drawFrame(0, 64, 128, 64);
*/

u8g2.drawStr(1, 1, volba12);
u8g2.drawStr(1, 17, volba22);
u8g2.drawStr(1, 33, volba32);
u8g2.drawStr(1, 49 , volba42);

u8g2.setDrawColor(2);

switch (stavmenu2) {

case 1:
  u8g2.drawBox(0, 0, 128, 16);
  break;

case 2:
  u8g2.drawBox(0, 16, 128, 16);
  break;

case 3:
  u8g2.drawBox(0, 32, 128, 16);
  break;

case 4:
  u8g2.drawBox(0, 48, 128, 16);
  break;

default:
  break;

}
}

void text3(int pozice3x, int pozice3y, int fonty3, const char* text3) {
u8g2.setDrawColor(1);
switch (fonty3) {

case 1:
  u8g2.setFont(u8g2_font_6x10_tf);
  break;

case 2:
  u8g2.setFont(u8g2_font_9x15_tf);
  break;
  /*
      case 3:

        break;

      case 4:

        break;

      default:

        break;
  */

}
u8g2.drawStr(pozice3x, pozice3y, text3);

}

void bitmenu3(int vyber3 = 0) {
u8g2.drawFrame(16, 16 + obrazky * 2, 40, 40);

//predchozivyber3 = vyber3;
}

void oznameni2(int silawifi3 = 0, int stavbluetooth3 = 0, int stavbaterie3 = 0, const char* oznameni3) {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.drawLine(0, 11, 128, 11);

u8g2.drawStr(0,0,oznameni3);

u8g2.drawLine(111, 0, 125, 0);
u8g2.drawLine(111, 9, 125, 9);
u8g2.drawLine(111, 0, 125, 0);
u8g2.drawLine(111, 9, 111, 0);
u8g2.drawLine(125, 8, 125, 1);
u8g2.drawLine(125, 7, 125, 2);

// switch (tavbaterie3){}

}

upss

//Lcd display
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

//SD karta
#include "FS.h"
#include "SD.h"

//PINY

//piny lcd dislay
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 14, /* data=*/ 27, /* CS=*/ 12, /* reset=*/ 8);


//piny joystick 1
int xjoy1pin = 36;
int yjoy1pin = 39;
int tlacjoy1pin = 33;
//piny joystick 2
int xjoy2pin = 0;
int yjoy2pin = 0;
int tlacjoy2pin = 33;


//triger 1
int triger1pin = 0;
//triger 2
int triger2pin = 0;
















//ROYDELENI JADER
TaskHandle_t CPU;
TaskHandle_t GPU;





//OS promene

//PROMENE VSTUPU
//joystick 2
int xjoy1h = 0;
int yjoy1h = 0;

int xjoy1 = 0;
int yjoy1 = 0;
int tlacjoy1 = 0;

//joystick 1
int xjoy2h = 0;
int yjoy2h = 0;

int xjoy2 = 0;
int yjoy2 = 0;
int tlacjoy2 = 0;








//CPU GRAFICKE PROMENE
int obrazky = 0;
int casobrazky = 0;
//menu
int menu2aktivace = 0;
int stavmenu1         = 0;
const char* volba11   = "";
const char * volba21  = "";
const char* volba31   = "";
const char* volba41   = "";

int stavmenu2         = 0;
const char* volba12   = "";
const char * volba22  = "";
const char* volba32   = "";
const char* volba42   = "";
void menu(int stavmenu3, const char*volba13, const char*volba23, const char*volba33, const char*volba43);
//podmenu
int podmenuaktivace = 0;
int stavhlavnihomenu2 = 0;
const char* vlevo2 = "";
const char* vlevostred2 = "";
const char* pravostred2 = "";
const char* pravo2 = "";

//text
int textaktivace = 0;
int pozicex2 = 0;
int pozicey2 = 0;
int fonty2 = 0;
const char* text2 = "";
void text3(int pozice3x, int pozice3y, int fonty3, const char* text3);
//bitmenu
int predchozivyber3 = 0;
int animacebitmenu = 0;
int vyber2 = 0;
int bitmenuaktivace = 0;
void bitmenu(int vyber1);
void bitmenu3(int vyber2);

//oznameni
int silawifi2 = 0;
int stavbluetooth2 = 0;
int stavbaterie2 = 0;
const char* oznameni2 = "";
int oznameni2aktivace = 0;
void oznameni(int silawifi = 0, int stavbluetooth = 0, int stavbaterie = 0, const char* oznameni="");
void oznameni2(int silawifi3 = 0, int stavbluetooth3 = 0, int stavbaterie3 = 0, const char* oznameni3);













//OS

int cas1 = 0;
int casobnovy = 10;


int cas2 = 0;




//stavy
//triger 1
int triger1 = 0;

//triger 2
int triger2 = 0;





//stav josticku 1
int stavjoy1 = 0;
int predchozistavjoy1 = 0;
//stav josticku 2
int stavjoy2 = 0;
int predchozistavjoy2 = 0;
int nulaX, nulaY;

int couter = 0;
int menux = 0;
int menuy = 0;
int menuuroven [64][64];

























void setup() {

  //INICIALIZACE

  //seriaval linka
  Serial.begin(9600);

  //lcd display
  u8g2.begin();
  u8g2.setDisplayRotation(U8G2_R2);
  //joystick 1
  pinMode(xjoy1pin, INPUT);
  pinMode(yjoy1pin, INPUT);
  pinMode(tlacjoy1pin, INPUT);
  //joystick 2
  pinMode(xjoy2pin, INPUT);
  pinMode(yjoy2pin, INPUT);
  pinMode(tlacjoy2pin, INPUT);

  //triger 1
  pinMode(triger1pin, INPUT);

  //triger 2
  pinMode(triger2pin, INPUT);

  pinMode(13, OUTPUT);
  nulaX = analogRead(39);
  nulaY  = analogRead(36);

  //ROZDELENI PRO JADRA
  xTaskCreatePinnedToCore(
    Task1code, /* Function to implement the task */
    "CPU", /* Name of the task */
    10000,  /* Stack size in words */
    NULL,  /* Task input parameter */
    1,  /* Priority of the task */
    &CPU,  /* Task handle. */
    1); /* Core where the task should run */
  delay(100);
  xTaskCreatePinnedToCore(
    Task2code,   /* Task function. */
    "GPU",     /* name of task. */
    10000,       /* Stack size of task */
    NULL,        /* parameter of the task */
    1,           /* priority of the task */
    &GPU,      /* Task handle to keep track of created task */
    0);          /* pin task to core 0 */
  delay(100);


}

void Task1code( void * pvParameters ) {
  //INTRUPT NA TLACITKA

  //Trigery
  attachInterrupt(triger1pin, zmertlacitka, RISING);
  attachInterrupt(triger2pin, zmertlacitka, RISING);
  //joystick tlacitka
  attachInterrupt(tlacjoy1pin, zmertlacitka, RISING);
  attachInterrupt(tlacjoy2pin, zmertlacitka, RISING);

  Serial.print("Task1 running on core ");
  Serial.println(xPortGetCoreID());
  digitalWrite(13, LOW);
  digitalWrite(13, HIGH);
  for (;;) {
    cas2 = cas1 = millis();

    joystickyzmer ();
    if (stavjoy1 != predchozistavjoy1) {

      if (stavjoy1 != 0) {
        if (stavjoy1 == 1) {
          menuy++;
        }
        if (stavjoy1 == 3) {
          menuy--;
        }
        if (stavjoy1 == 2) {
          menux++;
        }
        if (stavjoy1 == 4) {
          menux--;
        }

        if (menux < 0) {
          menux = 0;
        }
        if (menuy < 0) {
          menuy = 0;
        }
        if (menux >= 64) {
          menux = 64;
        }
        if (menuy >= 64) {
          menuy = 64;
        }
      }
    }





    bitmenu(menuy);


    // menu(menuy, "nazdar", "kup", "1", "2");



    bitmenu3(1);


    oznameni(1, 1, 1,"ahoj");







    //podmenu(, "ahoj", "cus", "zdar", "juu");









    if (cas1 - millis() >= 1000) {
      podmenuaktivace = 0;
      menu2aktivace = 0;
      textaktivace = 0;
      oznameni2aktivace = 0;
      bitmenuaktivace = 1;
    }
    predchozistavjoy1 = stavjoy1;
    predchozistavjoy2 = stavjoy2;

  }
}

void Task2code( void * pvParameters ) {

  for (;;) {
    // Serial.println("Task2 running on core ");
    // Serial.println(xPortGetCoreID());

    u8g2.clearBuffer();
    kreslit();
    u8g2.sendBuffer();

    obrazky++;
    if ( millis() - casobrazky >= 17) {
      if (obrazky >= 60) {
        obrazky = 0;
        casobrazky = millis();
      }
    }
  }
}
void loop() {
  delay(10000000);
}














void podmenu(int stavhlavnihomenu3, const char* vlevo3, const char* vlevostred3, const char* pravostred3, const char* pravo3) {

  stavhlavnihomenu2 = stavhlavnihomenu3;
  vlevo2 = vlevo3;
  vlevostred2 = vlevostred3;
  pravostred2 = pravostred3;
  pravo2 = pravo3;
  podmenuaktivace = 1;
}










//Grafika pod funkce pro cpu
void menu(int stavmenu3, const char*volba13, const char*volba23, const char*volba33, const char*volba43) {
  stavmenu1 = stavmenu3;
  volba11 = volba13;
  volba21 = volba23;
  volba31 = volba33;
  volba41 = volba43;
  menu2aktivace = 1;
}

void text(int pozicex, int pozicey, int fonty, const char* text) {
  pozicex2 = pozicex;
  pozicey2 = pozicey;
  fonty2 = fonty;
  text2 = text;
  textaktivace = 1;
}

void bitmenu(int vyber1 = 0) {
  vyber2 = vyber1;
  bitmenuaktivace = 1;

}
void oznameni(int silawifi, int stavbluetooth, int stavbaterie, const char* oznameni) {

  silawifi2 = silawifi;
  stavbluetooth2 = stavbluetooth;
  stavbaterie2 = stavbaterie;
  oznameni2 = oznameni;
  oznameni2aktivace = 1;



}


//měreni ovladani
void ICACHE_RAM_ATTR zmertlacitka() {
  triger1  = digitalRead(triger1pin);
  triger2  = digitalRead(triger2pin);

  tlacjoy1 = digitalRead(tlacjoy1pin);
  tlacjoy2  = digitalRead(tlacjoy2pin);
}

void joystickyzmer () {
  xjoy1h = 0;
  yjoy1h = 0;
  xjoy2h = 0;
  yjoy2h = 0;




  xjoy1h = analogRead(39) - nulaX;
  yjoy1h = analogRead(36) - nulaY;
  // načtení stavu tlačítka

  if (xjoy1h > 0) {
    xjoy1h = map(xjoy1h, 0, 4095 - nulaX, 0, 100);
  }
  else {
    xjoy1h = map(xjoy1h, 0, -nulaX, 0, -100);
  }
  if (yjoy1h > 0) {
    yjoy1h = map(yjoy1h, 0, 4095 - nulaY, 0, 100);
  }
  else {
    yjoy1h = map(yjoy1h, 0, -nulaY, 0, -100);
  }


  if (20 > xjoy1h  && 20 > yjoy1h && -20 < xjoy1h  && -20 < yjoy1h) {
    stavjoy1 = 0;
  }
  if (xjoy1h > 90  && 20 > yjoy1h && -20 < yjoy1h) {
    stavjoy1 = 1;
  }
  if (xjoy1h < -90  && 20 > yjoy1h && -20 < yjoy1h) {
    stavjoy1 = 3;
  }



  if (20 > xjoy1h && -20 < xjoy1h  && yjoy1h > 90 ) {
    stavjoy1 = 2;
  }
  if ( 20 > xjoy1h && -20 < xjoy1h && yjoy1h < -90 ) {
    stavjoy1 = 4;
  }

  if (90 < xjoy1h  && 90 < yjoy1h) {
    stavjoy1 = 5;
  }
  if (-90 > xjoy1h  && -90 > yjoy1h) {
    stavjoy1 = 7;
  }


  if (-90 > xjoy1h  && 90 < yjoy1h) {
    stavjoy1 = 6;
  }

  if (90 < xjoy1h  && -90 > yjoy1h) {
    stavjoy1 = 8;
  }





}










//GRAFICKE FUNKCE




void kreslit () {
  pripravitdisplay();

  if (podmenuaktivace == 1) {
    podmenu2(stavhlavnihomenu2 , vlevo2, vlevostred2, pravostred2, pravo2);
  }
  if (menu2aktivace == 1) {
    menu2( stavmenu1,  volba11,  volba21,  volba31,  volba41);
  }
  if (textaktivace == 1) {
    text3(pozicex2, pozicey2, fonty2, text2);
  }
  if (bitmenuaktivace == 1) {
    bitmenu3(vyber2);
  }
  if (oznameni2aktivace == 1) {
    oznameni2( silawifi2, stavbluetooth2, stavbaterie2, oznameni2);
  }
}

void pripravitdisplay() {
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
}

//PODMENU
void podmenu2(int stavhlavnihomenu1, const char* vlevo1, const char* vlevostred1, const char* pravostred1, const char* pravo1) {
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setDrawColor(1);

  u8g2.drawLine(0, 48, 128, 48);
  u8g2.drawLine(32, 48, 32, 64);
  u8g2.drawLine(64, 48, 64, 64);
  u8g2.drawLine(96, 48, 96, 64);


  u8g2.drawStr(0, 50, vlevo2);
  u8g2.drawStr(34, 50, vlevostred2);
  u8g2.drawStr(66, 50, pravostred2);
  u8g2.drawStr(98, 50, pravo2);

  u8g2.setDrawColor(2);

  switch (stavhlavnihomenu2) {

    case 1:
      u8g2.drawBox(0, 48, 32, 48);
      break;

    case 2:
      u8g2.drawBox(32, 48, 64, 48);
      break;

    case 3:
      u8g2.drawBox(64, 48, 96, 48);
      break;

    case 4:
      u8g2.drawBox(96, 48, 128, 48);
      break;

    default:
      break;


  }
  u8g2.setDrawColor(1);
  u8g2.drawLine(0, 48, 128, 48);

}

//MENU

void menu2(int stavmenu2, const char* volba12, const char * volba22, const char* volba32, const char* volba42) {
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setDrawColor(0);
  u8g2.drawBox(0, 0, 128, 64);
  u8g2.setDrawColor(1);

  /* u8g2.drawFrame(0, 16, 128, 16);
    u8g2.drawFrame(0, 32, 128, 32);
    u8g2.drawFrame(0, 48, 128, 48);
    u8g2.drawFrame(0, 64, 128, 64);
  */

  u8g2.drawStr(1, 1, volba12);
  u8g2.drawStr(1, 17, volba22);
  u8g2.drawStr(1, 33, volba32);
  u8g2.drawStr(1, 49 , volba42);

  u8g2.setDrawColor(2);

  switch (stavmenu2) {

    case 1:
      u8g2.drawBox(0, 0, 128, 16);
      break;

    case 2:
      u8g2.drawBox(0, 16, 128, 16);
      break;

    case 3:
      u8g2.drawBox(0, 32, 128, 16);
      break;

    case 4:
      u8g2.drawBox(0, 48, 128, 16);
      break;

    default:
      break;



  }
}


void text3(int pozice3x, int pozice3y, int fonty3, const char* text3) {
  u8g2.setDrawColor(1);
  switch (fonty3) {

    case 1:
      u8g2.setFont(u8g2_font_6x10_tf);
      break;

    case 2:
      u8g2.setFont(u8g2_font_9x15_tf);
      break;
      /*
          case 3:

            break;

          case 4:

            break;

          default:

            break;
      */


  }
  u8g2.drawStr(pozice3x, pozice3y, text3);

}

void bitmenu3(int vyber3 = 0) {
  u8g2.drawFrame(16, 16 + obrazky * 2, 40, 40);






  //predchozivyber3 = vyber3;
}


 void oznameni2(int silawifi3 = 0, int stavbluetooth3 = 0, int stavbaterie3 = 0, const char* oznameni3) {
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.drawLine(0, 11, 128, 11);

  u8g2.drawStr(0,0,oznameni3);


  u8g2.drawLine(111, 0, 125, 0);
  u8g2.drawLine(111, 9, 125, 9);
  u8g2.drawLine(111, 0, 125, 0);
  u8g2.drawLine(111, 9, 111, 0);
  u8g2.drawLine(125, 8, 125, 1);
  u8g2.drawLine(125, 7, 125, 2);


 // switch (tavbaterie3){}




  }