Toto je má konečná verze maturitního projektu

Dependencies:   mbed mbed-rtos UTouch_vyrobek UniGraphic

display.cpp

Committer:
smejky
Date:
2022-01-16
Revision:
10:0176705be216
Parent:
9:d1385f7171af
Child:
11:4ca8388080c6

File content as of revision 10:0176705be216:

#include "display.h"
#include "rtos.h"

UTouch touch(D4,D9,D3,D2,D5);//clk,chip_select,MOSI,miso,irq
ILI9341 spi(SPI_8,320000000,PTD2,PTD3,PTD1,PTC12, PTC3, PTC2, "TFT",240,320);// mosi, miso, sclk, chip_select, reset, dc
DigitalOut my_green(LED2);
DigitalOut my_red(LED4);
DigitalOut my_blue(LED3);
DigitalOut led2(LED2);
Thread thread;
PwmOut br(D10);

float lcd_jas = 0.50f;
int jas[] = {Green,Red};
int jas_s = 2;
int jazyk_s = 0;
int cas_hodiny = 0;
int cas_minuty = 0;
int cas_nastavit = 1037059200;
int time_on = 1037074920;
int time_off = 1037075100;
int lang = 0;
char minutka[32];
char hodinka[32];
char buffer[32];
char jazyk [4][150] = {
                         "Czech",
                         "English",
                         " Set Time",
                         "Brightness"
                     };   
char en[4][150] = {
                         "Czech",
                         "English",
                         " Set Time",
                         "Brightness"
                     };
char cz[4][150] = {
                         "Cestina",
                         "Anglictina",
                         "Nastavit cas",
                         "   Jas"
                     };



void hold(){
    int i = touch.DataAvailable();
     while (i){
              i = touch.DataAvailable();
              }
    
    }


void led2_thread()
{
    while (true) {
        led2 = !led2;
        Thread::wait(1000);
    }
}


/*
 v ILI9341.cpp zmeneny framerate ze 70 na 100, toto pomohlo problemu blikání displeje
 velikost fotky pro čudlik 180x70
x0 = od leveho horniho rohu(240max) y=0 od leveho horniho rohu x1 = od pravého spodniho rohu(240max) mel by byt vetsi nez x0 y1 = od pravého spodniho rohu mel by byt vetsi nez y0

4x doprava jas pro cudliky v menu


*/


void grafika(unsigned short int press = 0){  
    int spodni_pravy[] = {239,200,320,240,Black};
      
      
     switch(press)
{
    case 1:
        spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch);
        spi.Bitmap(274,72,46,42,(unsigned char*)gImage_cudlik_otoc);             // pravy
        spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek);
        spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek);           //pravy 
        
        break;
    case 2:
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_cudlik);// levy
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek);
        break;
    case 7: //zrusit
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit);
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek);
        break;
    case 9: //potvrdit
        spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch);
        spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit);             
        spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek);
        spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek);           
        break;
    case 3:
        spi.Bitmap(0,200,80,40,(unsigned char*)gImage_spodni_levy);
        break;
    case 4:
        spi.Bitmap(80,200,80,40,(unsigned char*)gImage_stredni_levy);        
        break;        
    case 5:
        spi.Bitmap(160,200,80,40,(unsigned char*)gImage_stredni_pravy);
        break;        
    case 6:
        spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]);                //pravy kraj spodni
        break;           
    case 8:
        spi.Bitmap(0,200,80,40,(unsigned char*)gImage_spodni_levy);    
        break;
        
    default:
   spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi);
    
    spi.Bitmap(274,0,46,36,(unsigned char*)gImage_vypln);//pravy
    spi.Bitmap(274,165,46,36,(unsigned char*)gImage_vypln);//pravy
    spi.Bitmap(0,0,46,36,(unsigned char*)gImage_vypln);//levy
    spi.Bitmap(0,165,46,36,(unsigned char*)gImage_vypln);//levy
    
        spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch);
        spi.Bitmap(274,72,46,42,(unsigned char*)gImage_cudlik_otoc);             // pravy
        spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek);
        spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek);           //pravy   
        
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_cudlik);// levy
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek);
          

    //spi.Bitmap(160,200,80,40,(unsigned char*)gImage_stredni_levy);                                        
    spi.Bitmap(0,200,80,40,(unsigned char*)gImage_spodni_levy);
    spi.Bitmap(80,200,80,40,(unsigned char*)gImage_stredni_levy);
    spi.Bitmap(160,200,80,40,(unsigned char*)gImage_stredni_pravy);           //stred pravy spodni
    spi.fillrect(spodni_pravy[0],spodni_pravy[1],spodni_pravy[2],spodni_pravy[3],spodni_pravy[4]);                //pravy kraj spodni
}  
}

