Arduino_GFX icon indicating copy to clipboard operation
Arduino_GFX copied to clipboard

Can't use any gfx commands in Arduino loop

Open BenthamSoftwareServices opened this issue 1 year ago • 2 comments
trafficstars

When I add any gfx-> type command into loop() I get an error saying gfx is undefined, but it works if I use it in setup(), what am I doing wrong?

BenthamSoftwareServices avatar Aug 18 '24 18:08 BenthamSoftwareServices

you may start with hello world example first.

moononournation avatar Aug 19 '24 00:08 moononournation

Thank you very much the "hello world" works without problem. Can you see why my code following has error message gfx not declared in this scope, when I add a gfx command to loop, otherwise the gfx commands in setup work OK?

#include <Arduino_GFX_Library.h>

#define PIN_CS 22 //configurable #define PIN_DC 16 //configurable #define PIN_RES 4 //configurable #define PIN_SDA 23 //fixed #define PIN_SCL 18 //fixed

void setup() { Arduino_DataBus *bus = new Arduino_HWSPI(PIN_DC, PIN_CS); //create data bus class

Arduino_GFX *gfx = new Arduino_GC9A01(bus, PIN_RES, 0 /* rotation */, true /* IPS */, 240 /* width */, 240 /* height */); 

gfx->begin(); //initialise gfx class

gfx->fillScreen(gfx->color565(37, 234, 61));
delay(2000);

gfx->fillScreen(WHITE);

gfx->setCursor(15, 110);
gfx->setTextSize(3, 3);
gfx->setTextColor(BLACK);
delay(2000);
gfx->println("Hello from setup!");
}

void loop() { delay(2000); gfx->println("Hello from loop!"); delay(1000); }

BenthamSoftwareServices avatar Aug 19 '24 09:08 BenthamSoftwareServices