Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library (Arduino Framework)

Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library. 
- 2.4 inch 240×320 ST7789 SPI IPS
- 2.0 inch 240x320 ST7789 SPI IPS



Connection:
	
	Connection
	==========
					
	    Raspberry Pi Pico 2 W
						
		|
	    GP28| ------- LCD2_RST -----------------+
	    GND |                                   |
	    GP27| ------- LCD2_DC ----------------+ |
	    GP26| ------- LCD2_CS --------------+ | |
	    Run |				| | |
	    GP22| ------- LCD_RST ------+	| | |
	    GND |			|	| | |
	    GP21| ------- LCD_DC -------|-+	| | |
	    GP20| ------- LCD_BL -------|-|---+	| | |
	    GP19| MOSI	- SPI_SDA ----+ | |   |	| | |
	    GP18| SCK	- SPI_SCL --+ | | |   |	| | |
	    GND |		    | | | |   |	| | |
	    GP17| SS	- LCD_CS ---|-|-|-|-+ |	| | |
	    GP16| MISO  - no use    | | | | | |	| | |
	--------+		    | | | | | |	| | |
				    | | | | | |	| | |
	    ST7789 SPI IPS x 2	    | | | | | |	| | |
				    | | | | | |	| | |
	    1 GND - GND		    | | | | | |	| | |
	    2 VCC - 3V3		    | | | | | |	| | |
	    3 SCL ----------+-------+ | | | | |	| | |
	    4 SDA ----------|-+-------+ | | | |	| | |
	    5 RST ----------|-|---------+ | | |	| | |
	    6 DC  ----------|-|-----------+ | |	| | |
	    7 CS  ----------|-|-------------+ |	| | |
	    8 BL  ----------|-|-+-------------+	| | |
			    | | |		| | |
			    | |	|		| | |
	    1 GND - GND	    | |	|		| | |
	    2 VCC - 3V3	    | |	|		| | |
	    3 SCL ----------+ | |		| | |
	    4 SDA ------------+	|		| | |
	    5 RST --------------|---------------|-|-+
	    6 DC  --------------|---------------|-+
	    7 CS  --------------|---------------+
	    8 BL  --------------+




rpPico2W_Arduino_GFX_Dual.ino, color test.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.  
- 2.4 inch 240×320 ST7789 SPI IPS
- 2.0 inch 240x320 ST7789 SPI IPS
Color Test

details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-dual.html

Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico

Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html

*/
/*******************************************************************************
 * Start of Arduino_GFX setting
 ******************************************************************************/
#include <Arduino_GFX_Library.h>

#define SPI_SCK       18
#define SPI_MOSI      19
#define TFT_RST 22
#define TFT_DC  21
#define TFT_CS  17

#define TFT2_RST 28
#define TFT2_DC  27
#define TFT2_CS  26

#define TFT_BL  20

#define TFT_ROTATION 0
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
#define TFT_COLSTART 0
#define TFT_ROWSTART 0

#define TFT2_ROTATION 0
#define TFT2_WIDTH 240
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 0
#define TFT2_ROWSTART 0

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT_DC, TFT_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, TFT_ROTATION, true /* IPS */,
                                      TFT_WIDTH, TFT_HEIGHT,
                                      TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *gfx2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
                                       TFT2_WIDTH, TFT2_HEIGHT,
                                       TFT2_COLSTART, TFT2_ROWSTART);

/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

void setup(void)
{
  delay(2000);
  Serial.begin(115200);
  delay(500);

  Serial.println("--- Start ---");

  // Serial.setDebugOutput(true);
  // while(!Serial);
  Serial.println("Arduino_GFX_Library color test");

  // Init Display
  if (!gfx->begin())
  {
    Serial.println("gfx->begin() failed!");
  }
  gfx->fillScreen(RGB565_BLACK);
  // Init Display
  if (!gfx2->begin())
  {
    Serial.println("gfx2->begin() failed!");
  }
  gfx2->fillScreen(RGB565_BLACK);

  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);  //Turn On Backlight

  gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
  gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, RGB565_WHITE);

  gfx->setCursor(10, 10);
  gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx->println("Raspberry Pi Pico 2");
  gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
  gfx->println();
  gfx->println("Arduino_GFX_Library");

  gfx2->setCursor(10, 10);
  gfx2->setTextSize(2 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx2->println("Dual ST7789 exercise");
    gfx2->println("Color Test");

  delay(5000); // 5 seconds
}

