Why are my character strings printing as number values?

Hi there,

Notice the drawCallPage(); function that tries to draw the number pad page. The navigation and presses are working good but rather than printing the proper characters/words onto the buttons it is printing number values.

picture posted below here for context...

Please help me see my error:

//SET LIBRARIES
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>

//SET FONTS
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Fonts/FreeSansBold18pt7b.h>
#include <FreeDefaultFonts.h>

#define FO9 &FreeSans9pt7b
#define BO9 &FreeSansBold9pt7b
#define FO12 &FreeSans12pt7b
#define BO12 &FreeSansBold12pt7b
#define FO18 &FreeSans18pt7b
#define BO18 &FreeSansBold18pt7b
#define DIG7 &FreeSevenSegNumFont

//SET COLOURS & PARAMS
#define BLK 0x0000
#define WHT 0xFFFF
#define RED 0xF800
#define GRN 0x07E0
#define BLU 0x001F
#define YEL 0xFFE0
#define CYN 0x07FF
#define MAG 0xF81F
#define SCR 0x10A2
#define BUT 0x2945
#define FRM 0x632C

#define RAD 8

//SET SCREEN
MCUFRIEND_kbv disp;

//SET TOUCH PANEL
#define MINPRESSURE 100
#define MAXPRESSURE 1000
#define BOOP 100

#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

//touch sensitivity for X
#define TS_MINX 895
#define TS_MAXX 129

//touch sensitivity for Y
#define TS_MINY 71
#define TS_MAXY 907

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

//Check whether to press or not
boolean pressed(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t px, int16_t py)
{
    if((px > x1 && px < x2) && (py > y1 && py < y2))
    {
        return true;  
    } 
    else
    {
        return false;  
    }
 }


//SET BUTTON ARRAYS

// button perams: |start X|start Y|width X|height Y|end X|end Y|font|text colour|cursor X|cursor Y|label|numerator|

typedef struct button{  

  uint16_t topX;
  uint16_t topY;
  uint16_t sizX;
  uint16_t sizY;
  uint16_t botX;
  uint16_t botY;
  uint16_t butFont;
  uint16_t texCol;
  uint16_t curX;
  uint16_t curY;
  uint8_t butLab;
  uint16_t butVal;
}

button;

// button list:

button butSet[16] =
{//start X, start Y,  size X, size Y, end X,  end Y,  font, text colour,  cursor X, cursor Y, label,            numerator,          
    10,     110,      220,    60,     229,    169,    BO12, WHT,          48,       148,      "Patch Recall",   0,
    10,     180,      220,    60,     229,    229,    BO12, WHT,          41,       218,      "MIDI Settings",  0,                     
    10,     250,      220,    60,     229,    309,    BO12, WHT,          43,       288,      "LED Settings",   0,

    6,      76,       72,     55,     77,     130,    BO18, FRM,          32,       116,      "1",              1,
    84,     76,       72,     55,     155,    130,    BO18, FRM,          110,      116,      "2",              2,
    162,    76,       72,     55,     233,    130,    BO18, FRM,          188,      116,      "3",              3,
    6,      137,      72,     55,     77,     191,    BO18, FRM,          32,       177,      "4",              4,
    84,     137,      72,     55,     155,    191,    BO18, FRM,          110,      177,      "5",              5,
    162,    137,      72,     55,     233,    191,    BO18, FRM,          188,      177,      "6",              6,
    6,      198,      72,     55,     77,     252,    BO18, FRM,          32,       238,      "7",              7,
    84,     198,      72,     55,     155,    252,    BO18, FRM,          110,      238,      "8",              8,
    162,    198,      72,     55,     233,    252,    BO18, FRM,          188,      238,      "9",              9,
    84,     259,      72,     55,     155,    313,    BO18, FRM,          110,      299,      "0",              0,
    162,    259,      72,     55,     233,    313,    BO18, FRM,          193,      299,      ".",              0,
    6,      259,      72,     55,     77,     313,    BO9,  RED,          23,       292,      "ESC",            0,
    162,    6,        72,     64,     233,    69,     BO9,  GRN,          173,      44,       "SEND",           0,
};

