Go Down

Topic: Can't print variable to screen (Read 280 times) previous topic - next topic

fulstop

iv recently started playing round with a touchscreen from sainsmart.
i can get most things to work as i expect.
but for some reason I just can't get it to print a variable on the screen.
i can print a word eg "hello" in its place, or a can set up the serial monitor and print the variable to that.
but if i try to print it to the screen i just get weird shapes coming up.
heres the code i have, its quite messy as iv been trying lots of different things to try to get it to work.
basically I'm trying to use touch buttons to increase or decrease a value, ill then use that value as a delay or something.
thanks in advance for any help

Code: [Select]
#include <UTFT.h>
#include <ITDB02_Touch.h>

// Declare which fonts we will be using
extern uint8_t BigFont[];

// 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 k =0;
int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";


  // the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  myGLCD.setColor(0, 255, 0); 
  myGLCD.print("count", 80, 180);
 
// Initial setup
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();

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

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

   {
    //^button
    myGLCD.setColor(0, 0, 0);
  myGLCD.fillRoundRect (10, 30, 60, 80);//button size
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (10, 30, 60, 80);
  myGLCD.print("UP", 25, 50);

  myGLCD.setColor(0, 0, 0);
  myGLCD.fillRoundRect (10, 90, 60, 140);//button size
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (10, 90, 80, 140);
  myGLCD.print("DOWN", 12, 107);

   myGLCD.setColor(0, 0, 0);
  myGLCD.fillRoundRect (140, 120, 200, 200);//button size
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (140, 120, 200, 200);


 
   myGLCD.setColor(0, 255, 0); 
       myGLCD.print("SPEED", 5, 0);
 
   }

   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 updateStr(int val)
{
  if (stCurrentLen<20)
  {
    stCurrent[stCurrentLen]=val;
    stCurrent[stCurrentLen+1]='\0';
    stCurrentLen++;
    myGLCD.setColor(0, 255, 0);
    myGLCD.print(stCurrent, LEFT, 224);
  }
}

void loop()
{
while (true)
  {
    if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
     
      if ((x>=10) && (x<=60))  // Upper row
      {
        if ((y>=30) && (y<=80))  // Button: 1
        {         
          waitForIt(10, 30, 60, 80);
          updateStr('1');
         
           k = k + 1;
           
        }
        if ((y>=90) && (y<=140))  // Button: 2
        {         
          waitForIt(10, 90, 60, 140);
          updateStr('2');
         
           k=k - 1;
        }

       
if (k>2)

{
digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
}
else
{
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW}
}
Serial.print(k);
myGLCD.print("       ",165,155);
       myGLCD.print(k, 165, 155);
      }     
      }     
      }     
      }

david_prentice

#1
Nov 25, 2016, 08:17 am Last Edit: Nov 25, 2016, 09:32 am by david_prentice
If you want to print the value of an integer,   UTFT has a method called printNumI().

Read the PDF that documents the UTFT methods.

David.

Edit.  corrected the method name

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy