#include <Arduino_GFX_Library.h>
#include "LiberationSans_Bold10pt7b.h"
// Pinovi za tvoj Wokwi projekat
#define GFX_DC 2
#define GFX_CS 15
#define GFX_RST 9
#define GFX_MOSI 23
#define GFX_SCK 18
#define GFX_BL 21
Arduino_DataBus *bus = new Arduino_ESP32SPI(GFX_DC, GFX_CS, GFX_SCK, GFX_MOSI, -1, VSPI);
Arduino_GFX *gfx = new Arduino_ILI9341(bus, GFX_RST, 0); // rotation 0 = portrait, promeni na 1 ili 3 ako treba landscape
#define BLACK 0x0000
#define WHITE 0xFFFF
String songTitle = "Veoma duugačak naziv pesme - Izvođač sa dugim imenom";
int scrollPos = 0;
unsigned long lastScroll = 0;
const unsigned long scrollDelay = 100; // 80-150 za glatki osećaj
const int textY = 180; // pomerio malo niže da sigurno vidiš
const int textHeight = 32; // dovoljno za 10pt bold font
int textPixelWidth = 0; // biće tačno izračunato
void setup() {
Serial.begin(115200);
gfx->begin();
gfx->fillScreen(BLACK);
pinMode(GFX_BL, OUTPUT);
digitalWrite(GFX_BL, HIGH);
gfx->setFont(&LiberationSans_Bold10pt7b);
gfx->setTextColor(WHITE, BLACK); // background boja je važna da ne flickeruje
prepareScrollingText();
Serial.println("Setup gotov - počinje scrolling...");
}
void prepareScrollingText() {
// Tačnija širina teksta pomoću getTextBounds (Arduino_GFX nasleđuje od Adafruit_GFX)
int16_t x1, y1;
uint16_t w, h;
gfx->getTextBounds(songTitle, 0, 0, &x1, &y1, &w, &h);
textPixelWidth = w;
Serial.print("Tekst širina: ");
Serial.println(textPixelWidth);
}
void loop() {
if (millis() - lastScroll >= scrollDelay) {
lastScroll = millis();
// Brišemo ceo red (minimalno treperenje)
gfx->fillRect(0, textY, gfx->width(), textHeight, BLACK);
// Pomeramo tekst
int x = -scrollPos;
gfx->setCursor(x, textY + 22); // 22 je dobar baseline za većinu 10pt fontova (testiraj 18-26)
gfx->print(songTitle + " " + songTitle); // razmak + ponavljanje za seamless loop
scrollPos += 2; // 2 piksela po koraku je dobar kompromis
// Reset kad prođe ceo tekst + razmak
if (scrollPos > textPixelWidth + 50) scrollPos = 0;
}
}Loading
ili9341-cap-touch
ili9341-cap-touch