I have a 3 ½ " touch screen like this one
Connected to an arduino mega.
I am altering this piece of software and getting good results
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
//CONTROLLER ili9481 ili9468, ili9488 hx8357, or r61581
//ID = 0x6814
// ALL Touch panels and wiring are DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341 (input pins)
//const int TS_LEFT = 912, TS_RT = 189, TS_TOP = 912, TS_BOT = 176;//portrait
//const int TS_LEFT = 912, TS_RT = 176, TS_TOP = 189, TS_BOT = 821;//landscape
const int TS_LEFT = 950, TS_RT = 206, TS_TOP = 189, TS_BOT = 921;//landscape
//this last calculation means touch is directly over drawn boxes.
//is this needed to correct different types of display? screen for my display is 480 x 320
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button on_btn, off_btn, top_left_btn, top_rt_btn, bot_left_btn, bot_rt_btn;
int pixel_x, pixel_y;
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
void setup(void)
{
Serial.begin(9600);
uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
Serial.println("Calibrate for your Touch Panel");
//if (ID == 0xD3D3) ID = 0x9486; // write-only shield
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
tft.begin(ID);
tft.setRotation(1); //0=portrait,1=landscape
tft.fillScreen(BLACK);
//on_btn.initButton(&tft, 60 ,200 , 100 , 40 , WHITE, CYAN,BLACK, "ON", 2 );
on_btn.initButton(&tft, 60 ,200 , 100 , 40 , WHITE, CYAN,BLACK, "ON", 2 );
// ( ? , in , down,width,height,border,bkgrnd,text, text,size)
// colour,colour,colour,
//319 is bottom row, 0 is left edge. Buttons(in and down above) number from centre of box
//put a spot in each corner
top_left_btn.initButton(&tft, 0 , 0 , 1 , 1 , WHITE, CYAN,BLACK, "", 2 );
bot_left_btn.initButton(&tft, 0 , 319 , 1 , 1 , WHITE, CYAN,BLACK, "", 2 );
top_rt_btn.initButton(&tft, 479 , 0 , 1 , 1 , WHITE, CYAN,BLACK, "", 2 );
bot_rt_btn.initButton(&tft, 479 , 319 , 1 , 1 , WHITE, CYAN, BLACK,"", 2 );
off_btn.initButton(&tft,180 ,200 ,100 , 40 , WHITE, CYAN , BLACK, "OFF", 2 );
on_btn.drawButton(false);
top_left_btn.drawButton(false);
bot_left_btn.drawButton(false);
top_rt_btn.drawButton(false);
bot_rt_btn.drawButton(false);
off_btn.drawButton(false);
// on_btn
tft.fillRect(40, 80, 160, 80, RED);
tft.drawCircle(260,240,60, RED);//from the left,from the top,dia,colour
tft.drawCircle(360,240,40, BLUE);
tft.fillCircle (360,120,40,RED);
//tft.bmpDraw(woof.bmp,360,120)
//tft.drawBitmap(360,120,*woof.bmp,25,25,RED);
tft.fillRect(240, 0, 1, 1, RED);//puts a red spot middle of top row.
tft.fillRect(240, 0, 1, 319, RED);//put a red line down the middle.
}
/* two buttons are quite simple
*/
void loop(void)
{
tft.drawLine(260, 20, 290, 20, RED);//in from left,down horiz length,vert length(line = 1,colour
//tft.drawLine(290, 20, 310, 30, BLACK);
//tft.drawLine(290, 20, 310, 20, RED);
//delay (500);
//tft.drawLine(290, 20, 310, 20, BLACK);
//tft.drawLine(290, 20, 310, 30, RED);
//delay (500);
{
bool down = Touch_getXY();
on_btn.press(down && on_btn.contains(pixel_x, pixel_y));
off_btn.press(down && off_btn.contains(pixel_x, pixel_y));
if (on_btn.justReleased()
)
{
on_btn.drawButton();//renews button background colour
tft.drawLine(290, 20, 310, 30, BLACK);//when on is released delete previous line
tft.drawLine(290, 20, 310, 20, RED);//draw new line. from in from left, down from top
// to in from left and down from top
}
if (on_btn.justPressed())
{
on_btn.drawButton(true);//deletes button background colour
tft.fillRect(40, 80, 160, 80, GREEN);
// in,down,width,height,colour
}
if (off_btn.justReleased())
{
off_btn.drawButton();//renews button background colour
tft.drawLine(290, 20, 310, 20, BLACK);//when on is released delete previous line
tft.drawLine(290, 20, 310, 30, RED);//draw new line. from in from left, down from top
} // to in from left and down from top.
}
if (off_btn.justPressed()) {
off_btn.drawButton(true);//deletes button background colour
tft.fillRect ( 40 , 80 , 160 , 80 , RED );
//box drawn from (top lft,bot lft,top rt,bot rt,bkgrnd colour
}
//tft.drawCircle(260,240,60, RED);//from the left,from the top,dia,colour
//delay (500);
//tft.drawCircle(260,240,60, BLACK);//from the left,from the top,dia,colour
//tft.drawCircle(240,240,60, RED);//from the left,from the top,dia,colour
//delay (500);
//tft.drawCircle(240,240,60, BLACK);//from the left,from the top,dia,colour
}
bool Touch_getXY(void)//Touch_getXY() updates global vars
{
TSPoint p = ts.getPoint();
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);
bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
if (pressed) {
pixel_x = map(p.y, TS_LEFT, TS_RT, 0, 480); //landscape
//pixel_x = map(p.y, LEFT=716, RT=591, 0, 480); //landscape
//pixel_x = map(p.x, TS_LEFT, TS_RT, 0, 320); //portrait
//TS_LEFT, TS_RT,
pixel_y = map(p.x, TS_TOP, TS_BOT, 0, 320);//landscape
//pixel_y = map(p.x, TOP=385, BOT=462, 0, 320);//landscape
//pixel_y = map(p.y, TS_TOP, TS_BOT, 0, 480);//portrait
//TS_TOP, TS_BOT,
}
return pressed;
}
I would like to download bitmap files to the screen but can't get Adafruit or MCUFRIEND libraries to do it
I have downloaded the UTFT libraries from here but the bitmap demo sketch asks for a different set of pins and doesn't conform to any I try, I just get a white screen.
Question can the UTFT demo be altered to work with my screen?
here is the sketch that I am trying to run
// UTFT_Bitmap
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// This program is a demo of the drawBitmap()-function.
//
// This demo was made to work on the 320x240 modules.
// Any other size displays may cause strange behaviour.
//
// This program requires the UTFT library.
//
#include <UTFT.h>
#include <avr/pgmspace.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];
// Set the pins to the correct ones for your development shield
// ------------------------------------------------------------
// Arduino Uno / 2009:
// -------------------
// Standard Arduino Uno/2009 shield : <display model>,A5,A4,A3,A2
// DisplayModule Arduino Uno TFT shield : <display model>,A5,A4,A3,A2
//
// Arduino Mega:
// -------------------
// Standard Arduino Mega/Due shield : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Mega : <display model>,38,39,40,41
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ITDB32S,A5,A4,A3,A2);
extern unsigned int info[0x400];
extern unsigned int icon[0x400];
extern unsigned int tux[0x400];
void setup()
{
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
}
It consists of this sketch plus 3 others icon.c tux.c and info.c
The program asks me to alter the pins to suit but there seems to be no similarity between the pins of the top sketch that works with XP = 6, XM = A2, YP = A1, YM = 7 and the bottom sketch UTFT myGLCD(ITDB32S,A5,A4,A3,A2);
Is it possible to get the bottom sketch to run and if so how?
Thanks,
Bob

