LoginSignup
0
0

70歳の挑戦... パラレル接続のTFTを使ってみた(その3)

Last updated at Posted at 2024-04-30

 「パラレル接続のTFTモジュールを使ってみた(その2)」の続編です。前回、このモジュールを「ArduinoIDE」の標準ライブラリで動かした場合の具体的な内容は端折ったので今回紹介します。
 「ESP32 Dev Module」ボード上で、「Arduino_GFX_Library」を用い「UTFT_Demo_480x320.ino」を動作させた場合のスコア(1ループ後)が下の写真です。

StandardLib.jpg

ご覧のように「1375msecs」となっています。この状態で「TFT_eSPIライブラリ」に変更すると所要時間が半減、「LovyanGFXライブラリ」だと1/3になるということです。以下にそのコードを示します。このコードは「TFT_eSPIライブラリ」のものなので、標準ライブラリで動くよう少し改変しています。

UTFT_Demo_480x320.ino
// 3.95" TFT LCD Parallel Shield Test on ESP32 Dev Module

#include <Arduino_GFX_Library.h>

Arduino_DataBus *bus = new Arduino_SWPAR8(12/* 14TFT_DC*/,27/*TFT_CS*/,14/*25 WR*/, 32/*RD*/, 
                  23/*D0*/,19/*D1*/,18/*D2*/,26/*D3*/,5/*21 D4*/,4/*D5*/,0/*D6*/,15/*2 D7*/);

// ? Touch Pin : DC(RS)=aXM=12, WR=aYP=14 (analog pin)  YM=22,XP=21 (digital pin)

Arduino_GFX *tft = new Arduino_ILI9488(bus, 33/*A4 DF_GFX_RST*/, 0 /*rotation*/, false /*IPS*/);

#define WAIT 0
#define CENTER 230
#define GREY 0x7BEF
uint32_t runTime = 0;

void setup()
{
  randomSeed(analogRead(0));
  Serial.begin(115200);
  Serial.println("parallel tft test");
// Setup the LCD
  tft->begin();
  tft->setRotation(1);
}

void loop()
{
  int buf[478];
  int x, x2;
  int y, y2;
  int r;

  runTime = millis();
// Clear the screen and draw the frame
  tft->fillScreen(BLACK);

  tft->fillRect(0, 0, 480, 13, RED);

  tft->fillRect(0, 305, 480, 320, GREY);
  tft->setTextColor(BLACK,RED);
  tft->setCursor(CENTER, 155);
  tft->println("Standard Graphic");
  tft->setTextColor(YELLOW);
  tft->setCursor(309,1);
  tft->println("Adapted by Bodmer");
  tft->drawRect(0, 14, 479, 305-14, BLUE);

// Draw crosshairs
  tft->drawLine(239, 15, 239, 304, BLUE);
  tft->drawLine(1, 159, 478, 159, BLUE);
  for (int i=9; i<470; i+=10)
    tft->drawLine(i, 157, i, 161, BLUE);
  for (int i=19; i<220; i+=10)
    tft->drawLine(237, i, 241, i, BLUE);

// Draw sin-, cos- and tan-lines  
  tft->setTextColor(CYAN);
  tft->setCursor(5, 15);
  tft->println("Sin");
  for (int i=1; i<478; i++)
  {
    tft->drawPixel(i,159+(sin(((i*1.13)*3.14)/180)*95),CYAN);
  }
  
  tft->setTextColor(RED);
  tft->setCursor(5, 30);
  tft->println("Cos");
  for (int i=1; i<478; i++)
  {
    tft->drawPixel(i,159+(cos(((i*1.13)*3.14)/180)*95),RED);
  }

  tft->setTextColor(YELLOW);
  tft->setCursor(5, 45);
  tft->println("Tan");
  for (int i=1; i<478; i++)
  {
    tft->drawPixel(i,159+(tan(((i*1.13)*3.14)/180)),YELLOW);
  }

  delay(WAIT);

  tft->fillRect(1,15,478-1,304-15,BLACK);
  tft->drawLine(239, 15, 239, 304,BLUE);
  tft->drawLine(1, 159, 478, 159,BLUE);

// Draw a moving sinewave
int col = 0;
  x=1;
  for (int i=1; i<(477*15); i++) 
  {
    x++;
    if (x==478)
      x=1;
    if (i>478)
    {
      if ((x==239)||(buf[x-1]==159))
        col = BLUE;
      else
        tft->drawPixel(x,buf[x-1],BLACK);
    }
    y=159+(sin(((i*0.7)*3.14)/180)*(90-(i / 100)));
    tft->drawPixel(x,y, BLUE);
    buf[x-1]=y;
  }

  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

// Draw some filled rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        col = MAGENTA;
        break;
      case 2:
        col = RED;
        break;
      case 3:
        col = GREEN;
        break;
      case 4:
        col = BLUE;
        break;
      case 5:
        col = YELLOW;
        break;
    }
    tft->fillRect(150+(i*20), 70+(i*20), 60, 60,col);
  }

  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

