TAKE A LOOK AT THIS PLEASE!
Moderators: adafruit_support_bill, adafruit

TAKE A LOOK AT THIS PLEASE!

by romny1992 on Wed Jan 02, 2013 9:35 pm

Hi,
im trying to make 4 LEDs turn on with my TFT touchscreen shield....

i have an arduino MEGA 2560 R3, and the touchscreen shield i have is from Seeedstudio: TFT 2.8" touchscreen sheild V1 (RED).

so far this is all i have, i just need to write the code to turn on the LEDs when i press each square, and this is where i need help.

i dont know how to do that, any of you guys can just help me making one square to work. after that ill just take a look at it and then i can make the other 3 to work.

this is the code i have:

Code: Select all | TOGGLE FULL SIZE
#include <stdint.h>
#include <TouchScreen.h>
#include <TFT.h>

#ifdef SEEEDUINO
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 14   // can be a digital pin, this is A0
  #define XP 17   // can be a digital pin, this is A3
#endif


void setup()
{

Tft.init();  //init TFT library
pinMode(0,OUTPUT);
 
 
                //  X-Y-Length-Height  //
  Tft.fillRectangle(0, 0, 240, 320, WHITE);   //Background
  Tft.fillRectangle(0, 0, 240, 12, BLUE);     //blue bar
  Tft.fillRectangle(212, 1, 21, 10, BLACK);  // battery body
  Tft.fillRectangle(210, 3, 2, 6, BLACK);    // battery tip
  Tft.fillRectangle(219, 2, 13, 8, GREEN);   // battery level at FULL ---> (201, 2, 19, 8, GREEN);
   
  //statusbar
  Tft.drawString("Romny          12/31/12",5, 4, 1, YELLOW);
 
  //4 squares
  Tft.fillRectangle(30, 50, 80, 80, RED);//1
  Tft.fillRectangle(130, 50, 80, 80, GREEN);//2
  Tft.fillRectangle(30, 160, 80, 80, BLUE);//3
  Tft.fillRectangle(130, 160, 80, 80, YELLOW);//4
 
  //square Label
  Tft.drawString("LED1",40, 80, 2, BLACK);
  Tft.drawString("LED2",40, 190, 2, BLACK);
  Tft.drawString("LED3",135, 80, 2, BLACK);
  Tft.drawString("LED4",135, 190, 2, BLACK); 
}

void loop()
{
 

}
Attachments
libraries.rar
(385.1 KiB) Downloaded 49 times
4 LEDs_Code.rar
(633 Bytes) Downloaded 42 times
photo.JPG
photo.JPG (567.09 KiB) Viewed 545 times
romny1992
 
Posts: 4
Joined: Tue Jan 01, 2013 6:04 pm

Re: TAKE A LOOK AT THIS PLEASE!

by romny1992 on Wed Jan 02, 2013 11:38 pm

ok this is what i have so far, but im getting an error.

#include <stdint.h>
#include <TouchScreen.h>
#include <TFT.h>

#ifdef SEEEDUINO
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A1 // must be an analog pin, use "An" notation!
#define YM 14 // can be a digital pin, this is A0
#define XP 17 // can be a digital pin, this is A3
#endif


void setup()
{

Tft.init(); //init TFT library
pinMode(0,OUTPUT);


// X-Y-Length-Height //
Tft.fillRectangle(0, 0, 240, 320, WHITE); //Background
Tft.fillRectangle(0, 0, 240, 12, BLUE); //blue bar
Tft.fillRectangle(212, 1, 21, 10, BLACK); // battery body
Tft.fillRectangle(210, 3, 2, 6, BLACK); // battery tip
Tft.fillRectangle(219, 2, 13, 8, GREEN); // battery level at FULL ---> (201, 2, 19, 8, GREEN);

//statusbar
Tft.drawString("Romny 12/31/12",5, 4, 1, YELLOW);

//4 squares
Tft.fillRectangle(30, 50, 80, 80, RED);//1
Tft.fillRectangle(130, 50, 80, 80, GREEN);//2
Tft.fillRectangle(30, 160, 80, 80, BLUE);//3
Tft.fillRectangle(130, 160, 80, 80, YELLOW);//4

//square Label
Tft.drawString("LED1",40, 80, 2, BLACK);
Tft.drawString("LED2",40, 190, 2, BLACK);
Tft.drawString("LED3",135, 80, 2, BLACK);
Tft.drawString("LED4",135, 190, 2, BLACK);
}

