#include <M5StickCPlus.h>

int USE_SPRITE = 0 ; //スプライトを使用するとき1

TFT_eSprite spu = TFT_eSprite(&M5.Lcd); // Sprite object

void setup() {
  M5.begin();
  M5.Lcd.setRotation(3);

  spu.setColorDepth(8);
  spu.createSprite(240, 135);

  randomSeed(analogRead(0));
}

void loop() {
  int r = random(100000);
  if ( USE_SPRITE ) {
    spu.fillSprite( CYAN );
    spu.setCursor(30, 34, 4);  spu.setTextSize(2);
    spu.setTextColor( WHITE, BLUE );
    spu.printf("  %d  \n Sprite ", r );
    spu.pushSprite(0, 0);
  } else {
    M5.Lcd.fillScreen( CYAN );
    M5.Lcd.setCursor(30, 34, 4);  M5.Lcd.setTextSize(2);
    M5.Lcd.setTextColor( WHITE, BLUE );
    M5.Lcd.printf("  %d  \n LCD ", r);
  }

  M5.update();
  if (M5.BtnA.wasReleased()) {
    USE_SPRITE = 1 - USE_SPRITE ; // スプライト使用の切り替え(1なら0、0なら1)
    M5.Beep.tone(1000 + 1000 * USE_SPRITE, 500);
  }
  M5.Beep.update();
  delay(100);
}