mirror of
				https://github.com/digistump/DigistumpArduino.git
				synced 2025-11-03 13:04:48 -08:00 
			
		
		
		
	switch to setup for Arduino Boards Manager
This commit is contained in:
		@@ -0,0 +1,236 @@
 | 
			
		||||
// UTouch_ButtonTest (C)2010-2012 Henning Karlsen
 | 
			
		||||
// web: http://www.henningkarlsen.com/electronics
 | 
			
		||||
//
 | 
			
		||||
// This program is a quick demo of how create and use buttons.
 | 
			
		||||
//
 | 
			
		||||
// This program requires the UTFT library.
 | 
			
		||||
//
 | 
			
		||||
// It is assumed that the display module is connected to an
 | 
			
		||||
// appropriate shield or that you know how to change the pin 
 | 
			
		||||
// numbers in the setup.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <UTFT.h>
 | 
			
		||||
#include <UTouch.h>
 | 
			
		||||
 | 
			
		||||
// Declare which fonts we will be using
 | 
			
		||||
extern uint8_t BigFont[];
 | 
			
		||||
 | 
			
		||||
// Uncomment the next two lines for the Arduino 2009/UNO
 | 
			
		||||
//UTFT        myGLCD(ITDB24D,19,18,17,16);   // Remember to change the model parameter to suit your display module!
 | 
			
		||||
//UTouch      myTouch(15,10,14,9,8);
 | 
			
		||||
 | 
			
		||||
// Uncomment the next two lines for the Arduino Mega
 | 
			
		||||
UTFT        myGLCD(ITDB32S, 38,39,40,41);   // Remember to change the model parameter to suit your display module!
 | 
			
		||||
UTouch      myTouch(6,5,4,3,2);
 | 
			
		||||
 | 
			
		||||
int x, y;
 | 
			
		||||
char stCurrent[20]="";
 | 
			
		||||
int stCurrentLen=0;
 | 
			
		||||
char stLast[20]="";
 | 
			
		||||
 | 
			
		||||
/*************************
 | 
			
		||||
**   Custom functions   **
 | 
			
		||||
*************************/
 | 
			
		||||
 | 
			
		||||