void malovani(){
    
    while(1==1)
    {
      if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         unsigned short int touch_y = touch.GetX();
         unsigned short int  touch_x = touch.GetY();
         touch_x = touch_x - 10;
         touch_y = touch_y + 10;
         spi.pixel(touch_x,touch_y,Blue);           
        }
     }
    }
}

/*
else if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy [1])){
              R_is_pressed = 1;
              spi.fillrect(pravy[0],pravy[1],pravy[2],pravy[3],pravy[4]);
               wait(0.1);   
            } 

*/





void Button(int strana = 0){
    int pravy[] = {34,0,165,46}; //pravý čudlík
    int levy[] = {34,274,165,320}; //levý čudlík
    //int cudlik[] = {20,80,42,130,Orange}; //slider    nepovedeny projekt
    //int stred_cudliku[] = {30,105,Blue};  //střed čudliku
    int spodni_levy[] = {200,240,240,320}; // levy spodni cudlik
    int stredni_levy[] = {200,160,240,239}; //stred levy spodni cudlik
    int stredni_pravy[] = {200,80,240,158}; //stred pravy spodni cudlik
    int spodni_pravy[] = {200,0,240,77}; // pravy spodni cudlik
    
    int cudlik_1[] = {10,213,58,260};
    int cudlik_2[] = {10,137,58,184};



      
  
    while(1)
    {
      if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         
         
         unsigned short int touch_y = touch.GetX();  // 0-320
         unsigned short int  touch_x = touch.GetY(); // 0-240
         touch_x = touch_x - 5;
         touch_y = touch_y + 10;
         //spi.pixel(touch_x,touch_y,Blue);
         //printf("x %d ,y %d\r\n",touch_x,touch_y);
         
            //pravý čudlik
            if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){
            int m = strana;   
    switch(strana){
            case 0:
                m++;
            break;
            case 1:
                m++;
            break;
            default:
            m = 0;
   }
            //GRAFIKA**************************************************
            spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(274,72,46,42,(unsigned char*)gImage_cudlik_otoc_s);
            spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            hold();
              grafika(1);
              Menu(m);
               wait(0.2); 
            }
                   
            //pravý čudlik
            
            //levý čudlik 
            if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
            int m = strana;   
    switch(strana){
            case 1:
                m--;
            break;
            default:
            m = 1;       
   }
            //GRAFIKA**************************************************
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch_s);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_cudlik_s);// levy
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek_s);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            
            hold();
              grafika(2);
              wait(0.2);
              Menu(m);
            }  
            //levý čudlik

            //levý spodni čudlik
            if ((touch_x > spodni_levy[0]) && (touch_x < spodni_levy[2]) && (touch_y < spodni_levy[3]) && (touch_y > spodni_levy[1])){
            spi.Bitmap(0,200,80,40,(unsigned char*)gImage_spodni_levy_s);
              
            hold();
                
              grafika(9);
              grafika(8);
              grafika(7);
              nastaveni();
               wait(0.2);
            }  
            //levý spodni čudlik
            
            
            //stred levy spodni cudlik
            if ((touch_x > stredni_levy[0]) && (touch_x < stredni_levy[2]) && (touch_y < stredni_levy[3]) && (touch_y > stredni_levy[1])){

            
            spi.Bitmap(80,200,80,40,(unsigned char*)gImage_stredni_levy_s);

            
            thread.start(led2_thread);
            
            hold();
              grafika(4);
               wait(0.2);
            }
            //stred levy spodni cudlik

                        
            //stred pravy spodni cudlik
            if ((touch_x > stredni_pravy[0]) && (touch_x < stredni_pravy[2]) && (touch_y < stredni_pravy[3]) && (touch_y > stredni_pravy[1])){
            spi.Bitmap(160,200,80,40,(unsigned char*)gImage_stredni_pravy_s);
            
            thread.terminate();    
            hold();
              grafika(5);
               wait(0.2);
            }  
            //stred pravy spodni cudlik

            //kraj pravy spodni cudlik
            if ((touch_x > spodni_pravy[0]) && (touch_x < spodni_pravy[2]) && (touch_y < spodni_pravy[3]) && (touch_y > spodni_pravy[1])){
            
            hold();
            
            spi.locate(255,210);
            spi.printf("%s",buffer);
            
             // grafika(6);
               wait(0.2);
            } 
            //kraj pravy spodni cudlik
          
