Making an object move with a button tft display

Hello,

I was wondering if anyone had any advice on making an object move forward and backwards using buttons or joystick. I just dont know how to connect with the object.

This is the code, i know i have no controller yet.

#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>

#if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
#define TFT_CS 14
#define TFT_RST 15
#define TFT_DC 32

#elif defined(ESP8266)
#define TFT_CS 4
#define TFT_RST 16
#define TFT_DC 5

#else
// For the breakout board, you can use any 2 or 3 pins.
// These pins will also work for the 1.8" TFT shield.
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
#endif

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

float p = 3.1415926;

void setup(void) {
Serial.begin(115200);
tft.init(135, 240);
uint16_t time = millis();
tft.fillScreen(ST77XX_BLACK);
testlines(ST77XX_YELLOW);
delay(500);

}

void loop() {

}

void testlines(uint16_t color) {
tft.fillScreen(ST77XX_BLACK);
for (int16_t x=0; x < tft.width(); x+=0) {
tft.drawLine(0, 0, x, tft.height()-1, color);
tft.drawRect(3, 3, 20, 20, ST7735_WHITE);
delay(0);
}
}

Any help would be wonderful:)

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).


to move the object, gather the new position from your input device, erase the previous position and draw at the new position. rinse and repeat

By "object" did you mean that little rectangle?
tft.drawRect(3, 3, 20, 20, ST7735_WHITE);

You don't have any code in your sketch for working with the buttons. I would start with getting that working in your sketch first. But if you want to redraw the object, just fill the screen with your background color (black), then draw the object in the new location you want it. So, if your first draw is
tft.drawRect(3, 3, 20, 20, ST7735_WHITE);
and you want to move it to the right 5 pixels you would modify it to
tft.drawRect(8, 3, 20, 20, ST7735_WHITE);

The sketch you have uploaded looks like the demo sketch. So, do you understand how it works?

Please edit your posts to add code tags.

Code tags for BOTH pssts please. If you don’t care about the forum’s lisibility why should we spend time trying to hello. Do the right thing please.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.