PART3 - Drawing Random Eyes Using Ardunio_GFX_Library With 2xGC9A01 and RP2040-zero

by egocen in Circuits > Arduino

52 Views, 0 Favorites, 0 Comments

PART3 - Drawing Random Eyes Using Ardunio_GFX_Library With 2xGC9A01 and RP2040-zero

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

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

To draw an eye shape using the Arduino_GFX_Library, follow these steps:

  1. Install the Ardunio_GFX_Library
  2. Set up the hardware, including connecting an two GC9A01and sound sensor



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

Complete the connections. Install the library.

The code creates an eye drawing using given angle and color variables and includes functionality to stop the drawing when a signal is received from a sound sensor. This integration of the sound sensor with the Arduino_GFX_Library allows for interactive control, ensuring that the eye drawing pauses or stops based on auditory input.

here is my sample;


---------------

#include <Arduino_GFX_Library.h>

#include <Arduino.h>

#include "hardware/adc.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

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


int zamansay=0; //timecounter

int sespin = 26; // GPIO26ADC sound sensör pini olarak tanımla

int sesValue = 0; // Sensör değerini saklamak için değişken

int hata, adres, cihaz_sayisi; // Değişkenlerimizi tanımlıyoruz



void setup(void)

{

#ifdef DEV_DEVICE_INIT

DEV_DEVICE_INIT();

#endif



Serial.begin(115200); // Seri iletişim başlat


// Init Display

if (!gfx->begin())

{

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

}

if (!gfx2->begin())

{

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

}

gfx->fillScreen(RGB565_WHITE);

gfx2->fillScreen(RGB565_WHITE);


//startup anim

gozciz (1,90,-1,RGB565_BLUE); //colour, display 1 or 2 ,size, eye angle

gozciz (2,90,-1,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

gozciz (1,90,-1,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

gozciz (2,90,-1,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

delay(400);

gkapakciz(80); eyelid rectangular

delay(5000); // 5 seconds

gfx->fillScreen(RGB565_WHITE);

gfx2->fillScreen(RGB565_WHITE);

//stabil eyes

gozciz (1,80,-1,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

gozciz (2,80,-1,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

}


void loop()

{

if (zamansay > 0) { //timecounter like millis

//Serial.println(zamansay);

zamansay= zamansay - 1; countdown time

}

sesornek(); //random eyes stop with sound sensor

}

void gkapakciz(int y)

{

gfx->fillRect(0, 0, 240, y, 0x8410);

gfx2->fillRect(0, 0, 240, y, 0x8410);

}


void gozciz(int goz,int boyut, int aci, int renk){

int beyaz=100;

int kx = 120 ;

int ky = 120 ;

//mavi,siyah merkez bulma -1 sa orta


if (aci != -1){

kx = (120 + (beyaz-boyut) * cos(aci * (PI / 180.0)));

ky = 120 - (beyaz-boyut) * sin(aci * (PI / 180.0));

}

//parıltı merkezi

int x = kx + boyut * sqrt(2) / 2;

int y = ky - boyut * sqrt(2) / 2;


if (goz==1) //sol left

{

// Sol gözü çiz

gfx->fillCircle(120, 120, beyaz, RGB565_WHITE); // Gözün beyaz kısmı

gfx->fillCircle(kx, ky, boyut, renk); // Mavi iris

gfx->fillCircle(kx, ky, boyut-20, RGB565_BLACK); // Siyah pupil

gfx->fillCircle(x-30, y+30, (boyut-20)/10, RGB565_WHITE); // Beyaz parıltı


}else{ //sag right

gfx2->fillCircle(120, 120, beyaz, RGB565_WHITE); // Gözün beyaz kısmı

gfx2->fillCircle(kx, ky, boyut, renk); // Mavi iris

gfx2->fillCircle(kx, ky, boyut-20, RGB565_BLACK); // Siyah pupil

gfx2->fillCircle(x-30, y+30, (boyut-20)/10, RGB565_WHITE); // Beyaz parıltı


}

}

void sesornek() {

//sensor kontrol


sesValue = analogRead(sespin);

Serial.println(sesValue);

if (sesValue < 1000) {

gozciz (1,90,-1,RGB565_BLUE); //if angle -1 normal eyes else 0-360 degree anlges

gozciz (2,90,-1,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

zamansay=20000; continue in 20000 loop

}

if (zamansay == 1 ){ draw random eyes since timecount

//Default display

gfx->fillScreen(RGB565_BLACK); turn the normal eyes end of timecount

gfx2->fillScreen(RGB565_BLACK);


int ranboyut = random(40, 80);

int ranaci = random(0, 360);

gozciz (1,ranboyut,ranaci,RGB565_BLUE); //Draw random size, random angle but blue! even time goes to zero

gozciz (2,ranboyut,ranaci,RGB565_BLUE); //sag/sol goz,boyut, konum açı,renk

zamansay=200000;//since 200000 loop

}

}