Last active
April 15, 2020 06:35
-
-
Save mongonta0716/e3f20b64b5731e393d69d55c5ed9dd2b to your computer and use it in GitHub Desktop.
Comparison of LovyanGFX and M5StackLibrary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 基本的な使い方 | |
// ヘッダをincludeします。 | |
//#include <LovyanGFX.hpp> | |
#include <M5Stack.h> | |
// 対応機種をArduino環境で使う場合は、特別な設定は不要です。 | |
static M5Display lcd; // LGFXのインスタンスを作成。 | |
static TFT_eSprite sprite(&lcd); // スプライトを使う場合はLGFX_Spriteのインスタンスを作成。 | |
uint32_t targettime = 0; | |
void setup(void) | |
{ | |
M5.begin(); | |
lcd.init(); | |
lcd.setRotation(1); | |
lcd.fillScreen(0); // 黒で塗り潰し | |
lcd.clear(0xFFFF); // 白で塗り潰し | |
lcd.clear(); // 黒で塗り潰し | |
lcd.startWrite(); // SPIバス確保 | |
for (uint32_t x = 0; x < 128; ++x) { | |
for (uint32_t y = 0; y < 128; ++y) { | |
lcd.drawPixel(x, y, lcd.color565(255 - x*2, x + y, 255 - y*2)); | |
} | |
} | |
lcd.endWrite(); // SPIバス解放 | |
delay(1000); | |
sprite.createSprite(65, 65); // 幅65、高さ65でスプライトを作成。 | |
for (uint32_t x = 0; x < 64; ++x) { | |
for (uint32_t y = 0; y < 64; ++y) { | |
sprite.drawPixel(x, y, lcd.color565(255 - x*4, (x + y)*2, 255 - y*4)); // スプライトに描画 | |
} | |
} | |
sprite.drawRect(0, 0, 65, 65, 0xFFFF); | |
sprite.pushSprite(64, 0); // lcdの座標64,0にスプライトを描画 | |
sprite.pushSprite(0, 64); // lcdの座標0,64にスプライトを描画 | |
delay(1000); | |
targettime = millis(); | |
} | |
uint32_t loopsec = 0; | |
uint32_t count = 0; | |
uint32_t lastcount = 0; | |
uint32_t count_per_sec = 0; | |
void loop(void) | |
{ | |
lcd.setPivot(lcd.width()>>1, lcd.width()>>1); | |
int32_t center_x = lcd.width()/2; | |
int32_t center_y = lcd.height()/2; | |
for (int angle = 0; angle <= 360; ++angle) { | |
sprite.pushRotated(angle); | |
sprite.pushSprite(random(lcd.width()), random(lcd.height())); | |
count++; | |
lcd.setCursor(0, 180); | |
lcd.setTextSize(3); | |
lcd.setTextColor(TFT_BLACK, TFT_YELLOW); | |
lcd.printf("%d\n", count); | |
lcd.printf("%d/sec",count_per_sec); | |
if ((millis() - targettime) > 1000) { | |
count_per_sec = (count - lastcount); | |
lastcount = count; | |
targettime = millis(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment