按钮使用3.2 tft显示屏和arduino mega

时间:2017-02-09 17:53:36

标签: arduino

我正在尝试使用arduino mega在3.2 tft lcd上制作一个按钮,我按钮的代码工作。当点击开始测试时,它会将第一个屏幕菜单更改为下一个屏幕。我的代码如下发生这种情况但是当它移动到下一个屏幕时,按钮仍然在后台并且处于活动状态。我试图在按下按钮后删除按钮,这样我就可以在新屏幕上添加新按钮。

代码:

#include <UTFT.h>
#include <ITDB02_Touch.h>



// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSeqNumFont[];
             extern unsigned int bird01[0x41A];

   // Uncomment the next two lines for the ITDB02 Shield
   UTFT          myGLCD(SSD1289, 38, 39, 40, 41);
             ITDB02_Touch  myTouch(6, 5, 4, 3, 2);
          // Uncomment the next two lines for the ITDB02 Mega Shield
   //ITDB02        myGLCD(38,39,40,41);   // Remember to add ASPECT_16x9 if            you are using an ITDB02-3.2WC!
  //ITDB02_Touch  myTouch(6,5,4,3,2);

  int x, y;
  char stCurrent[20]="";
  int stCurrentLen=0;
  char stLast[20]="";
  char currentPage , selectedUnit;
  int page,pg;

  void setup(){
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();

  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_MEDIUM);

  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);

  drawHomeScreen();

  selectedUnit = '0';



  }







        // Draw a red frame while a button is touched
            void waitForIt(int x1, int y1, int x2, int y2)
                    {
                       myGLCD.setColor(255, 0, 0);
                        myGLCD.drawRoundRect (x1, y1, x2, y2);
                         while (myTouch.dataAvailable())
                           myTouch.read();
                           myGLCD.setColor(255, 255, 255);
                           myGLCD.drawRoundRect (x1, y1, x2, y2);
                       }





                     void loop (){           

                         if (myTouch.dataAvailable())
                             {
                               myTouch.read();
                               x=myTouch.getX();
                               y=myTouch.getY();



                               do{
         if ((x>=35) && (x<=285) && (y>=90) && ( y<=130) && (page = 1)) {
            waitForIt(35, 90, 285, 130);
            currentPage = "1";
            myGLCD.clrScr ();
            pg = 2;
            drawChipScreen();

             }
                   } while (pg<2);
   /*
   else {
   if((x>=35) && (x<=285) && (y>=190) && ( y<=230) ){
   myGLCD.clrScr ();
   drawHomeScreen();

   }
   }
  */
   }
   }


     void drawChipScreen()
      {


       myGLCD.clrScr();

       currentPage= '1';
       myGLCD.setFont(BigFont);
       myGLCD.setBackColor(16,167,103);
       myGLCD.print("Test Chip", CENTER, 10);  





      myGLCD.setBackColor(16,167,103);
      myGLCD.setColor(255,255,255);
      myGLCD.setFont(BigFont);
      myGLCD.print("Back", 5, 215);   

      if((x>=0) && (x<=10) && (y>=205) && (y<=235) )
       {
        waitForIt(0, 205, 10 , 235);

        }



       myGLCD.InitLCD(LANDSCAPE);

       myTouch.InitTouch(LANDSCAPE);
       myTouch.setPrecision(PREC_MEDIUM);

       myGLCD.setFont(BigFont);
       myGLCD.setBackColor(0, 0, 255);

       // Draw the upper row of buttons
        for (x=0; x<5; x++)
         {
         myGLCD.setColor(0, 0, 255);
         myGLCD.fillRoundRect (10+(x*60), 40, 60+(x*60), 80);
         myGLCD.setColor(255, 255, 255);
         myGLCD.drawRoundRect (10+(x*60), 40, 60+(x*60), 80);
         myGLCD.printNumI(x+1, 27+(x*60), 47);
         }



         }

         void drawHomeScreen () {

         myGLCD.setBackColor(0,0,0);
         myGLCD.setColor(255,255,255);
         myGLCD.setFont(BigFont);
         myGLCD.print("Testing 123", CENTER, 10);
         myGLCD.setColor(255,0,0);
         myGLCD.drawLine(0,32,319,32);
         myGLCD.setColor(255,255,255);
         myGLCD.setFont(SmallFont);
         myGLCD.print("by Smu Students", CENTER,41);
         myGLCD.setFont(BigFont);
         myGLCD.print("Select a type of test", CENTER, 64);

         myGLCD.setColor(16, 167, 103);
         myGLCD.fillRoundRect (35,90,285,130);
         myGLCD.setColor(255,255,255);
         myGLCD.drawRoundRect(35,90,285,130);
         myGLCD.setFont(BigFont);
         myGLCD.setBackColor(16,167,103);
         myGLCD.print("Regular Test", CENTER, 102);

         myGLCD.setColor(16, 167, 103);
         myGLCD.fillRoundRect (35,140,285,180);
         myGLCD.setColor(255,255,255);
         myGLCD.drawRoundRect(35,140,285,180);
          myGLCD.setFont(BigFont);
            myGLCD.setBackColor(16,167,103);
              myGLCD.print("Debug", CENTER, 152);
         pg = 1;
          }

0 个答案:

没有答案