TinyArcade
#include <TinyScreen.h>
static const unsigned long FPS = 30;
static const unsigned long INTERVAL_TIME = 1000000 / FPS;
TinyScreen tiny_screen = TinyScreen(TinyScreenPlus);
unsigned long micros_time;
void setup()
{
tiny_screen.begin();
tiny_screen.setBitDepth(TSBitDepth8);
tiny_screen.setBrightness(8);
tiny_screen.setFont(liberationSansNarrow_12ptFontInfo);
tiny_screen.fontColor(TS_8b_White, TS_8b_Black);
micros_time = micros();
}
void loop()
{
unsigned long interval_time = micros() - micros_time;
if(interval_time > INTERVAL_TIME)
{
char text[128];
// 30FPS間隔で行う処理 (画面更新、ゲーム進行など)
tiny_screen.clearScreen();
tiny_screen.setCursor(0, 0);
sprintf(text, "FPS %lu", 1000000 / interval_time);
tiny_screen.print(text);
tiny_screen.setCursor(0, 12);
sprintf(text, "interval_time = %lums", interval_time);
tiny_screen.print(text);
micros_time = micros();
}
// 最速で行う処理 (サウンド処理など)
}