#define num_of_color 5
int color[num_of_color] = {RGB565_RED, RGB565_GREEN, RGB565_BLUE, RGB565_WHITE, RGB565_BLACK};
String color_name[num_of_color] = {"RED", "GREEN", "BLUE", "WHITE", "BLACK"};
int color_index = 0;

void loop()
{
  unsigned long startTime, stopTime;
  //
  startTime = millis();
  gfx->fillScreen(color[color_index]);
  gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, color[color_index]^0xFFFF);

  gfx->setTextColor(color[color_index]^0xFFFF);
  gfx->setCursor(10, 70);
  gfx->setTextSize(6 /* x scale */, 6 /* y scale */, 2 /* pixel_margin */);
  gfx->println(color_name[color_index]);
  stopTime = millis();

  gfx->setCursor(10, 140);
  gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  //gfx->println(String(stopTime-startTime));
  gfx->printf("%i ms", stopTime-startTime);

  //
  startTime = millis();
  gfx2->fillScreen(color[color_index]);
  gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, color[color_index]^0xFFFF);

  gfx2->setTextColor(color[color_index]^0xFFFF);
  gfx2->setCursor(10, 70);
  gfx2->setTextSize(6 /* x scale */, 6 /* y scale */, 2 /* pixel_margin */);
  gfx2->println(color_name[color_index]);
  stopTime = millis();

  gfx2->setCursor(10, 140);
  gfx2->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  //gfx->println(String(stopTime-startTime));
  gfx2->printf("%i ms", stopTime-startTime);

  //

  color_index++;
  if (color_index==num_of_color){
    color_index = 0;
  }

  delay(1000); // 1 second
}



rpPico2W_Arduino_GFX_Dual_random.ino, random pattern.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.  
- 2.4 inch 240×320 ST7789 SPI IPS
- 2.0 inch 240x320 ST7789 SPI IPS
Display Random Pattern.

details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-dual.html

Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico

Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html

*/
#include <Arduino_GFX_Library.h>

#define SPI_SCK       18
#define SPI_MOSI      19
#define TFT_RST 22
#define TFT_DC  21
#define TFT_CS  17

#define TFT2_RST 28
#define TFT2_DC  27
#define TFT2_CS  26

#define TFT_BL  20

#define TFT_ROTATION 0
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
#define TFT_COLSTART 0
#define TFT_ROWSTART 0

#define TFT2_ROTATION 0
#define TFT2_WIDTH 240
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 0
#define TFT2_ROWSTART 0

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT_DC, TFT_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, TFT_ROTATION, true /* IPS */,
                                      TFT_WIDTH, TFT_HEIGHT,
                                      TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *gfx2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
                                       TFT2_WIDTH, TFT2_HEIGHT,
                                       TFT2_COLSTART, TFT2_ROWSTART);

/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

void setup(void)
{

  delay(2000);
  Serial.begin(115200);
  delay(500);

  Serial.println("--- Start ---");

  // Serial.setDebugOutput(true);
  // while(!Serial);
  Serial.println("Arduino_GFX_Library color test");

  // Init Display
  if (!gfx->begin())
  {
    Serial.println("gfx->begin() failed!");
  }
  gfx->fillScreen(RGB565_BLACK);
  // Init Display
  if (!gfx2->begin())
  {
    Serial.println("gfx2->begin() failed!");
  }
  gfx2->fillScreen(RGB565_BLACK);

  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);  //Turn On Backlight

  gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
  gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, RGB565_WHITE);

  gfx->setCursor(10, 10);
  gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx->println("Raspberry Pi Pico 2");
  gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
  gfx->println();
  gfx->println("Arduino_GFX_Library");

  gfx2->setCursor(10, 10);
  gfx2->setTextSize(2 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx2->println("Dual ST7789 exercise");
  gfx2->println("Random pattern");

  delay(5000); // 5 seconds

  gfx->fillScreen(RGB565_BLACK);
  gfx2->fillScreen(RGB565_BLACK);
}


