Hi,
I have a problem that has been giving me the slip for three or four days. I have tried everything I can find, most too complicated for my simple task.
I have a 3.5 TFT / Touch / SD card shield, with pins directly onto the uno. It looks okay but I would like to place a file in the root of the SD called "Alien8.bmp" as the background of the display. I have tried to attach an ebay picture the same as my shield.
I just can't find a way to achieve this.. Please can anyone help this old git!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#if 1
#include <SD.h>
#include <SPI.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000
#define sd_cs 10
// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 7, XM = A1, YP = A2, YM = 6; //320x480 ID=0x6814
const int TS_LEFT = 129, TS_RT = 904, TS_TOP = 84, TS_BOT = 924;
#define TOUCH_ORIENTATION PORTRAIT
#define TITLE " Drink Server "
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button WL_btn, BC_btn, GT_btn, L_btn, C_btn, T_btn;
int pixel_x, pixel_y; //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
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.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}
return pressed;
}
#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(){
Serial.begin(9600);
uint16_t ID = tft.readID();
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
tft.begin(ID); //was ID
tft.setRotation(0); //PORTRAIT
tft.fillRect(10, 10, 320, 25, RED);
tft.setCursor (95, 20);
tft.setTextSize(2);
tft.println(TITLE);
Serial.print(F("Initializing SD card..."));
if (!SD.begin(sd_cs)) {
Serial.println(F("failed!"));
return;
}
Serial.println(F("OK!"));
WL_btn.initButton(&tft, 155, 70, 200, 50, WHITE, CYAN, BLACK, "Wiskey Lemonade", 3);
BC_btn.initButton(&tft, 155, 130, 200, 50, WHITE, CYAN, BLACK, "Brandy Coke", 3);
GT_btn.initButton(&tft, 155, 190, 200, 50, WHITE, CYAN, BLACK, "Gin and Tonic", 3);
L_btn.initButton(&tft, 155, 250, 200, 50, WHITE, CYAN, BLACK, "Lemonade", 3);
C_btn.initButton(&tft, 155, 310, 200, 50, WHITE, CYAN, BLACK, "Coke", 3);
T_btn.initButton(&tft, 155, 370, 200, 50, WHITE, CYAN, BLACK, "Tonic", 3);
WL_btn.drawButton(false);
BC_btn.drawButton(false);
GT_btn.drawButton(false);
L_btn.drawButton(false);
C_btn.drawButton(false);
T_btn.drawButton(false);
tft.fillRect(40, 430, 250, 50, BLACK);
}
/*
updating multiple buttons from a list
anything more than two buttons gets repetitive
you can place button addresses in separate lists
e.g. for separate menu screens
*/
// Array of button addresses to behave like a list
Adafruit_GFX_Button *buttons[] = {&WL_btn, &BC_btn, >_btn, &L_btn, &C_btn, &T_btn, NULL};
/* update the state of a button and redraw as reqd
main program can use isPressed(), justPressed() etc
*/
bool update_button(Adafruit_GFX_Button *b, bool down)
{
b->press(down && b->contains(pixel_x, pixel_y));
if (b->justReleased())
b->drawButton(false);
if (b->justPressed())
b->drawButton(true);
return down;
}
/* most screens have different sets of buttons
life is easier if you process whole list in one go
/
bool update_button_list(Adafruit_GFX_Button *pb)
{
bool down = Touch_getXY();
for (int i = 0 ; pb != NULL; i++) {
update_button(pb, down);
* }*
* return down;*
}
/* compare the simplicity of update_button_list()
*/
void loop(void)
{
* //bmpDraw("alien8.bmp", 0, 0);*
* update_button_list(buttons); //use helper function*
* if (WL_btn.justPressed()) {
_ Serial.println(F("05,10,01,40,10,00,40,10,00,40,10,01,40,10,00,40,10,00,"));_
_ tft.fillRect(40, 430, 250, 50, GREEN);_
_ }_
if (BC_btn.justPressed()) {
_ Serial.println(F("05,10,00,40,10,01,40,10,00,40,10,00,40,10,01,40,10,00,"));_
_ tft.fillRect(40, 430, 250, 50, WHITE);_
_ }_
if (GT_btn.justPressed()) {
_ Serial.println(F("05,10,00,40,10,00,40,10,01,40,10,00,40,10,00,40,10,01,"));_
_ tft.fillRect(40, 430, 250, 50, BLUE);_
_ }_
if (L_btn.justPressed()) {
_ Serial.println(F("05,10,00,40,10,00,40,10,00,40,10,01,40,10,00,40,10,00,"));_
_ tft.fillRect(40, 430, 250, 50, YELLOW);_
_ }_
if (C_btn.justPressed()) {
_ Serial.println(F("05,10,00,40,10,00,40,10,00,40,10,00,40,10,01,40,10,00,"));_
_ tft.fillRect(40, 430, 250, 50, CYAN);_
_ }_
if (T_btn.justPressed()) {
_ Serial.println("05,10,00,40,10,00,40,10,00,40,10,00,40,10,00,40,10,01,");_
_ tft.fillRect(40, 430, 250, 50, MAGENTA);_
_ }_
_#endif*_
* delay(1000);*
* tft.fillRect(40, 430, 250, 50, BLACK);*
* delay(1000);*
}
It looks okay but I would like to place a file in the root of the SD called "Alien8.bmp" as the background of the display. I have tried to attach an ebay picture the same as my shield.
I just can't find a way to achieve this.. Please can anyone help this old git!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!