This is tft demo sketch i have it copied f this on myn arduino sketch 1.0.1:
#include <stdint.h>
#include <C:\Documents and Settings\wp\desktop\TouchScreen.h>
#include <C:\Documents and Settings\wp\desktop\TFT.h>
//Measured ADC values for (0,0) and (240-1,320-1)
//TS_MINX corresponds to ADC value when X = 0
//TS_MINY corresponds to ADC value when Y = 0
//TS_MAXX corresponds to ADC value when X = 240 -1
//TS_MAXY corresponds to ADC value when Y = 320 -1
static unsigned int TS_MINX, TS_MAXX, TS_MINY, TS_MAXY;
//Touch Screen Co-ordinate mapping register
static unsigned int MapX1, MapX2, MapY1, MapY2;
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// The 2.8" TFT Touch shield has 300 ohms across the X plate
/* Usage: TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Where, XP = X plus, YP = Y plus, XM = X minus and YM = Y minus */
//init TouchScreen port pins. This would be reinitialized in setup() based on the hardware detected.
TouchScreen ts = TouchScreen(17, A2, A1, 14, 300);
void setup(void)
{
Tft.init();//init TFT
initTouchScreenParameters(); //initializes Touch Screen parameters based on the detected TFT Touch Schield hardware
//Lines
Tft.drawLine(0,0,50,50,RED);//draw a 45degree red line point(0,0) to point(50,50)
Tft.drawVerticalLine(25,0,50,GREEN);//draw a vertical green line point(25,0) to point(25,50)
Tft.drawHorizontalLine(0,25,50,BLUE);//draw a horizontal blue line point(0,25) to point(50,25)
//Rectangle
Tft.drawRectangle(50,0,80,50,WHITE);//draw a white rectangle, length=80(X-AXIS), width=50(Y-AXIS)
Tft.fillRectangle(0,50,50,80,CYAN);//fill a cyan rectangle, length=50(X-AXIS), width=80(Y-AXIS)
//Circle
Tft.drawCircle(75,75,25,RED);//draw a red circle, circle centre(75,75) radius=25
Tft.fillCircle(150,100,50,GREEN);//fill a green circle, circle centre(150,100) radius=50
//Text
Tft.drawChar('S',0,150,2,RED);//draw a char, start from point(0,150) font size 2(1616)
Tft.drawString("Seeed Studio",8,166,2,GREEN);//draw a char, start from point(8,166) font size 2(1616)
}
void loop(void)
{
// a point object holds x y and z coordinates
Point p = ts.getPoint();
p.x = map(p.x, TS_MINX, TS_MAXX, MapX1, MapX2);
p.y = map(p.y, TS_MINY, TS_MAXY, MapY1, MapY2);
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > ts.pressureThreshhold)
{
//p.x;
//p.y;
//p.z;
Tft.fillCircle(p.x,p.y,2,GREEN);
}
}
void initTouchScreenParameters()
{
//This function initializes Touch Screen parameters based on the detected TFT Touch Schield hardware
if(Tft.IC_CODE == 0x5408) //SPFD5408A TFT driver based Touchscreen hardware detected
{
#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
ts = TouchScreen(54, A1, A2, 57, 300); //init TouchScreen port pins
#else
ts = TouchScreen(14, A1, A2, 17, 300); //init TouchScreen port pins
#endif
//Touchscreen parameters for this hardware
TS_MINX = 120;
TS_MAXX = 910;
TS_MINY = 120;
TS_MAXY = 950;
MapX1 = 239;
MapX2 = 0;
MapY1 = 0;
MapY2 = 319;
}
else //ST7781R TFT driver based Touchscreen hardware detected
{
#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
ts = TouchScreen(57, A2, A1, 54, 300); //init TouchScreen port pins
#else
ts = TouchScreen(17, A2, A1, 14, 300); //init TouchScreen port pins
#endif
//Touchscreen parameters for this hardware
TS_MINX = 140;
TS_MAXX = 900;
TS_MINY = 120;
TS_MAXY = 940;
MapX1 = 239;
MapX2 = 0;
MapY1 = 319;
MapY2 = 0;
}
}
This is tft fil.h on myn desktop:
/*
ST7781R TFT Library.
/
/
*/
#include <Arduino.h>
#include <avr/pgmspace.h>
#ifndef TFT_h
#define TFT_h
#define MEGA
//Basic Colors
#define RED 0xf800
#define GREEN 0x7e00
#define BLUE 0x001f
#define BLACK 0x0000
#define YELLOW 0xffe0
#define WHITE 0xffff
//Other Colors
#define CYAN 0x07ff
#define BRIGHT_RED 0xf810
#define GRAY1 0x8410
#define GRAY2 0x4208
//TFT resolution 240*320
#define MIN_X 0
#define MIN_Y 0
#define MAX_X 240
#define MAX_Y 320
#ifdef SEEEDUINO
//========================================
#define DDR_CS DDRB
#define PORT_CS PORTB
#define CS_BIT 0x04
#define CS_OUTPUT {DDR_CS|=CS_BIT;}
#define CS_HIGH {PORT_CS|=CS_BIT;}
#define CS_LOW {PORT_CS&=~CS_BIT;}
//-----------------------------------------
#define DDR_RS DDRB
#define PORT_RS PORTB
#define RS_BIT 0x08
#define RS_OUTPUT {DDR_RS|=RS_BIT;}
#define RS_HIGH {PORT_RS|=RS_BIT;}
#define RS_LOW {PORT_RS&=~RS_BIT;}
//-----------------------------------------
#define DDR_WR DDRB
#define PORT_WR PORTB
#define WR_BIT 0x10
#define WR_OUTPUT {DDR_WR|=WR_BIT;}
#define WR_HIGH {PORT_WR|=WR_BIT;}
#define WR_LOW {PORT_WR&=~WR_BIT;}
#define WR_RISING {PORT_WR|=WR_BIT;PORT_WR&=~WR_BIT;}
//-----------------------------------------
#define DDR_RD DDRB
#define PORT_RD PORTB
#define RD_BIT 0x20
#define RD_OUTPUT {DDR_RD|=RD_BIT;}
#define RD_HIGH {PORT_RD|=RD_BIT;}
#define RD_LOW {PORT_RD&=~RD_BIT;}
#define RD_RISING {PORT_RD|=RD_BIT;PORT_RD&=~RD_BIT;}
//========================================
#endif
#ifdef MEGA
//==================/CS=====================
#define DDR_CS DDRB
#define PORT_CS PORTB
#define CS_BIT 0x10
#define CS_OUTPUT {DDR_CS|=CS_BIT;}
#define CS_HIGH {PORT_CS|=CS_BIT;}
#define CS_LOW {PORT_CS&=~CS_BIT;}
//------------------RS----------------------
#define DDR_RS DDRB
#define PORT_RS PORTB
#define RS_BIT 0x20
#define RS_OUTPUT {DDR_RS|=RS_BIT;}
#define RS_HIGH {PORT_RS|=RS_BIT;}
#define RS_LOW {PORT_RS&=~RS_BIT;}
//------------------WR----------------------
#define DDR_WR DDRB
#define PORT_WR PORTB
#define WR_BIT 0x40
#define WR_OUTPUT {DDR_WR|=WR_BIT;}
#define WR_HIGH {PORT_WR|=WR_BIT;}
#define WR_LOW {PORT_WR&=~WR_BIT;}
#define WR_RISING {PORT_WR|=WR_BIT;PORT_WR&=~WR_BIT;}
//------------------RD---------------------
#define DDR_RD DDRB
#define PORT_RD PORTB
#define RD_BIT 0x80
#define RD_OUTPUT {DDR_RD|=RD_BIT;}
#define RD_HIGH {PORT_RD|=RD_BIT;}
#define RD_LOW {PORT_RD&=~RD_BIT;}
#define RD_RISING {PORT_RD|=RD_BIT;PORT_RD&=~RD_BIT;}
//========================================
#endif
#ifdef MAPLE
// not yet implemented
#endif
/Macro definitions for char display direction/
#define LEFT2RIGHT 0
#define DOWN2UP 1
#define RIGHT2LEFT 2
#define UP2DOWN 3
extern unsigned char simpleFont[][8];
class TFT
{
public:
void init (void);
void sendCommand(unsigned int index);
void sendData(unsigned int data);
void pushData(unsigned char data);
unsigned char getData(void);
unsigned int readRegister(unsigned int index);
void setXY(unsigned int poX, unsigned int poY);
void setPixel(unsigned int poX, unsigned int poY,unsigned int color);
void drawLine(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color);
void drawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color);
void drawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color);
void drawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color);
void fillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color);
void drawCircle(int poX, int poY, int r,unsigned int color);
void fillCircle(int poX, int poY, int r,unsigned int color);
void drawChar(unsigned char ascii,unsigned int poX, unsigned int poY,unsigned int size, unsigned int fgcolor);
void drawString(char *string,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor);
void all_pin_input(void);
void all_pin_output(void);
void all_pin_low(void);
void setOrientation(unsigned int HV);
void setDisplayDirect(unsigned char = LEFT2RIGHT);
private:
void exitStandBy(void);
unsigned char DisplayDirect;
};
extern TFT Tft;
#endif
this is touchscreen file:
// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// (c) ladyada / adafruit
// Code under MIT License
class Point {
public:
Point(void);
Point(int16_t x, int16_t y, int16_t z);
bool operator==(Point);
bool operator!=(Point);
int16_t x, y, z;
};
class TouchScreen {
public:
TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym);
TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx);
bool isTouching(void);
uint16_t pressure(void);
int readTouchY();
int readTouchX();
Point getPoint();
int16_t pressureThreshhold;
private:
uint8_t _yp, _ym, _xm, _xp;
uint16_t _rxplate;
};
this is error;
cpp; in function 'void init touchscreenparameters()':
70; class tft has no member named ic_cod
=( =( =(