void loop()
{
  // Draw random circle in gfx
  if (random(0, 2)) {
    gfx->fillCircle(random(gfx->width()), random(gfx->height()), random(30), random(0xffff));
  } else {
    gfx->drawCircle(random(gfx->width()), random(gfx->height()), random(30), random(0xffff));
  }

  // Draw random circle in gfx2
  gfx2->drawLine(random(gfx->width()), random(gfx->height()), random(gfx->width()), random(gfx->height()), random(0xffff));

  delay(500); // 1 second
}



rpPico2W_Arduino_GFX_Dual_cube.ino, floating cube.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.  
- 2.4 inch 240×320 ST7789 SPI IPS
- 2.0 inch 240x320 ST7789 SPI IPS
Display Floating Cube.

details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-dual.html

Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico

Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html

*/
#include <Arduino_GFX_Library.h>

#define SPI_SCK       18
#define SPI_MOSI      19
#define TFT_RST 22
#define TFT_DC  21
#define TFT_CS  17

#define TFT2_RST 28
#define TFT2_DC  27
#define TFT2_CS  26

#define TFT_BL  20

#define TFT_ROTATION 0
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
#define TFT_COLSTART 0
#define TFT_ROWSTART 0

#define TFT2_ROTATION 0
#define TFT2_WIDTH 240
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 0
#define TFT2_ROWSTART 0

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT_DC, TFT_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, TFT_ROTATION, true /* IPS */,
                                      TFT_WIDTH, TFT_HEIGHT,
                                      TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *gfx2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
                                       TFT2_WIDTH, TFT2_HEIGHT,
                                       TFT2_COLSTART, TFT2_ROWSTART);

/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

void setup(void)
{

  delay(2000);
  Serial.begin(115200);
  delay(500);

  Serial.println("--- Start ---");

  // Serial.setDebugOutput(true);
  // while(!Serial);
  Serial.println("Arduino_GFX_Library color test");

  // Init Display
  if (!gfx->begin())
  {
    Serial.println("gfx->begin() failed!");
  }
  gfx->fillScreen(RGB565_BLACK);
  // Init Display
  if (!gfx2->begin())
  {
    Serial.println("gfx2->begin() failed!");
  }
  gfx2->fillScreen(RGB565_BLACK);

  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);  //Turn On Backlight

  gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
  gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, RGB565_WHITE);

  gfx->setCursor(10, 10);
  gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx->println("Raspberry Pi Pico 2");
  gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
  gfx->println();
  gfx->println("Arduino_GFX_Library");

  gfx2->setCursor(10, 10);
  gfx2->setTextSize(2 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx2->println("Dual ST7789 exercise");
  gfx2->println("Floating Cube");

  delay(5000); // 5 seconds

  gfx->fillScreen(RGB565_BLACK);
  gfx2->fillScreen(RGB565_BLACK);
}

float angle = 0;
float scale = 2000;
float distance = 1000;

float cube[8][3] = {
  {-20, -20, -20}, {20, -20, -20}, {20, 20, -20}, {-20, 20, -20},
  {-20, -20,  20}, {20, -20,  20}, {20, 20,  20}, {-20, 20,  20}
};

int edges[12][2] = {
  {0,1},{1,2},{2,3},{3,0},
  {4,5},{5,6},{6,7},{7,4},
  {0,4},{1,5},{2,6},{3,7}
};

void rotateZ(float &x, float &y, float angle) {
  float tmpX = x * cos(angle) - y * sin(angle);
  float tmpY = x * sin(angle) + y * cos(angle);
  x = tmpX; y = tmpY;
}

