void foto()
{ myGLCD.clrScr();
  myGLCD.setColor(VGA_WHITE);
  myGLCD.setBackColor(VGA_BLACK);
  // myGLCD.setFont(BigFont);
  myGLCD.setFont(Ubuntubold);
  myGLCD.print("FOTO RAMKA ", CENTER, 150);
  myGLCD.setFont(BigFont);
  if (myTouch.dataAvailable())
  { myTouch.read();
    delay(1000);
    if (myTouch.dataAvailable())
    { myTouch.read();
    }
  }
  comand();
  displayBR(0);
  // analogWrite(7, 0);//яркость экрана
  randomSeed(analogRead(0));
  int dispage = 0, loopcount = 0;
  while (1)
  {
    if (dispage == 0)
    { myFiles.load(0, 0, 800, 480, "foto/0.raw" , 32, 0);
      displayBR(1);

      myGLCD.setColor(VGA_WHITE);
      myGLCD.setBackColor(VGA_BLACK);
      // myGLCD.print("This is the Homepage!", CENTER,441);

      // myGLCD.setColor(VGA_RED);
      // myGLCD.print("Clearing in " + String(x) + " seconds!", CENTER, 460);
      comand();
      displayBR(0);
      dispage = 1;

    }
    if (dispage == 1)
    { myFiles.load(0, 0, 800, 480, "foto/1.raw" , 32, 0);
      displayBR(1);
      randomSeed(analogRead(0));
      myGLCD.setColor(VGA_WHITE);
      myGLCD.setBackColor(VGA_BLACK);
      // myGLCD.print("This is image 1", 0, 0);
      dispage = random(2, 6) + 2;
      comand();
      displayBR(0);

    }
    if (dispage == 2)
    {
      myFiles.load(0, 0, 800, 480, "foto/2.raw" , 32, 0);
      displayBR(1);
      myGLCD.setColor(VGA_WHITE);
      myGLCD.setBackColor(VGA_BLACK);
      // myGLCD.print("This is image 2", 0, 0);
      dispage = random(1, 8);
      comand();
      displayBR(0);

    }
    if (dispage == 3)
    {
      myFiles.load(0, 0, 800, 480, "foto/3.raw" , 32, 0);
      displayBR(1);
      myGLCD.setColor(VGA_WHITE);
      myGLCD.setBackColor(VGA_BLACK);
      // myGLCD.print("This is image 3", 0, 0);
      dispage = random(6) + 3;
      comand();
      displayBR(0);

    }
    if (dispage == 4)
    {
      myFiles.load(0, 0, 800, 480, "foto/4.raw" , 32, 0);
      displayBR(1);
      myGLCD.setColor(VGA_WHITE);
      myGLCD.setBackColor(VGA_BLACK);
      // myGLCD.print("This is image 4", 0, 0);
      dispage = random(3) + 5;
      comand();
      displayBR(0);

    }
    if (dispage == 5)
    {
      myFiles.load(0, 0, 800, 480, "foto/5.raw" , 32, 0);
      displayBR(1);
      myGLCD.setColor(VGA_WHITE);
      myGLCD.setBackColor(VGA_BLACK);
      //  myGLCD.print("This is image 5", 0, 0);
      randomSeed(analogRead(0));
      dispage = random(6) - 1;
      comand();
      displayBR(0);

    }
    if (dispage == 6)
    {
      myFiles.load(0, 0, 800, 480, "foto/6.raw" , 32, 0);
      displayBR(1);
      myGLCD.setColor(VGA_WHITE);
      myGLCD.setBackColor(VGA_BLACK);
      //  myGLCD.print("This is image 6", 0, 0);
      dispage = random(5) + 2;
      comand();
      displayBR(0);

    }
    if (dispage == 7)
    {
      myFiles.load(0, 0, 800, 480, "foto/7.raw" , 32, 0);
      displayBR(1);
      // while (1);
      dispage = random(9) - 1;

      delay(5000);
      displayBR(0);

    }
    if (dispage == 8)
    {
      myFiles.load(0, 0, 800, 480, "foto/8.raw" , 32, 0);
      displayBR(1);
      // while (1);
      dispage = random(7);
      comand();
      displayBR(0);

    }
    loopcount++;
    if (loopcount > 10) dispage = 1;
    if ( dispage > 8) dispage = 8;
    if ( dispage < 0) dispage = 2;
    Serial.println(dispage);
    randomSeed(analogRead(0));



  }
}


//**************************** ЯРКОСТЬ ЭКРАНА *************************************
void displayBR(bool j)
{
  if (j == 1)
  {
    for (int i = 0; i < 200; i = i + 2 )
    {
      analogWrite(7, i);//яркость экрана
      delay(50);
    }
  }
  else
  { for (int i = 200; i >= 0; i = i - 2 )
    {
      analogWrite(7, i);//яркость экрана
      delay(50);
    }
  }
}
//***********опрoс клавиш и тача***************
void comand()
{
  int st = 0;
  while (st < 100) {
    delay(100);
    but();
    st++;
    if (st > 50)break;
    if (valBtnL || valBtnR || valBtnT || valBtnD)
    { valBtnPause = 0;
      analogWrite(7, 200);//яркость экран
      exit_menu = 1;

    }
    if (myTouch.dataAvailable())
    { myTouch.read();
      exit_menu = 1;
      analogWrite(7, 200);//яркость экрана

    }
  }
  if (exit_menu == 1)
  {
    exit_menu = 0;
    loop();
  }
}
