Robot cocktail maker and TFT screen

I have 2 on order. A ST7738 and a ILI9486. Already have SD-to-display test code for both. They are supposed to be here Tuesday, but who knows. I'll be able to tell you more after I test for a bit.

You asked me about functions before and I replied in post #11 that I'm not sure what you mean. The answer seems too obvious: yes, of course you can. Your current code already contains several functions for different purposes, so I know you are familiar with them. Sounds like you are also familiar with functions from writing Visual BASIC code?

Can you give an example of a function that you would write in VB that you don't know how to write in C/C++?

What size bitmaps do you plan on using? Width is the important factor.

I was going to use 80 x 80

I bought that exact same ILI9486 and could not get the touch screen to work at all.

Right now I have the max pixel width set at 256. No limit on height. It takes images directly from a 16 bit bitmap file in 5R6G5B format. No need to convert.

My code resembles the old dot matrix line printers. Print a line at a time.

I don't really care about the touchscreen as much as the display resolution.

BTW, that touchscreen states it needs a pen to work. It is resistive, not capacitive.
Both my displays should arrive today.

Awesome. The screen is now working. I sourced mine from Aliexpress and they advised different libraries. I use the Adafruit ones from the link in amazon and its all working OK. Now all I need to do is figure out my original problem which is how to get the buttons on there.

This is the function in my code that displays the bitmap.
Think you can figure out how to use it?
void displayImage(char* fileName,int col,int row)

Edit: Guess I should warn you about the SD library. It is stuck in the past with 8.3 file format. Don't use filenames longer than 8 characters and a 3 character file extension.

To be honest, not really I am just learning.

Easy. The filename is the bitmap file on the SD card you want to display, and col and row determine where on the display the image will start. Screen coordinates of the upper left corner. This displays myfile.bmp with the upper left corner starting at column 10 and row 20.
displayImage("myfile.bmp",10,20);

1 Like

Giving it a go now

You can't try it now. It's in my sketch. I have to test it.

Edit: Don't try to cheat. The code checks the header for file type, pixel color resolution at 16 bits and the image width.

Are you trying it with the Adafruit Libraries and the ILI9486?

Cos if you are I will use the same and copy all your code

I'll take a look at the Adafruit library. The TFT and UTFT libraries use different functions to set the location and save the color.

Edit: You don't need that code. That was the converter. I bypassed that and get the data directly from the original bmp file.

I have created two BMPs and named them the same as yours "arduino.bmp" and arduino2.bmp". What size shall I make them to match with yours?

Ensure they are 16 bit 5R6G5B format. Gimp image program does a great job.
You can make them any size you want as long as the width is 256 pixels or less.
My code gets the image width from the file header.

after calibrating this code got me this

#if 1

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP=6,XM=A2,YP=A1,YM=7; //320x480 ID=0x6814
const int TS_LEFT=945,TS_RT=157,TS_TOP=970,TS_BOT=164;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button on_btn, off_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(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
    tft.begin(ID);
    tft.setRotation(0);            //PORTRAIT
    tft.fillScreen(BLACK);
    on_btn.initButton(&tft,  60, 200, 100, 40, WHITE, CYAN, BLACK, "ON", 2);
    off_btn.initButton(&tft, 180, 200, 100, 40, WHITE, CYAN, BLACK, "OFF", 2);
    on_btn.drawButton(false);
    off_btn.drawButton(false);
    tft.fillRect(40, 80, 160, 80, RED);
}

/* two buttons are quite simple
 */
void loop(void)
{
    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();
    if (off_btn.justReleased())
        off_btn.drawButton();
    if (on_btn.justPressed()) {
        on_btn.drawButton(true);
        tft.fillRect(40, 80, 160, 80, GREEN);
    }
    if (off_btn.justPressed()) {
        off_btn.drawButton(true);
        tft.fillRect(40, 80, 160, 80, RED);
    }
}
#endif

If you use Gimp, load any type file.
When ready, select
File -> Export As
Select the "Select file type" lower left.
From that list, select Windows BMP image
Click Export.
On the popup window, select "Advanced Options".
Select 16 bit 5R 6G 5B

Will paint work?