void drawCube(Arduino_GFX *g, float ang){
  g->fillScreen(RGB565_BLACK);

  int projected[8][2];
  for (int i = 0; i < 8; i++) {
    float x = cube[i][0], y = cube[i][1], z = cube[i][2];
    rotateZ(x, y, ang);
    rotateZ(y, z, ang * 0.5);

    int sx = (int)(x * scale / (z + distance)) + g->width()/2;
    int sy = (int)(y * scale / (z + distance)) + g->height()/2;
    projected[i][0] = sx;
    projected[i][1] = sy;
  }

  for (int e = 0; e < 12; e++) {
    int a = edges[e][0], b = edges[e][1];
    g->drawLine(projected[a][0], projected[a][1],
                  projected[b][0], projected[b][1], RGB565_WHITE);
  }

}

void loop() {

  // Draw on gfx
  drawCube(gfx, angle);
  drawCube(gfx2, angle);

  angle += 0.05;
  delay(30);
}


In order to prevent the noticeable flicking, the following exercise use canvas as buffer before display.
 
rpPico2W_Arduino_GFX_Dual_cube_canvas.ino, floating cube using canvas.
/*
Raspberry Pi Pico 2 W display on dual LCD using Arduino_GFX_Library.  
- 2.4 inch 240×320 ST7789 SPI IPS
- 2.0 inch 240x320 ST7789 SPI IPS
Display Floating Cube on Canvas.

details:
https://coxxect.blogspot.com/2026/01/raspberry-pi-pico-2-w-display-on-dual.html

Using board of Raspberry Pi Pico/RP2040/RP2350 by Earle F. Philhower III in Boards Manager.
https://github.com/earlephilhower/arduino-pico

Install Earle Philhower Raspberry Pi Pico Arduino core in Arduino IDE
https://coxxect.blogspot.com/2023/08/install-earle-philhower-raspberry-pi.html

*/
#include <Arduino_GFX_Library.h>

#define SPI_SCK       18
#define SPI_MOSI      19
#define TFT_RST 22
#define TFT_DC  21
#define TFT_CS  17

#define TFT2_RST 28
#define TFT2_DC  27
#define TFT2_CS  26

#define TFT_BL  20

#define TFT_ROTATION 0
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
#define TFT_COLSTART 0
#define TFT_ROWSTART 0

#define TFT2_ROTATION 0
#define TFT2_WIDTH 240
#define TFT2_HEIGHT 320
#define TFT2_COLSTART 0
#define TFT2_ROWSTART 0

/* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(TFT_DC, TFT_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);
Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(TFT2_DC, TFT2_CS, SPI_SCK, SPI_MOSI, GFX_NOT_DEFINED /* MISO */);

/* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
Arduino_GFX *gfx = new Arduino_ST7789(bus, TFT_RST, TFT_ROTATION, true /* IPS */,
                                      TFT_WIDTH, TFT_HEIGHT,
                                      TFT_COLSTART, TFT_ROWSTART);
Arduino_GFX *gfx2 = new Arduino_ST7789(bus2, TFT2_RST, TFT2_ROTATION, true /* IPS */,
                                       TFT2_WIDTH, TFT2_HEIGHT,
                                       TFT2_COLSTART, TFT2_ROWSTART);

/*******************************************************************************
 * End of Arduino_GFX setting
 ******************************************************************************/

Arduino_Canvas *canvas = new Arduino_Canvas(gfx->width(), gfx->height(), gfx);
Arduino_Canvas *canvas2 = new Arduino_Canvas(gfx2->width(), gfx2->height(), gfx2);

