PART 2 - Drawing Bitmap EYES With RP2040-zero and 2 GC9A01 Displays As Ardunio Code

by egocen in Circuits > Arduino

43 Views, 0 Favorites, 0 Comments

PART 2 - Drawing Bitmap EYES With RP2040-zero and 2 GC9A01 Displays As Ardunio Code

Ekran görüntüsü 2025-02-21 122143.png
Ekran görüntüsü 2025-02-21 122152.png

There is EYES.PNG in Public Doly Project site on doly.ai

In addition to the code shared in Part 1, I will be providing a new example.

I will try to convert it to c array and display selected part to two screens with import command.

In this demonstration, I will be exploring a less common approach by sharing a code example that extracts specific sections from a bitmap C array containing various pairs of eye shapes and displays them on two GC9A01 screens. My goal is to show that, although this method is not widely preferred, it is entirely feasible and worth experimenting with.

Sample code below as demo for first row only.

Converting Bitmap Files to C Array

eyes.png

Attached file also converted eyes.bmp to eyes.h

How you can convert a bitmap to a C array:

  1. Open your bitmap file using an appropriate tool (e.g., GIMP or Photoshop) and decide if it should be grayscale or colored.
  2. Save the file in an appropriate format (usually BMP or RGB).
  3. Use an online converter or a specialized tool to convert the bitmap image to a C array. This tool will generate the C code for the image.
  4. Add the generated C code to your project file and write the necessary code to display the image.


Downloads

Import C Array and Display With Drawpixel Command

#include <Arduino_GFX_Library.h>

#include <Arduino.h>

#include "eyes.h"




Arduino_DataBus *bus = new Arduino_RPiPicoSPI(8 /* DC */, 9 /* CS */, 10 /* SCK */, 11 /* MOSI */, 12 /* MISO */, spi1 /* spi */);

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


// İkinci ekran tanımlamaları

Arduino_DataBus *bus2 = new Arduino_RPiPicoSPI(12 /* DC */, 14 /* CS */, 10 /* SCK */, 11 /* MOSI */, 17 /* MISO */, spi1 /* spi */);

Arduino_GFX *gfx2 = new Arduino_GC9A01(bus2, 29 /* RST */, 0 /* rotation */, true /* IPS */, 240 /* width */, 240 /* height */);


/* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */


/*******************************************************************************

* End of Arduino_GFX setting

******************************************************************************/

void setup(void)

{

#ifdef DEV_DEVICE_INIT

DEV_DEVICE_INIT();

#endif

// Init Display

if (!gfx->begin())

{

Serial.println("gfx->begin() failed!");

}

if (!gfx2->begin())

{

Serial.println("gfx2->begin() failed!");

}

gfx->fillScreen(RGB565_BLACK);

gfx2->fillScreen(RGB565_BLACK);


int16_t bitmapWidth = 714;

int16_t bitmapHeight = 603;


gozcagir(3); (means calleyes with section no 3 as startup)

delay(5000); // 5 seconds


}



void loop()

{

gozcagir(random(6)); (means calleyes :call random eyes section between 1 to 6)

delay(2000); // 1 second

}




void gozcagir(int frameno) {


drawRegion(frameno * 100 + 7, 5, frameno * 100 + 100, 55, 5); //x,y,x2,y2,zoom,screen no 1 or 2


}



// calculate and cut selected eyes section

void drawRegion(int x, int y, int x2, int y2, int zoom) {

// Kesit boyutları

int newWidth = x2 - x + 1;

int newHeight = y2 - y + 1;

// Geçici dizi

uint16_t tempArray[newHeight][newWidth];


// Orijinal diziden kesiti geçici diziye kopyalama

for (int i = 0; i < newHeight; i++) {

for (int j = 0; j < newWidth; j++) {

tempArray[i][j] = (eyes[y + i][x + j]);

}

}

// Büyütülmüş görüntü için geçici 2 parça dizi

uint16_t zoomedArray1[newHeight * zoom][(newWidth/2) * zoom];

uint16_t zoomedArray2[newHeight * zoom][(newWidth/2) * zoom];

// Kesiti büyüterek geçici diziye kopyalama

for (int i = 0; i < newHeight; i++) {

for (int j = 0; j < newWidth; j++) {

for (int zx = 0; zx < zoom; zx++) {

for (int zy = 0; zy < zoom; zy++) {

if (j < 50){

zoomedArray1[i * zoom + zy][j * zoom + zx] = tempArray[i][j];

}else{

zoomedArray2[i * zoom + zy][j * zoom + zx] = tempArray[i][j];

}

}

}

}

}

gfx->draw16bitRGBBitmap(8, -5, (uint16_t *)zoomedArray1, (newWidth/2)*zoom, (newHeight)*zoom);

gfx2->draw16bitRGBBitmap(8, -5, (uint16_t *)zoomedArray2, (newWidth/2)*zoom, (newHeight)*zoom);

}