// Draw some filled, rounded rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        col = MAGENTA;
        break;
      case 2:
        col = RED;
        break;
      case 3:
        col = GREEN;
        break;
      case 4:
        col = BLUE;
        break;
      case 5:
        col = YELLOW;
        break;
    }
    tft->fillRoundRect(270-(i*20), 70+(i*20), 60, 60, 3, col);
  }
  
  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

// Draw some filled circles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        col = MAGENTA;
        break;
      case 2:
        col = RED;
        break;
      case 3:
        col = GREEN;
        break;
      case 4:
        col = BLUE;
        break;
      case 5:
        col = YELLOW;
        break;
    }
    tft->fillCircle(180+(i*20),100+(i*20), 30,col);
  }
  
  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

// Draw some lines in a pattern

  for (int i=15; i<304; i+=5)
  {
    tft->drawLine(1, i, (i*1.6)-10, 303, RED);
  }

  for (int i=304; i>15; i-=5)
  {
    tft->drawLine(477, i, (i*1.6)-11, 15, RED);
  }

  for (int i=304; i>15; i-=5)
  {
    tft->drawLine(1, i, 491-(i*1.6), 15, CYAN);
  }

  for (int i=15; i<304; i+=5)
  {
    tft->drawLine(477, i, 490-(i*1.6), 303, CYAN);
  }
  
  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

// Draw some random circles
  for (int i=0; i<100; i++)
  {
    x=32+random(416);
    y=45+random(226);
    r=random(30);
    tft->drawCircle(x, y, r,random(0xFFFF));
  }

  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

// Draw some random rectangles
  for (int i=0; i<100; i++)
  {
    x=2+random(476);
    y=16+random(289);
    x2=2+random(476);
    y2=16+random(289);
    if (x2<x) {
      r=x;x=x2;x2=r;
    }
    if (y2<y) {
      r=y;y=y2;y2=r;
    }
    tft->drawRect(x, y, x2-x, y2-y,random(0xFFFF));
  }

  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

// Draw some random rounded rectangles
  for (int i=0; i<100; i++)
  {
    x=2+random(476);
    y=16+random(289);
    x2=2+random(476);
    y2=16+random(289);
    if (x2<x) {
      r=x;x=x2;x2=r;
    }
    if (y2<y) {
      r=y;y=y2;y2=r;
    }
    tft->drawRoundRect(x, y, x2-x, y2-y, 3,random(0xFFFF));
  }

  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

  for (int i=0; i<100; i++)
  {
    x=2+random(476);
    y=16+random(289);
    x2=2+random(476);
    y2=16+random(289);
    col=random(0xFFFF);
    tft->drawLine(x, y, x2, y2,col);
  }

  delay(WAIT);
  
  tft->fillRect(1,15,478-1,304-15,BLACK);

  for (int i=0; i<10000; i++)
  {
    tft->drawPixel(2+random(476), 16+random(289),random(0xFFFF));
  }

  delay(WAIT);

  tft->fillRect(0, 0, 480, 320, BLUE);

  tft->fillRoundRect(160, 70, 319-160, 169-70, 3,RED);
  
  tft->setTextColor(WHITE);
  tft->setCursor(CENTER, 93);
  tft->println("That's it!");
  tft->setCursor(CENTER, 119);
  tft->println("Restarting in");
  tft->setCursor(CENTER, 132);
  tft->println("a few seconds...");
  tft->setTextColor(GREEN);
  tft->setCursor(CENTER, 280);
  tft->println("Runtime: (msecs)");
  //tft->setTextDatum(TC_DATUM); not in Standard library
  runTime = millis()-runTime;
  tft->setCursor(CENTER, 300);
  tft->println(String(runTime));
  //tft->setTextDatum(TL_DATUM);
  delay (10000);
}

今回は以上です。最後まで見ていただきありがとうございました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0