//MENU CUDLIKY**********************************************************************************************************************************************************************************
            //prvni
            if ((touch_x > cudlik_1[0]) && (touch_x < cudlik_1[2]) && (touch_y < cudlik_1[3]) && (touch_y > cudlik_1[1]) && (strana == 1)){
            spi.Bitmap(60,10,48,24,(unsigned char*)gImage_cudlik1s_vrch);
            spi.Bitmap(60,34,48,24,(unsigned char*)gImage_cudlik1s_spodek);
            hold();
            spi.Bitmap(60,10,48,24,(unsigned char*)gImage_cudlik1_vrch);
            spi.Bitmap(60,34,48,24,(unsigned char*)gImage_cudlik1_spodek);
            wait(0.2);
            grafika(7);
            grafika(9);
            Static();
            } 

            
            //prvni
          //druhy
            if ((touch_x > cudlik_2[0]) && (touch_x < cudlik_2[2]) && (touch_y < cudlik_2[3]) && (touch_y > cudlik_2[1]) && (strana == 1)){
            spi.Bitmap(60,10,48,24,(unsigned char*)gImage_cudlik1s_vrch);
            spi.Bitmap(60,34,48,24,(unsigned char*)gImage_cudlik1s_spodek);
            hold();
            spi.Bitmap(60,10,48,24,(unsigned char*)gImage_cudlik1_vrch);
            spi.Bitmap(60,34,48,24,(unsigned char*)gImage_cudlik1_spodek);
               wait(0.2);
           
            } 

            
            //druhy
                      
        }
      }
    }    
}