void wordUp(uint8_t dropWord, uint16_t typeX, uint16_t typeY, uint16_t dropFont, uint16_t fontCol){
  disp.setFont(dropFont);
  disp.setTextColor(fontCol);
  disp.setCursor(typeX, typeY);
  disp.print(dropWord);
}

//SET GLOBALS
char currentPage;


void setup(){
  
// Setup the LCD
  disp.begin(0x9341);
  disp.setRotation(0);
  disp.fillScreen(BLK);
  
  drawHomeScreen();
  currentPage = '0';
}

void loop(){
  
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE){
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, 239);
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, 319);

    if (currentPage == '0'){
      
      //goto caller
      if (pressed(10, 110, 229, 169, p.x, p.y)){
        disp.fillCircle(60, 60, 10, RED);
        currentPage = '1';
        disp.fillScreen(BLK);
        drawCallScreen();
        delay(BOOP);
      }
      
      //goto settings
      if (pressed(10, 180, 229, 239, p.x, p.y)){
        disp.fillCircle(60, 60, 10, YEL);
        delay(BOOP);
      }

      //goto LED
      if (pressed(10, 250, 229, 309, p.x, p.y)){
        disp.fillCircle(60, 60, 10, BLU);
        delay(BOOP);
      }

    }//page 0 end

    if (currentPage == '1'){
      
      //goto caller
      if (pressed(6, 259, 77, 313, p.x, p.y)){
        disp.fillCircle(60, 60, 10, RED);
        currentPage = '0';
        disp.fillScreen(BLK);
        drawHomeScreen();
        delay(BOOP);
      }
    
    }//page 1 end
    
  }//press end 

}//loop end


// ====== Custom Functions ======

//draw home screen
void drawHomeScreen(){
  disp.fillRect(10, 10, 220, 90, SCR);
  disp.fillRoundRect(10, 110, 220, 60, RAD, BUT);
  disp.fillRoundRect(10, 180, 220, 60, RAD, BUT);
  disp.fillRoundRect(10, 250, 220, 60, RAD, BUT);

  disp.drawRect(10, 10, 220, 90, FRM);
  disp.drawRoundRect(10, 110, 220, 60, RAD, FRM);
  disp.drawRoundRect(10, 180, 220, 60, RAD, FRM);
  disp.drawRoundRect(10, 250, 220, 60, RAD, FRM);

  disp.setFont(BO12);
  disp.setTextColor(WHT);
  disp.setCursor(48, 148);
  disp.print("Recall Patch");
  disp.setCursor(41, 218);
  disp.print("MIDI Settings");
  disp.setCursor(43, 288);
  disp.print("LED Settings");  
}

//draw MIDI caller screen
void drawCallScreen(){

  disp.fillRect(6, 6, 150, 64, SCR); //num screen
  disp.drawRect(6, 6, 150, 64, FRM); //frame screen

  uint16_t i;
  for(i=3; i<16; i++){
    disp.fillRoundRect(butSet[i].topX, butSet[i].topY, butSet[i].sizX, butSet[i].sizY, RAD, BUT);
    disp.drawRoundRect(butSet[i].topX, butSet[i].topY, butSet[i].sizX, butSet[i].sizY, RAD, FRM);
    wordUp(butSet[i].butLab, butSet[i].curX, butSet[i].curY, butSet[i].butFont, butSet[i].texCol);
  }

  disp.setFont(DIG7);
  disp.setTextColor(RED);
  disp.setCursor(27, 64);
  disp.print("00");

  disp.fillCircle(98, 58, 3, RED);
  
  disp.setCursor(105, 64);
  disp.print("0");
}

Where is the label ?? (It’s defined as a unit8_t, so a number)

You don’t need typedef in C++ just go with

 struct button {  
  uint16_t topX;
  uint16_t topY;
  uint16_t sizX;
  uint16_t sizY;
  uint16_t botX;
  uint16_t botY;
  uint16_t butFont;
  uint16_t texCol;
  uint16_t curX;
  uint16_t curY;
  const char* butLab;
  uint16_t butVal;
};

It's important to pay attention to compiler warnings

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.