Go Down

Topic: 3.2" LCD Display a Number enter from Numeric Keypad (Read 124 times) previous topic - next topic

snthool

Hello Forum
I am using arduino atmega2560 with non touch 3.2" 480*320 TFT LCD display interfaced with numeric keypad 4*4.
I have used following code to display the number enter through numeric keypad

#define LCD_CS A3
#define LCD_CD A2   
#define LCD_WR A1   
#define LCD_RD A0   

#define LCD_RESET A4

#define   BLACK           0x0000
#define   BLUE            0x001F
#define   RED             0xF800
#define   GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF

//#include "TFTLCD.h"
#include <Keypad.h>
#include <UTFT.h>
extern uint8_t SmallFont[];
const byte ROWS = 4;
const byte COLS = 4;
char buffer;
long lastUpdate = 0;
int x;

UTFT myGLCD(CTE32HR,38,39,40,41);

char keys[ROWS][COLS] =
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'},
 
};

byte rowPins[ROWS] = {6,7,8,9}; //connect to row pinouts
byte colPins[COLS] = {10,11,12,13}; //connect to column pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(void)
{
  Serial.begin(9600);
  Serial.println("8 Bit LCD test!");
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

}

void loop(void)
{
  char key = keypad.getKey();

  if (key != NO_KEY)
  {
    Serial.print(key);
    buffer=key;
  }
  /*testtext(BLACK);
   delay(1000); */
   
  if((millis() - lastUpdate) > 100)  // has it been >1 second since the last update?
  {
    testtext(BLACK);  // update display
    lastUpdate = millis();
  x=x+8;  // remember the time
  }

}
//int y = (10*x);
// for TFT screen display letters
void testtext(uint16_t color)
{
  myGLCD.fillScr(CYAN);
// myGLCD.setCursor(50, 20);
// myGLCD.setTextColor(RED);
//  myGLCD.setTextSize(2);
  myGLCD.print("HI TEXTS BELOW" , CENTER ,10);
 
 
//  myGLCD.setCursor(x, 50);
// myGLCD.setTextSize(4);
  myGLCD.print(buffer , CENTER, 30);

}

But when I have enter the number from keypad  display is showing some junk value.
Please suggest how to display the correct number enter from keypad.

david_prentice

First off.   Tidy up your code.   Remove obsolete lines.   Indent it nicely. (ctrl-T)
Then copy-paste it into a CODE window.   (top left icon)

I guess that you should get an Error for  myGLCD.print(buffer , CENTER, 30);
At least there would be a Warning.

Read the UTFT documentation to see what methods are available for printing char[], char, integer, floats.
Life is easier if you choose intuitive names for variables.  e.g char letter, char buffer[], char *str, ...

David.

snthool

Thanks David for your quick reply
I have tried with different printNumI  then it starts displaying its ASCII value, then I used ASCII to integer conversion function against it starts to display junk values. What could be a reasons?

david_prentice

#3
May 18, 2017, 08:36 am Last Edit: May 18, 2017, 09:24 am by david_prentice
What do do want to display?  printNumI will show "65" for the letter 'A'
There does not appear to be method for displaying a single char.   Only for char[ ]

So you should write your char to strbuffer[0] and NUL to strbuffer[1]
Then you can display the one-letter string in buffer with print(strbuffer, x, y)

UTFT has unintuitive methods.   Hey-ho,   that is the library that you have chosen.
Even more confusing.   The method for showing a char[ ] or String is called print() instead of printString().

Most Arduino libraries inherit from Stream and Print classes.   So you are used to the idea of an overloaded Serial.print()  working for char, byte,  int, long, float, char[ ], String ...   It all appears to work by magic.   You have to study the docs for Stream, Print, ... to see what is available.

UTFT does not inherit from any other classes.   So if the method is not declared in UTFT.h it does not exist.
This makes life easy to understand.   You just have to get your head around the peculiar set of methods.

David.

Edit.  While I was walking my dog,   I realised that you can convert anything to a String.   e.g. char letter;  ...   GLCD.print(String(letter));
I presume you are using a Mega.   So the extra bloat from String is no problem.

snthool


Go Up