void Menu(int strana = 0){   
    switch(strana)
{
    case 1:
    spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi);
    
    
    //CUDLIKY*******************************************************************************
    //prvni rada
    spi.Bitmap(213,10,48,24,(unsigned char*)gImage_cudlik3_vrch);
    spi.Bitmap(213,34,48,24,(unsigned char*)gImage_cudlik3_spodek);
    
    spi.Bitmap(137,10,48,24,(unsigned char*)gImage_cudlik2_vrch);
    spi.Bitmap(137,34,48,24,(unsigned char*)gImage_cudlik2_spodek);

    spi.Bitmap(60,10,48,24,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(60,34,48,24,(unsigned char*)gImage_cudlik1_spodek);
    
    //prvni rada
    
    //druha rada
    spi.Bitmap(213,76,48,24,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(213,100,48,24,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(137,76,48,24,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(137,100,48,24,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(60,76,48,24,(unsigned char*)gImage_cudlik4_vrch);
    spi.Bitmap(60,100,48,24,(unsigned char*)gImage_cudlik4_spodek);
    // druha rada
    
    //treti rada
    spi.Bitmap(213,142,48,24,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(213,166,48,24,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(137,142,48,24,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(137,166,48,24,(unsigned char*)gImage_cudlik1_spodek);
    
    spi.Bitmap(60,142,48,24,(unsigned char*)gImage_cudlik1_vrch);
    spi.Bitmap(60,166,48,24,(unsigned char*)gImage_cudlik1_spodek);
    // treti rada
    
    //CUDLIKY*******************************************************************************

    strana = 1;
    Button(strana);
                
        break;
    default:
    spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi);
    strana = 0;
    Button(strana);
} 
    }

void Static(){
    int red1[] = {213,76,260,124};
    int green1[] = {137,76,184,124};
    int blue1[] = {60,76,107,124};
   
    
    int red[] = {76,213,124,260};
    int green[] = {76,137,124,184};
    int blue[] = {76,60,124,107};


    int pravy[] = {34,0,165,46}; //pravý čudlík
    int levy[] = {34,274,165,320}; //levý čudlík
    
    spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi);
    spi.fillrect(red1[0],red1[1],red1[2],red1[3],Red); 
    spi.fillrect(green1[0],green1[1],green1[2],green1[3],Green);
    spi.fillrect(blue1[0],blue1[1],blue1[2],blue1[3],Blue); 
    
    
    int r = 1;
    int g = 1;
    int b = 1;
    while(1)
    {
      if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         unsigned short int touch_y = touch.GetX();  // 0-320
         unsigned short int  touch_x = touch.GetY(); // 0-240
         
          //pravý čudlik
            if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){
            
            //GRAFIKA**************************************************
            spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit_s);
            spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            hold();
            my_red = r;
            my_green = g;
            my_blue = b;
              grafika(1);
              grafika(2);
              Menu();
            wait(0.2); 
            }       
            //pravý čudlik
            
            //levý čudlik 
            if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
            //GRAFIKA**************************************************
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch_s);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit_s);// levy
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek_s);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            
            hold();
              grafika(2);
              grafika(1);
              wait(0.2);
              Menu();
            }  
            //levý čudlik
          
if((touch_x > red[0]) && (touch_x < red[2]) && (touch_y < red[3]) && (touch_y > red[1])){
            hold();   
            r = !r;
            printf("%d",r); 
            wait(0.2);     
}

if((touch_x > green[0]) && (touch_x < green[2]) && (touch_y < green[3]) && (touch_y > green[1])){  
            hold(); 
            g = !g;
            printf("%d",g); 
            wait(0.2);     
}

if((touch_x > blue[0]) && (touch_x < blue[2]) && (touch_y < blue[3]) && (touch_y > blue[1])){
            hold();   
            b = !b;
            printf("%d",b); 
            wait(0.2);     
}

         }
    } 
  }

}

void nastaveni(){   
    int pravy[] = {34,0,165,46}; //pravý čudlík
    int levy[] = {34,274,165,320}; //levý čudlík
    int i = 0;

        
    spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi);
    int check1[] = {66,10,96,40};
    int check2[] = {66,56,96,86};

    int prvni[] = {46,0,273,46}; //prvni čudlík
    int druhy[] = {46,46,273,92}; //druhy čudlík
    int treti[] = {46,92,273,138}; //treti čudlík
    int ctvrty[] = {46,138,273,184}; //treti čudlík    
    
    
    spi.background(MojeSeda);
    spi.fillrect(prvni[0],prvni[1],prvni[2],prvni[3],MojeSeda); //prvni
    spi.rect(prvni[0],prvni[1],prvni[2],prvni[3],White); //prvni
    spi.set_font((unsigned char*) Arial28x28);
    spi.locate(140,14);
    spi.printf(jazyk[0]);
    
    spi.fillrect(druhy[0],druhy[1],druhy[2],druhy[3],MojeSeda); //druhy
    spi.rect(druhy[0],druhy[1],druhy[2],druhy[3],White); //druhy
    spi.locate(140,60);
    spi.printf(jazyk[1]);
    