void drawButtons()
 | 
			
		||||
{
 | 
			
		||||
// Draw the upper row of buttons
 | 
			
		||||
  for (x=0; x<5; x++)
 | 
			
		||||
  {
 | 
			
		||||
    myGLCD.setColor(0, 0, 255);
 | 
			
		||||
    myGLCD.fillRoundRect (10+(x*60), 10, 60+(x*60), 60);
 | 
			
		||||
    myGLCD.setColor(255, 255, 255);
 | 
			
		||||
    myGLCD.drawRoundRect (10+(x*60), 10, 60+(x*60), 60);
 | 
			
		||||
    myGLCD.printNumI(x+1, 27+(x*60), 27);
 | 
			
		||||
  }
 | 
			
		||||
// Draw the center row of buttons
 | 
			
		||||
  for (x=0; x<5; x++)
 | 
			
		||||
  {
 | 
			
		||||
    myGLCD.setColor(0, 0, 255);
 | 
			
		||||
    myGLCD.fillRoundRect (10+(x*60), 70, 60+(x*60), 120);
 | 
			
		||||
    myGLCD.setColor(255, 255, 255);
 | 
			
		||||
    myGLCD.drawRoundRect (10+(x*60), 70, 60+(x*60), 120);
 | 
			
		||||
    if (x<4)
 | 
			
		||||
      myGLCD.printNumI(x+6, 27+(x*60), 87);
 | 
			
		||||
  }
 | 
			
		||||
  myGLCD.print("0", 267, 87);
 | 
			
		||||
// Draw the lower row of buttons
 | 
			
		||||
  myGLCD.setColor(0, 0, 255);
 | 
			
		||||
  myGLCD.fillRoundRect (10, 130, 150, 180);
 | 
			
		||||
  myGLCD.setColor(255, 255, 255);
 | 
			
		||||
  myGLCD.drawRoundRect (10, 130, 150, 180);
 | 
			
		||||
  myGLCD.print("Clear", 40, 147);
 | 
			
		||||
  myGLCD.setColor(0, 0, 255);
 | 
			
		||||
  myGLCD.fillRoundRect (160, 130, 300, 180);
 | 
			
		||||
  myGLCD.setColor(255, 255, 255);
 | 
			
		||||
  myGLCD.drawRoundRect (160, 130, 300, 180);
 | 
			
		||||
  myGLCD.print("Enter", 190, 147);
 | 
			
		||||
  myGLCD.setBackColor (0, 0, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void updateStr(int val)
 | 
			
		||||
{
 | 
			
		||||
  if (stCurrentLen<20)
 | 
			
		||||
  {
 | 
			
		||||
    stCurrent[stCurrentLen]=val;
 | 
			
		||||
    stCurrent[stCurrentLen+1]='\0';
 | 
			
		||||
    stCurrentLen++;
 | 
			
		||||
    myGLCD.setColor(0, 255, 0);
 | 
			
		||||
    myGLCD.print(stCurrent, LEFT, 224);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    myGLCD.setColor(255, 0, 0);
 | 
			
		||||
    myGLCD.print("BUFFER FULL!", CENTER, 192);
 | 
			
		||||
    delay(500);
 | 
			
		||||
    myGLCD.print("            ", CENTER, 192);
 | 
			
		||||
    delay(500);
 | 
			
		||||
    myGLCD.print("BUFFER FULL!", CENTER, 192);
 | 
			
		||||
    delay(500);
 | 
			
		||||
    myGLCD.print("            ", CENTER, 192);
 | 
			
		||||
    myGLCD.setColor(0, 255, 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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*************************
 | 
			
		||||
**  Required functions  **
 | 
			
		||||
*************************/
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
// Initial setup
 | 
			
		||||
  myGLCD.InitLCD();
 | 
			
		||||
  myGLCD.clrScr();
 | 
			
		||||
 | 
			
		||||
  myTouch.InitTouch();
 | 
			
		||||
  myTouch.setPrecision(PREC_MEDIUM);
 | 
			
		||||
 | 
			
		||||
  myGLCD.setFont(BigFont);
 | 
			
		||||
  myGLCD.setBackColor(0, 0, 255);
 | 
			
		||||
  drawButtons();  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  while (true)
 | 
			
		||||
  {
 | 
			
		||||
    if (myTouch.dataAvailable())
 | 
			
		||||
    {
 | 
			
		||||
      myTouch.read();
 | 
			
		||||
      x=myTouch.getX();
 | 
			
		||||
      y=myTouch.getY();
 | 
			
		||||
      
 | 
			
		||||
      if ((y>=10) && (y<=60))  // Upper row
 | 
			
		||||
      {
 | 
			
		||||
        if ((x>=10) && (x<=60))  // Button: 1
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(10, 10, 60, 60);
 | 
			
		||||
          updateStr('1');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=70) && (x<=120))  // Button: 2
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(70, 10, 120, 60);
 | 
			
		||||
          updateStr('2');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=130) && (x<=180))  // Button: 3
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(130, 10, 180, 60);
 | 
			
		||||
          updateStr('3');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=190) && (x<=240))  // Button: 4
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(190, 10, 240, 60);
 | 
			
		||||
          updateStr('4');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=250) && (x<=300))  // Button: 5
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(250, 10, 300, 60);
 | 
			
		||||
          updateStr('5');
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if ((y>=70) && (y<=120))  // Center row
 | 
			
		||||
      {
 | 
			
		||||
        if ((x>=10) && (x<=60))  // Button: 6
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(10, 70, 60, 120);
 | 
			
		||||
          updateStr('6');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=70) && (x<=120))  // Button: 7
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(70, 70, 120, 120);
 | 
			
		||||
          updateStr('7');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=130) && (x<=180))  // Button: 8
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(130, 70, 180, 120);
 | 
			
		||||
          updateStr('8');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=190) && (x<=240))  // Button: 9
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(190, 70, 240, 120);
 | 
			
		||||
          updateStr('9');
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=250) && (x<=300))  // Button: 0
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(250, 70, 300, 120);
 | 
			
		||||
          updateStr('0');
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if ((y>=130) && (y<=180))  // Upper row
 | 
			
		||||
      {
 | 
			
		||||
        if ((x>=10) && (x<=150))  // Button: Clear
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(10, 130, 150, 180);
 | 
			
		||||
          stCurrent[0]='\0';
 | 
			
		||||
          stCurrentLen=0;
 | 
			
		||||
          myGLCD.setColor(0, 0, 0);
 | 
			
		||||
          myGLCD.fillRect(0, 224, 319, 239);
 | 
			
		||||
        }
 | 
			
		||||
        if ((x>=160) && (x<=300))  // Button: Enter
 | 
			
		||||
        {
 | 
			
		||||
          waitForIt(160, 130, 300, 180);
 | 
			
		||||
          if (stCurrentLen>0)
 | 
			
		||||
          {
 | 
			
		||||
            for (x=0; x<stCurrentLen+1; x++)
 | 
			
		||||
            {
 | 
			
		||||
              stLast[x]=stCurrent[x];
 | 
			
		||||
            }
 | 
			
		||||
            stCurrent[0]='\0';
 | 
			
		||||
            stCurrentLen=0;
 | 
			
		||||
            myGLCD.setColor(0, 0, 0);
 | 
			
		||||
            myGLCD.fillRect(0, 208, 319, 239);
 | 
			
		||||
            myGLCD.setColor(0, 255, 0);
 | 
			
		||||
            myGLCD.print(stLast, LEFT, 208);
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            myGLCD.setColor(255, 0, 0);
 | 
			
		||||
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
 | 
			
		||||
            delay(500);
 | 
			
		||||
            myGLCD.print("            ", CENTER, 192);
 | 
			
		||||
            delay(500);
 | 
			
		||||
            myGLCD.print("BUFFER EMPTY", CENTER, 192);
 | 
			
		||||
            delay(500);
 | 
			
		||||
            myGLCD.print("            ", CENTER, 192);
 | 
			
		||||
            myGLCD.setColor(0, 255, 0);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,350 @@
 | 
			
		||||
// UTouch_Calibration (C)2012 Henning Karlsen
 | 
			
		||||
// web: http://www.henningkarlsen.com/electronics
 | 
			
		||||
//
 | 
			
		||||
// This program can be used to calibrate the touchscreen
 | 
			
		||||
// of the display modules.
 | 
			
		||||
// This program requires the UTFT library and a touch
 | 
			
		||||
// screen module that is compatible with UTFT.
 | 
			
		||||
//
 | 
			
		||||
// It is assumed that the display module is connected to an
 | 
			
		||||
// appropriate shield or that you know how to change the pin 
 | 
			
		||||
// numbers in the setup.
 | 
			
		||||
//
 | 
			
		||||
// Instructions will be given on the display.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <UTFT.h>
 | 
			
		||||
#include <UTouch.h>
 | 
			
		||||
 | 
			
		||||
// Define the orientation of the touch screen. Further 
 | 
			
		||||
// information can be found in the instructions.
 | 
			
		||||
#define TOUCH_ORIENTATION  PORTRAIT
 | 
			
		||||
 | 
			
		||||
// Declare which fonts we will be using
 | 
			
		||||
extern uint8_t SmallFont[];
 | 
			
		||||
 | 
			
		||||
// Uncomment the next two lines for the Arduino 2009/UNO
 | 
			
		||||
//UTFT        myGLCD(ITDB24D,19,18,17,16);   // Remember to change the model parameter to suit your display module!
 | 
			
		||||
//UTouch      myTouch(15,10,14,9,8);
 | 
			
		||||
 | 
			
		||||
// Uncomment the next two lines for the Arduino Mega
 | 
			
		||||
UTFT        myGLCD(ITDB32S,38,39,40,41);   // Remember to change the model parameter to suit your display module!
 | 
			
		||||
UTouch      myTouch(6,5,4,3,2);
 | 
			
		||||
 | 
			
		||||
// ************************************
 | 
			
		||||
// DO NOT EDIT ANYTHING BELOW THIS LINE
 | 
			
		||||
// ************************************
 | 
			
		||||
uint32_t cx, cy;
 | 
			
		||||
uint32_t rx[10], ry[10];
 | 
			
		||||
uint32_t clx, crx, cty, cby;
 | 
			
		||||
float px, py;
 | 
			
		||||
int dispx, dispy, text_y_center;
 | 
			
		||||
uint32_t calx, caly, cals;
 | 
			
		||||
char buf[13];
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  myGLCD.InitLCD();
 | 
			
		||||
  myGLCD.clrScr();
 | 
			
		||||
  myGLCD.setFont(SmallFont);
 | 
			
		||||
 | 
			
		||||
  myTouch.InitTouch(TOUCH_ORIENTATION);
 | 
			
		||||
  myTouch.setPrecision(PREC_LOW);
 | 
			
		||||
  dispx=myGLCD.getDisplayXSize();
 | 
			
		||||
  dispy=myGLCD.getDisplayYSize();
 | 
			
		||||
  text_y_center=(dispy/2)-6;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void drawCrossHair(int x, int y)
 | 
			
		||||
{
 | 
			
		||||
  myGLCD.drawRect(x-10, y-10, x+10, y+10);
 | 
			
		||||
  myGLCD.drawLine(x-5, y, x+5, y);
 | 
			
		||||
  myGLCD.drawLine(x, y-5, x, y+5);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void readCoordinates()
 | 
			
		||||
{
 | 
			
		||||
  int iter = 2000;
 | 
			
		||||
  int cnt = 0;
 | 
			
		||||
  uint32_t tx=0;
 | 
			
		||||
  uint32_t ty=0;
 | 
			
		||||
  boolean OK = false;
 | 
			
		||||
  
 | 
			
		||||
  while (OK == false)
 | 
			
		||||
  {
 | 
			
		||||
    myGLCD.setColor(255, 255, 255);
 | 
			
		||||
    myGLCD.print("*  PRESS  *", CENTER, text_y_center);
 | 
			
		||||
    while (myTouch.dataAvailable() == false) {}
 | 
			
		||||
    myGLCD.print("*  HOLD!  *", CENTER, text_y_center);
 | 
			
		||||
    while ((myTouch.dataAvailable() == true) && (cnt<iter))
 | 
			
		||||
    {
 | 
			
		||||
      myTouch.read();
 | 
			
		||||
      if (!((myTouch.TP_X==65535) || (myTouch.TP_Y==65535)))
 | 
			
		||||
      {
 | 
			
		||||
        tx += myTouch.TP_X;
 | 
			
		||||
        ty += myTouch.TP_Y;
 | 
			
		||||
        cnt++;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (cnt>=iter)
 | 
			
		||||
    {
 | 
			
		||||
      OK = true;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      tx = 0;
 | 
			
		||||
      ty = 0;
 | 
			
		||||
      cnt = 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  cx = tx / iter;
 | 
			
		||||
  cy = ty / iter;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void calibrate(int x, int y, int i)
 | 
			
		||||
{
 | 
			
		||||
  myGLCD.setColor(255, 255, 255);
 | 
			
		||||
  drawCrossHair(x,y);
 | 
			
		||||
  myGLCD.setBackColor(255, 0, 0);
 | 
			
		||||
  readCoordinates();
 | 
			
		||||
  myGLCD.setColor(255, 255, 255);
 | 
			
		||||
  myGLCD.print("* RELEASE *", CENTER, text_y_center);
 | 
			
		||||
  myGLCD.setColor(80, 80, 80);
 | 
			
		||||
  drawCrossHair(x,y);
 | 
			
		||||
  rx[i]=cx;
 | 
			
		||||
  ry[i]=cy;
 | 
			
		||||
  while (myTouch.dataAvailable() == true)
 | 
			
		||||
  {
 | 
			
		||||
    myTouch.read();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void waitForTouch()
 | 
			
		||||
{
 | 
			
		||||
  while (myTouch.dataAvailable() == true)
 | 
			
		||||
  {
 | 
			
		||||
    myTouch.read();
 | 
			
		||||
  }
 | 
			
		||||
  while (myTouch.dataAvailable() == false) {}
 | 
			
		||||
  while (myTouch.dataAvailable() == true)
 | 
			
		||||
  {
 | 
			
		||||
    myTouch.read();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void toHex(uint32_t num)
 | 
			
		||||
{
 | 
			
		||||
  buf[0] = '0';
 | 
			
		||||
  buf[1] = 'x';
 | 
			
		||||
  buf[10] = 'U';
 | 
			
		||||
  buf[11] = 'L';
 | 
			
		||||
  buf[12] = 0;
 | 
			
		||||
  for (int zz=9; zz>1; zz--)
 | 
			
		||||
  {
 | 
			
		||||
    if ((num & 0xF) > 9)
 | 
			
		||||
      buf[zz] = (num & 0xF) + 55;
 | 
			
		||||
    else
 | 
			
		||||
      buf[zz] = (num & 0xF) + 48;
 | 
			
		||||
    num=num>>4;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void startup()
 | 
			
		||||
{
 | 
			
		||||
  myGLCD.setColor(255, 0, 0);
 | 
			
		||||
  myGLCD.fillRect(0, 0, dispx-1, 13);
 | 
			
		||||
  myGLCD.setColor(255, 255, 255);
 | 
			
		||||
  myGLCD.setBackColor(255, 0, 0);
 | 
			
		||||
  myGLCD.drawLine(0, 14, dispx-1, 14);
 | 
			
		||||
  myGLCD.print("UTouch Calibration", CENTER, 1);
 | 
			
		||||
  myGLCD.setBackColor(0, 0, 0);
 | 
			
		||||
 | 
			
		||||
  if (dispx==220)
 | 
			
		||||
  {  
 | 
			
		||||
    myGLCD.print("Use a stylus or something", LEFT, 30);
 | 
			
		||||
    myGLCD.print("similar to touch as close", LEFT, 42);
 | 
			
		||||
    myGLCD.print("to the center of the", LEFT, 54);
 | 
			
		||||
    myGLCD.print("highlighted crosshair as", LEFT, 66);
 | 
			
		||||
    myGLCD.print("possible. Keep as still as", LEFT, 78);
 | 
			
		||||
    myGLCD.print("possible and keep holding", LEFT, 90);
 | 
			
		||||
    myGLCD.print("until the highlight is", LEFT, 102);
 | 
			
		||||
    myGLCD.print("removed. Repeat for all", LEFT, 114);
 | 
			
		||||
    myGLCD.print("crosshairs in sequence.", LEFT, 126);
 | 
			
		||||
    myGLCD.print("Touch screen to continue", CENTER, 162);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    myGLCD.print("INSTRUCTIONS", CENTER, 30);
 | 
			
		||||
    myGLCD.print("Use a stylus or something similar to", LEFT, 50);
 | 
			
		||||
    myGLCD.print("touch as close to the center of the", LEFT, 62);
 | 
			
		||||
    myGLCD.print("highlighted crosshair as possible. Keep", LEFT, 74);
 | 
			
		||||
    myGLCD.print("as still as possible and keep holding", LEFT, 86);
 | 
			
		||||
    myGLCD.print("until the highlight is removed. Repeat", LEFT, 98);
 | 
			
		||||
    myGLCD.print("for all crosshairs in sequence.", LEFT, 110);
 | 
			
		||||
 | 
			
		||||
    myGLCD.print("Further instructions will be displayed", LEFT, 134);
 | 
			
		||||
    myGLCD.print("when the calibration is complete.", LEFT, 146);
 | 
			
		||||
 | 
			
		||||
    myGLCD.print("Do NOT use your finger as a calibration", LEFT, 170);
 | 
			
		||||
    myGLCD.print("stylus or the result WILL BE imprecise.", LEFT, 182);
 | 
			
		||||
 | 
			
		||||
    myGLCD.print("Touch screen to continue", CENTER, 226);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  waitForTouch();
 | 
			
		||||
  myGLCD.clrScr();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void done()
 | 
			
		||||
{
 | 
			
		||||
  myGLCD.clrScr();
 | 
			
		||||
  myGLCD.setColor(255, 0, 0);
 | 
			
		||||
  myGLCD.fillRect(0, 0, dispx-1, 13);
 | 
			
		||||
  myGLCD.setColor(255, 255, 255);
 | 
			
		||||
  myGLCD.setBackColor(255, 0, 0);
 | 
			
		||||
  myGLCD.drawLine(0, 14, dispx-1, 14);
 | 
			
		||||
  myGLCD.print("UTouch Calibration", CENTER, 1);
 | 
			
		||||
  myGLCD.setBackColor(0, 0, 0);
 | 
			
		||||
  
 | 
			
		||||
  if (dispx==220)
 | 
			
		||||
  {  
 | 
			
		||||
    myGLCD.print("To use the new calibration", LEFT, 30);
 | 
			
		||||
    myGLCD.print("settings you must edit the", LEFT, 42);
 | 
			
		||||
    myGLCD.setColor(160, 160, 255);
 | 
			
		||||
    myGLCD.print("UTouchCD.h", LEFT, 54);
 | 
			
		||||
    myGLCD.setColor(255, 255, 255);
 | 
			
		||||
    myGLCD.print("file and change", 88, 54);
 | 
			
		||||
    myGLCD.print("the following values. The", LEFT, 66);
 | 
			
		||||
    myGLCD.print("values are located right", LEFT, 78);
 | 
			
		||||
    myGLCD.print("below the opening comment.", LEFT, 90);
 | 
			
		||||
    myGLCD.print("CAL_X", LEFT, 110);
 | 
			
		||||
    myGLCD.print("CAL_Y", LEFT, 122);
 | 
			
		||||
    myGLCD.print("CAL_S", LEFT, 134);
 | 
			
		||||
    toHex(calx);
 | 
			
		||||
    myGLCD.print(buf, 75, 110);
 | 
			
		||||
    toHex(caly);
 | 
			
		||||
    myGLCD.print(buf, 75, 122);
 | 
			
		||||
    toHex(cals);
 | 
			
		||||
    myGLCD.print(buf, 75, 134);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {  
 | 
			
		||||
    myGLCD.print("CALIBRATION COMPLETE", CENTER, 30);
 | 
			
		||||
    myGLCD.print("To use the new calibration", LEFT, 50);
 | 
			
		||||
    myGLCD.print("settings you must edit the", LEFT, 62);
 | 
			
		||||
    myGLCD.setColor(160, 160, 255);
 | 
			
		||||
    myGLCD.print("UTouchCD.h", LEFT, 74);
 | 
			
		||||
    myGLCD.setColor(255, 255, 255);
 | 
			
		||||
    myGLCD.print("file and change", 88, 74);
 | 
			
		||||
    myGLCD.print("the following values.", LEFT, 86);
 | 
			
		||||
    myGLCD.print("The values are located right", LEFT, 98);
 | 
			
		||||
    myGLCD.print("below the opening comment in", LEFT, 110);
 | 
			
		||||
    myGLCD.print("the file.", LEFT, 122);
 | 
			
		||||
    myGLCD.print("CAL_X", LEFT, 150);
 | 
			
		||||
    myGLCD.print("CAL_Y", LEFT, 162);
 | 
			
		||||
    myGLCD.print("CAL_S", LEFT, 174);
 | 
			
		||||
 | 
			
		||||
    toHex(calx);
 | 
			
		||||
    myGLCD.print(buf, 75, 150);
 | 
			
		||||
    toHex(caly);
 | 
			
		||||
    myGLCD.print(buf, 75, 162);
 | 
			
		||||
    toHex(cals);
 | 
			
		||||
    myGLCD.print(buf, 75, 174);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  startup();
 | 
			
		||||
  
 | 
			
		||||
  myGLCD.setColor(80, 80, 80);
 | 
			
		||||
  drawCrossHair(dispx-11, 10);
 | 
			
		||||
  drawCrossHair(dispx/2, 10);
 | 
			
		||||
  drawCrossHair(10, 10);
 | 
			
		||||
  drawCrossHair(dispx-11, dispy/2);
 | 
			
		||||
  drawCrossHair(10, dispy/2);
 | 
			
		||||
  drawCrossHair(dispx-11, dispy-11);
 | 
			
		||||
  drawCrossHair(dispx/2, dispy-11);
 | 
			
		||||
  drawCrossHair(10, dispy-11);
 | 
			
		||||
  myGLCD.setColor(255, 255, 255);
 | 
			
		||||
  myGLCD.setBackColor(255, 0, 0);
 | 
			
		||||
  myGLCD.print("***********", CENTER, text_y_center-12);
 | 
			
		||||
  myGLCD.print("***********", CENTER, text_y_center+12);
 | 
			
		||||
 | 
			
		||||
  calibrate(10, 10, 0);
 | 
			
		||||
  calibrate(10, dispy/2, 1);
 | 
			
		||||
  calibrate(10, dispy-11, 2);
 | 
			
		||||
  calibrate(dispx/2, 10, 3);
 | 
			
		||||
  calibrate(dispx/2, dispy-11, 4);
 | 
			
		||||
  calibrate(dispx-11, 10, 5);
 | 
			
		||||
  calibrate(dispx-11, dispy/2, 6);
 | 
			
		||||
  calibrate(dispx-11, dispy-11, 7);
 | 
			
		||||
  
 | 
			
		||||
  if (TOUCH_ORIENTATION == LANDSCAPE)
 | 
			
		||||
    cals=(long(dispx-1)<<12)+(dispy-1);
 | 
			
		||||
  else
 | 
			
		||||
    cals=(long(dispy-1)<<12)+(dispx-1);
 | 
			
		||||
 | 
			
		||||
  if (TOUCH_ORIENTATION == PORTRAIT)
 | 
			
		||||
    px = abs(((float(rx[2]+rx[4]+rx[7])/3)-(float(rx[0]+rx[3]+rx[5])/3))/(dispy-20));  // PORTRAIT
 | 
			
		||||
  else
 | 
			
		||||
    px = abs(((float(rx[5]+rx[6]+rx[7])/3)-(float(rx[0]+rx[1]+rx[2])/3))/(dispy-20));  // LANDSCAPE
 | 
			
		||||
 | 
			
		||||
  if (TOUCH_ORIENTATION == PORTRAIT)
 | 
			
		||||
  {
 | 
			
		||||
    clx = (((rx[0]+rx[3]+rx[5])/3));  // PORTRAIT
 | 
			
		||||
    crx = (((rx[2]+rx[4]+rx[7])/3));  // PORTRAIT
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    clx = (((rx[0]+rx[1]+rx[2])/3));  // LANDSCAPE
 | 
			
		||||
    crx = (((rx[5]+rx[6]+rx[7])/3));  // LANDSCAPE
 | 
			
		||||
  }
 | 
			
		||||
  if (clx<crx)
 | 
			
		||||
  {
 | 
			
		||||
    clx = clx - (px*10);
 | 
			
		||||
    crx = crx + (px*10);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    clx = clx + (px*10);
 | 
			
		||||
    crx = crx - (px*10);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  if (TOUCH_ORIENTATION == PORTRAIT)
 | 
			
		||||
    py = abs(((float(ry[5]+ry[6]+ry[7])/3)-(float(ry[0]+ry[1]+ry[2])/3))/(dispx-20));  // PORTRAIT
 | 
			
		||||
  else
 | 
			
		||||
    py = abs(((float(ry[0]+ry[3]+ry[5])/3)-(float(ry[2]+ry[4]+ry[7])/3))/(dispx-20));  // LANDSCAPE
 | 
			
		||||
 | 
			
		||||
  if (TOUCH_ORIENTATION == PORTRAIT)
 | 
			
		||||
  {
 | 
			
		||||
    cty = (((ry[5]+ry[6]+ry[7])/3));  // PORTRAIT
 | 
			
		||||
    cby = (((ry[0]+ry[1]+ry[2])/3));  // PORTRAIT
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    cty = (((ry[0]+ry[3]+ry[5])/3));  // LANDSCAPE
 | 
			
		||||
    cby = (((ry[2]+ry[4]+ry[7])/3));  // LANDSCAPE
 | 
			
		||||
  }
 | 
			
		||||
  if (cty<cby)
 | 
			
		||||
  {
 | 
			
		||||
    cty = cty - (py*10);
 | 
			
		||||
    cby = cby + (py*10);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    cty = cty + (py*10);
 | 
			
		||||
    cby = cby - (py*10);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  calx = (long(clx)<<14) + long(crx);
 | 
			
		||||
  caly = (long(cty)<<14) + long(cby);
 | 
			
		||||
  if (TOUCH_ORIENTATION == LANDSCAPE)
 | 
			
		||||
    cals = cals + (1L<<31);
 | 
			
		||||
 | 
			
		||||
  done();
 | 
			
		||||
  while(true) {}
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,48 @@
 | 
			
		||||
// UTouch_QuickDraw (C)2010-2012 Henning Karlsen
 | 
			
		||||
// web: http://www.henningkarlsen.com/electronics
 | 
			
		||||
//
 | 
			
		||||
// This program is a quick demo of how to use the library.
 | 
			
		||||
//
 | 
			
		||||
// This program requires the UTFT library.
 | 
			
		||||
//
 | 
			
		||||
// It is assumed that the display module is connected to an
 | 
			
		||||
// appropriate shield or that you know how to change the pin 
 | 
			
		||||
// numbers in the setup.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <UTFT.h>
 | 
			
		||||
#include <UTouch.h>
 | 
			
		||||
 | 
			
		||||
// Uncomment the next two lines for the Arduino 2009/UNO
 | 
			
		||||
//UTFT        myGLCD(ITDB24D,19,18,17,16);   // Remember to change the model parameter to suit your display module!
 | 
			
		||||
//UTouch      myTouch(15,10,14,9,8);
 | 
			
		||||
 | 
			
		||||
// Uncomment the next two lines for the Arduino Mega
 | 
			
		||||
UTFT        myGLCD(ITDB32S, 38,39,40,41);   // Remember to change the model parameter to suit your display module!
 | 
			
		||||
UTouch      myTouch(6,5,4,3,2);
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  myGLCD.InitLCD();
 | 
			
		||||
  myGLCD.clrScr();
 | 
			
		||||
 | 
			
		||||
  myTouch.InitTouch();
 | 
			
		||||
  myTouch.setPrecision(PREC_MEDIUM);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop()
 | 
			
		||||
{
 | 
			
		||||
  long x, y;
 | 
			
		||||
  
 | 
			
		||||
  while (myTouch.dataAvailable() == true)
 | 
			
		||||
  {
 | 
			
		||||
    myTouch.read();
 | 
			
		||||
    x = myTouch.getX();
 | 
			
		||||
    y = myTouch.getY();
 | 
			
		||||
    if ((x!=-1) and (y!=-1))
 | 
			
		||||
    {
 | 
			
		||||
      myGLCD.drawPixel (x, y);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user