void setup(void)
{

  delay(2000);
  Serial.begin(115200);
  delay(500);

  Serial.println("--- Start ---");

  // Serial.setDebugOutput(true);
  // while(!Serial);
  Serial.println("Arduino_GFX_Library color test");

  // Init Display
  gfx->begin();
  gfx2->begin();
  canvas->begin();
  canvas2->begin();

  gfx2->fillScreen(RGB565_BLACK);

  pinMode(TFT_BL, OUTPUT);
  digitalWrite(TFT_BL, HIGH);  //Turn On Backlight

  gfx->drawRect(0, 0, gfx->width()-1, gfx->height()-1, RGB565_WHITE);
  gfx2->drawRect(0, 0, gfx2->width()-1, gfx2->height()-1, RGB565_WHITE);

  gfx->setCursor(10, 10);
  gfx->setTextSize(3 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx->println("Raspberry Pi Pico 2");
  gfx->setTextSize(2 /* x scale */, 2 /* y scale */, 2 /* pixel_margin */);
  gfx->println();
  gfx->println("Arduino_GFX_Library");

  gfx2->setCursor(10, 10);
  gfx2->setTextSize(2 /* x scale */, 3 /* y scale */, 3 /* pixel_margin */);
  gfx2->println("Dual ST7789 exercise");
  gfx2->println("Floating Cube on Canvas");

  delay(5000); // 5 seconds

  gfx->fillScreen(RGB565_BLACK);
  gfx2->fillScreen(RGB565_BLACK);
}

float angle = 0;
float scale = 2000;
float distance = 1000;

float cube[8][3] = {
  {-20, -20, -20}, {20, -20, -20}, {20, 20, -20}, {-20, 20, -20},
  {-20, -20,  20}, {20, -20,  20}, {20, 20,  20}, {-20, 20,  20}
};

int edges[12][2] = {
  {0,1},{1,2},{2,3},{3,0},
  {4,5},{5,6},{6,7},{7,4},
  {0,4},{1,5},{2,6},{3,7}
};

void rotateZ(float &x, float &y, float angle) {
  float tmpX = x * cos(angle) - y * sin(angle);
  float tmpY = x * sin(angle) + y * cos(angle);
  x = tmpX; y = tmpY;
}

void drawCube(Arduino_GFX *g, float ang){
  g->fillScreen(RGB565_BLACK);

  int projected[8][2];
  for (int i = 0; i < 8; i++) {
    float x = cube[i][0], y = cube[i][1], z = cube[i][2];
    rotateZ(x, y, ang);
    rotateZ(y, z, ang * 0.5);

    int sx = (int)(x * scale / (z + distance)) + g->width()/2;
    int sy = (int)(y * scale / (z + distance)) + g->height()/2;
    projected[i][0] = sx;
    projected[i][1] = sy;
  }

  for (int e = 0; e < 12; e++) {
    int a = edges[e][0], b = edges[e][1];
    g->drawLine(projected[a][0], projected[a][1],
                  projected[b][0], projected[b][1], RGB565_WHITE);
  }

}

void drawCubeCanvas(Arduino_Canvas *c, float ang){
  c->fillScreen(RGB565_BLACK);

  int projected[8][2];
  for (int i = 0; i < 8; i++) {
    float x = cube[i][0], y = cube[i][1], z = cube[i][2];
    rotateZ(x, y, ang);
    rotateZ(y, z, ang * 0.5);

    int sx = (int)(x * scale / (z + distance)) + c->width()/2;
    int sy = (int)(y * scale / (z + distance)) + c->height()/2;
    projected[i][0] = sx;
    projected[i][1] = sy;
  }

  for (int e = 0; e < 12; e++) {
    int a = edges[e][0], b = edges[e][1];
    c->drawLine(projected[a][0], projected[a][1],
                  projected[b][0], projected[b][1], RGB565_WHITE);
  }

  c->flush();
}

void loop() {

  // Draw on gfx
  drawCube(gfx, angle);
  //drawCubeCanvas(canvas, angle);

  // Draw on gfx2
  //drawCube(gfx2, angle);
  drawCubeCanvas(canvas2, angle);

  angle += 0.05;
  delay(30);
}



Comments

Popular posts from this blog

Drive 320x240 ILI9341 SPI TFT using ESP32-S3 (NodeMCU ESP-S3-12K-Kit) using TFT_eSPI library, in Arduino Framework.

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library