switch(lang)
{
            case 1:
            spi.fillrect(check1[0],check1[1],check1[2],check1[3],Green);
            spi.fillrect(check2[0],check2[1],check2[2],check2[3],Red);
            break;
            default:
            spi.fillrect(check1[0],check1[1],check1[2],check1[3],Red);
            spi.fillrect(check2[0],check2[1],check2[2],check2[3],Green);
}    
    
    
    spi.fillrect(treti[0],treti[1],treti[2],treti[3],MojeSeda); //treti
    spi.rect(treti[0],treti[1],treti[2],treti[3],White); //treti
    spi.locate(90,106);
    spi.printf(jazyk[2]);

    spi.fillrect(ctvrty[0],ctvrty[1],ctvrty[2],ctvrty[3],MojeSeda); //ctvrty
    spi.rect(ctvrty[0],ctvrty[1],ctvrty[2],ctvrty[3],White); //ctvrty
    spi.locate(95,152);
    spi.printf(jazyk[3]); 
     
        
    while(1){
if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         unsigned short int touch_y = touch.GetX();  // 0-320
         unsigned short int  touch_x = touch.GetY(); // 0-240
         
          //pravý čudlik
            if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){
            
            //GRAFIKA**************************************************
            spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit_s);
            spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            hold();
             switch(jazyk_s)
{
            case 1:
                    while(i < 4){
                        strcpy(jazyk[i], cz[i]);
                        i++;
                        }
            break;
            default:
                    while(i < 4){
                        strcpy(jazyk[i], en[i]);
                        i++;
                        }
}            
            i = 0;
              grafika(1);
              grafika(2);
              Menu();
            wait(0.2); 
            }       
            //pravý čudlik
            
            //levý čudlik 
            if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
            //GRAFIKA**************************************************
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch_s);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit_s);// levy
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek_s);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            
            hold();

              grafika(2);
              grafika(1);
              Menu();
            wait(0.2);
            }  
            //levý čudlik
          
if((touch_x > prvni[1]) && (touch_x < prvni[3]) && (touch_y < prvni[2]) && (touch_y > prvni[0])){
            hold();
            jazyk_s = 1;
            lang = jazyk_s; 
            spi.fillrect(check1[0],check1[1],check1[2],check1[3],Green);
            spi.fillrect(check2[0],check2[1],check2[2],check2[3],Red);
            wait(0.2);     
}
if((touch_x > druhy[1]) && (touch_x < druhy[3]) && (touch_y < druhy[2]) && (touch_y > druhy[0])){
            hold();
            jazyk_s = 0; 
            lang = jazyk_s; 
            spi.fillrect(check1[0],check1[1],check1[2],check1[3],Red);
            spi.fillrect(check2[0],check2[1],check2[2],check2[3],Green);
            wait(0.2);     
}
if((touch_x > treti[1]) && (touch_x < treti[3]) && (touch_y < treti[2]) && (touch_y > treti[0])){
            hold();
            nastavit_hodiny();  
}
if((touch_x > ctvrty[1]) && (touch_x < ctvrty[3]) && (touch_y < ctvrty[2]) && (touch_y > ctvrty[0])){
            hold();
            brightness();  
}


         }
    }
        }
    
}