void loop()
{


}
Attachments
Capture.PNG
Capture.PNG (57.58 KiB) Viewed 533 times
romny1992
 
Posts: 4
Joined: Tue Jan 01, 2013 6:04 pm

Re: TAKE A LOOK AT THIS PLEASE!

by romny1992 on Wed Jan 02, 2013 11:40 pm

this is what i have so far:

#include <stdint.h>
#include <TouchScreen.h>
#include <TFT.h>

#ifdef SEEEDUINO
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A1 // must be an analog pin, use "An" notation!
#define YM A0 // can be a digital pin, this is A0
#define XP A3 // can be a digital pin, this is A3
#endif

#define TS_MINX 140
#define TS_MAXX 900
#define TS_MINY 120
#define TS_MAXY 940

int GREENled = 30;
int REDled = 31;
int YELLOWled = 32;
int BLUEled = 33;


void setup()
{

Tft.init(); //init TFT library
pinMode(0,OUTPUT);
pinMode(GREENled, OUTPUT);
pinMode(REDled, OUTPUT);
pinMode(YELLOWled, OUTPUT);
pinMode(BLUEled, OUTPUT);


// X-Y-Length-Height //
Tft.fillRectangle(0, 0, 240, 320, WHITE); //Background
Tft.fillRectangle(0, 0, 240, 12, BLUE); //blue bar
Tft.fillRectangle(212, 1, 21, 10, BLACK); // battery body
Tft.fillRectangle(210, 3, 2, 6, BLACK); // battery tip
Tft.fillRectangle(219, 2, 13, 8, GREEN); // battery level at FULL ---> (201, 2, 19, 8, GREEN);

//statusbar
Tft.drawString("Romny 12/31/12",5, 4, 1, YELLOW);

//4 squares
Tft.fillRectangle(30, 50, 80, 80, RED);//1
Tft.fillRectangle(130, 50, 80, 80, GREEN);//2
Tft.fillRectangle(30, 160, 80, 80, BLUE);//3
Tft.fillRectangle(130, 160, 80, 80, YELLOW);//4

//square Label
Tft.drawString("LED1",40, 80, 2, BLACK);
Tft.drawString("LED2",40, 190, 2, BLACK);
Tft.drawString("LED3",135, 80, 2, BLACK);
Tft.drawString("LED4",135, 190, 2, BLACK);
}

void loop () {
int MapX1 = 239;
int MapX2 = 0;
int MapY1 = 319;
int MapY2 = 0;

// 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) {
//If you get here, someone is touching the screen at (p.x, p.y) coordinates.
//p.z has how hard they are pressing.

Tft.fillCircle(p.x,p.y,2,GREEN);
// The corners of button 1 are (30,50) and (80,80)
if (p.x > 30 && p.x < 80 && p.y > 50 && p.y < 80) {
//Put your code that turns on the LED Here.
digitalWrite(REDled, HIGH);
delay(1000);
}
}
}
romny1992
 
Posts: 4
Joined: Tue Jan 01, 2013 6:04 pm

Re: TAKE A LOOK AT THIS PLEASE!

by adafruit_support_bill on Thu Jan 03, 2013 6:18 am

Looks like you haven't declared your touchscreen. Not familiar with Seeed's screens or libraries. Best to ask this question at Seeed or Radioshack if that's where it was purchased.

These are the Adafruit customer support forums for Adafruit customers.

Thanks!
User avatar
adafruit_support_bill
 
Posts: 29610
Joined: Sat Feb 07, 2009 9:11 am