void brightness(){
    spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi);
    int pravy[] = {34,0,165,46}; //pravý čudlík
    int levy[] = {34,274,165,320}; //levý čudlík
    
    int p10t[] = {229,52,264,147};
    int p30t[] = {186,52,221,147};
    int p50t[] = {143,52,178,147};
    int p70t[] = {100,52,135,147};
    int p90t[] = {57,52,92,147};  
       
    int p10[] = {57,52,92,147};
    int p30[] = {100,52,135,147};
    int p50[] = {143,52,178,147};
    int p70[] = {186,52,221,147};
    int p90[] = {229,52,264,147};
     
    switch(jas_s){
    case 0:
    spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]);
    spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[1]);
    spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[1]);
    spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[1]);
    spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]);
    break;
    case 1:
    spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]);
    spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]);
    spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[1]);
    spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[1]);
    spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]);
    break;
    case 2:
    spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]);
    spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]);
    spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[0]);
    spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[1]);
    spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]);
    break;
    case 3:
    spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]);
    spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]);
    spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[0]);
    spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[0]);
    spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[1]);
    break;
    case 4:
    spi.fillrect(p10[0],p10[1],p10[2],p10[3],jas[0]);
    spi.fillrect(p30[0],p30[1],p30[2],p30[3],jas[0]);
    spi.fillrect(p50[0],p50[1],p50[2],p50[3],jas[0]);
    spi.fillrect(p70[0],p70[1],p70[2],p70[3],jas[0]);
    spi.fillrect(p90[0],p90[1],p90[2],p90[3],jas[0]);
    break;
    default:
    printf("err");
    
   }
    
    while(1){
if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         unsigned short int touch_y = touch.GetX();  // 0-320
         unsigned short int  touch_x = touch.GetY(); // 0-240
         
          //pravý čudlik
            if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){
            
            //GRAFIKA**************************************************
            spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit_s);
            spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            hold();
             
              grafika(9);
              br.write(lcd_jas);
              nastaveni();
            wait(0.2); 
            }       
            //pravý čudlik
            
            //levý čudlik 
            if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
            //GRAFIKA**************************************************
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch_s);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit_s);// levy
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek_s);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            
            hold();
            lcd_jas = 0.00f;
              grafika(7);
              nastaveni();
            wait(0.2);
            }  
            //levý čudlik
            
if((touch_x > p10t[1]) && (touch_x < p10t[3]) && (touch_y < p10t[2]) && (touch_y > p10t[0])){
        hold();
        jas_s = 0;
        lcd_jas = 0.10f;
        brightness();
        
}

if((touch_x > p30t[1]) && (touch_x < p30t[3]) && (touch_y < p30t[2]) && (touch_y > p30t[0])){
        hold();
        jas_s = 1;
        lcd_jas = 0.30f;
        brightness();
}
if((touch_x > p50t[1]) && (touch_x < p50t[3]) && (touch_y < p50t[2]) && (touch_y > p50t[0])){
        hold();
        jas_s = 2;
        lcd_jas = 0.50f;
        brightness();
        
}
if((touch_x > p70t[1]) && (touch_x < p70t[3]) && (touch_y < p70t[2]) && (touch_y > p70t[0])){
        hold();
        jas_s = 3;
        lcd_jas = 0.70f;
        brightness();
}
if((touch_x > p90t[1]) && (touch_x < p90t[3]) && (touch_y < p90t[2]) && (touch_y > p90t[0])){
        hold();
        jas_s = 4;
        lcd_jas = 0.90f;
        brightness();
}


    }
}
}
}



void nastavit_hodiny(){
    int pravy[] = {34,0,165,46}; //pravý čudlík
    int levy[] = {34,274,165,320}; //levý čudlík
    
    int up1[] = {172,28,258,57};  
    int down1[] = {172,142,258,171};  
    
    int up2[] = {62,28,148,57};  
    int down2[] = {62,142,148,171};    
    
    cas_hodiny = atoi(hodinka); 
    cas_minuty = atoi(minutka); 
    
    
    int h1 = cas_hodiny / 10; 
    int h2 = cas_hodiny % 10;
   
    char cisla[10][3] = {
                         "0",
                         "1",
                         "2",
                         "3",
                         "4",
                         "5",
                         "6",
                         "7",
                         "8",
                         "9"
                     };
   
    int m1 = cas_minuty / 10;
    int m2 = cas_minuty % 10;
    
    int blue1[] = {71,65,249,134};

    spi.Bitmap(46,0,228,200,(unsigned char*)gImage_pozadi);
    spi.Bitmap(62,28,86,29,(unsigned char*)gImage_nahoru);
    spi.Bitmap(62,142,86,29,(unsigned char*)gImage_dolu);
        
    spi.Bitmap(172,28,86,29,(unsigned char*)gImage_nahoru);
    spi.Bitmap(172,142,86,29,(unsigned char*)gImage_dolu); 
    
    

    spi.fillrect(blue1[0],blue1[1],blue1[2],blue1[3],MojeSeda);
    
    spi.set_font((unsigned char*) Arial48x47);
    spi.background(MojeSeda);
    spi.locate(80,80);
    spi.printf(cisla[h1]);
    spi.locate(110,80);
    spi.printf(cisla[h2]);
    spi.locate(155,80);
    spi.printf(":");
    spi.locate(189,80);
    spi.printf(cisla[m1]);
    spi.locate(219,80);
    spi.printf(cisla[m2]);
    
     
    while(1){
if (touch.DataAvailable())
      {
        if(touch.Read())
        {
         unsigned short int touch_y = touch.GetX();  // 0-320
         unsigned short int  touch_x = touch.GetY(); // 0-240
         
          //pravý čudlik
            if ((touch_x > pravy[0]) && (touch_x < pravy[2]) && (touch_y < pravy[3]) && (touch_y > pravy[1])){
            
            //GRAFIKA**************************************************
            spi.Bitmap(274,34,46,38,(unsigned char*)gImage_vrch_s);
            spi.Bitmap(274,72,46,42,(unsigned char*)gImage_potvrdit_s);
            spi.Bitmap(274,114,46,26,(unsigned char*)gImage_spodek_s);
            spi.Bitmap(274,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            hold();
             thread.terminate();
             cas_nastavit = 1037059200 + (cas_hodiny * 3600) +  (cas_minuty * 60);
             thread.start(hodiny);
              grafika(9);
              nastaveni();
            wait(0.2); 
            }       
            //pravý čudlik
            
            //levý čudlik 
            if ((touch_x > levy[0]) && (touch_x < levy[2]) && (touch_y < levy[3]) && (touch_y > levy[1])){
            //GRAFIKA**************************************************
        spi.Bitmap(0,34,46,38,(unsigned char*)gImage_vrch_s);
        spi.Bitmap(0,72,46,42,(unsigned char*)gImage_zrusit_s);// levy
        spi.Bitmap(0,114,46,26,(unsigned char*)gImage_spodek_s);
        spi.Bitmap(0,140,46,26,(unsigned char*)gImage_spodek_s);
            //GRAFIKA**************************************************
            
            hold();
            
            
            
              grafika(7);
              nastaveni();
            wait(0.2);
            }  
            //levý čudlik
if((touch_x > up1[1]) && (touch_x < up1[3]) && (touch_y < up1[2]) && (touch_y > up1[0])){
            spi.Bitmap(62,28,86,29,(unsigned char*)gImage_nahoru_s);
     while ((touch.DataAvailable()) && (h2 < 10)){
            h2++;
            cas_hodiny++;
            if(cas_hodiny == 24){
            cas_hodiny = 0;
            }
            if(h2 == 10){
            h2 = 0;
            h1++;
            }
            if((h1 == 2)&&(h2 == 4)){
            h2 = 0;
            h1 = 0;
            }
             
              spi.locate(80,80);
              spi.printf(cisla[h1]);
              spi.locate(110,80);
              spi.printf(cisla[h2]); 

              
              wait(0.1); 
    }
            spi.Bitmap(62,28,86,29,(unsigned char*)gImage_nahoru);     
}
if((touch_x > down1[1]) && (touch_x < down1[3]) && (touch_y < down1[2]) && (touch_y > down1[0])){
            spi.Bitmap(62,142,86,29,(unsigned char*)gImage_dolu_s); 
    while ((touch.DataAvailable()) && (h2 < 10)){
            h2--;
            if((h2 < 0)&&(h1 == 0)){
            h2 = 3;
            h1 = 2;
            }
            if(h2 < 0){
            h2 = 9;
            h1--;
            }
            cas_hodiny--;
            if(cas_hodiny < 0){
            cas_hodiny = 23;
            }
              spi.locate(80,80);
              spi.printf(cisla[h1]);
              spi.locate(110,80);
              spi.printf(cisla[h2]);
            wait(0.1);
    }
            spi.Bitmap(62,142,86,29,(unsigned char*)gImage_dolu); 
} 
if((touch_x > up2[1]) && (touch_x < up2[3]) && (touch_y < up2[2]) && (touch_y > up2[0])){
            spi.Bitmap(172,28,86,29,(unsigned char*)gImage_nahoru_s);
    while ((touch.DataAvailable()) && (m2 < 10)){
            m2++;
            cas_minuty++;
            if(cas_minuty == 60){
            cas_minuty = 0;
            }
            if((m1 == 5)&&(m2 == 10)){
            m2 = 0;
            m1 = 0;
            }
            if(m2 == 10){
            m2 = 0;
            m1++;
            }
           
              spi.locate(189,80);
              spi.printf(cisla[m1]);
              spi.locate(219,80);
              spi.printf(cisla[m2]);
            wait(0.1);
    }
            
            spi.Bitmap(172,28,86,29,(unsigned char*)gImage_nahoru);    
}
if((touch_x > down2[1]) && (touch_x < down2[3]) && (touch_y < down2[2]) && (touch_y > down2[0])){
            spi.Bitmap(172,142,86,29,(unsigned char*)gImage_dolu_s); 
    while ((touch.DataAvailable()) && (m2 < 10)){
            m2--;
            if((m2 < 0)&&(m1 == 0)){
            m2 = 9;
            m1 = 5;
            }
            if(m2 < 0){
            m2 = 9;
            m1--;
            }
            cas_minuty--;
            if(cas_minuty < 0){
            cas_minuty = 59;
            }
              spi.locate(189,80);
              spi.printf(cisla[m1]);
              spi.locate(219,80);
              spi.printf(cisla[m2]);
            wait(0.1);
    }
            
            spi.Bitmap(172,142,86,29,(unsigned char*)gImage_dolu);   
} 
            

    }
}
}
}




void hodiny(){
        set_time(cas_nastavit);
    while(1){
        time_t seconds = time(NULL);
        //seconds = seconds + 7200;
        if(seconds == time_on){
            printf("ON\r\n");
            }
        if(seconds == time_off){
            printf("OFF\r\n");
            }
        strftime(buffer, 32, "%R", localtime(&seconds));
        strftime(hodinka, 32, "%H", localtime(&seconds));
        strftime(minutka, 32, "%M", localtime(&seconds));
        printf("%s\r\n",buffer);
        Thread::wait(1000);
        }
    }

main(){

my_red = 1;
my_green = 1;
my_blue = 1;
    spi.set_orientation(3);
    spi.FastWindow(true);
    touch.InitTouch();
    touch.SetPrecision(PREC_EXTREME);
    spi.background(Black);
    spi.foreground(White);
    spi.cls();


    grafika();
    
    br.period_us(1000);
    br.write(lcd_jas);

    
 /*   nastavit_hodiny();
    thread.start(hodiny);*/
    Button();

    
}




/*  fail projekty
          //slider  
            if ((touch_x > cudlik[0]) && (touch_x < cudlik[2]) && (touch_y > cudlik[1]) && (touch_y < cudlik[3]) && (pressure > 0)){
            
            
        //if je udelany tady pro nastavení minima a maxima
           if ((touch_x > 25) && (touch_x < 140)){           
            
            unsigned short int y0 = cudlik[1];
            unsigned short int y1 = cudlik[3];      
            unsigned short int x_zadelavani_chyby = cudlik[0];
            unsigned short int x0 = x_zadelavani_chyby - 8;
              
              //printf("%d\r\n",touch_x);                  
              stred_cudliku[0] = touch_x;
              
              cudlik[0] = stred_cudliku[0] - 10;
              cudlik[1] = stred_cudliku[1] - 25;
              cudlik[2] = stred_cudliku[0] + 10;
              cudlik[3] = stred_cudliku[1] + 25;
              
                              
               
          if (touch_x > 34){    
              x0 = x_zadelavani_chyby + 8;
                spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green);
              
              }else{
spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black);
                  }
              
         if (touch_x < 34){    
              spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Black);
              
              }else{
                x0 = x_zadelavani_chyby + 8;
                spi.fillrect(x0,y0,x_zadelavani_chyby,y1,Green);
                  }     
              spi.fillrect(cudlik[0],cudlik[1],cudlik[2],cudlik[3],cudlik[4]);
              
              
              
              }
            } 
            
            //slider */