注意、いろいろ
- 過去ログを見よ!!!
- 3.1.3
- 「絶滅メディア博物」「スタックチャンフェス」
結果
プログラム
//balloon_1_M5StampS3_1
//インクルド
#include <M5UnitGLASS2.h>
#include <M5Unified.h>
#include <Avatar.h>
//定義
using namespace m5avatar; //ネームスペース
Avatar avatar; //アバターの実体の定義
const char* lyrics[] = {"やん坊","まん坊","天気予報"};//ポインター配列
const int lyricsSize = sizeof(lyrics) / sizeof(char*);//配列の個数
int lyricsIdx = 0;//カウンター
//初期化
void setup(){
  auto cfg=M5.config();
  cfg.unit_glass2.pin_sda=13;
  cfg.unit_glass2.pin_scl=15;
  M5.begin(cfg);//M5の初期化
  avatar.setScale(.45);
  avatar.setPosition(-88-17,-96);
  avatar.init();//アバターの初期化 (アバターは、バックグランドで動く)
  //avatar.setSpeechFont(&fonts::lgfxJapanGothic_12);//日本語フォント
  avatar.setSpeechFont(&fonts::lgfxJapanGothicP_16);//日本語フォント
}//setup
//メインループ
void loop(){
  //M5.update(); 
  //if (M5.BtnA.wasPressed()){//ボタンが押された場合
    //lyricsIdx++は、後で1プラスする
    //余りを求める処理は、0から文字列のポインター配列サイズぶん繰り返す
    //「l」に文字列のポインターが入る
    const char* l = lyrics[lyricsIdx++ % lyricsSize];
    avatar.setSpeechText(l); //テキストの表示
    avatar.setExpression(Expression::Happy); //表情を変える
    avatar.setMouthOpenRatio(0.7); //口を動かす
    delay(200);//0.2秒待つ
    avatar.setMouthOpenRatio(0); //口を閉じる
  //}//if
  delay(3000);//3秒待つ
}//loop
・
・
・
おまけ(元のサンプル)
#include <M5Unified.h>
#include <Avatar.h>
using namespace m5avatar;
Avatar avatar;
const char* lyrics[] = {"Hey,",     "diddle,",     "diddle,",        "The cat",
                         "and",      "the fiddle,", "The cow",        "jumped",
                         "over",     "the moon.",   "The little dog", "laughed",
                         "to",       "see",         "such sport,",    "And",
                         "the dish", "ran away",    "with the spoon."};
const int lyricsSize = sizeof(lyrics) / sizeof(char*);
int lyricsIdx = 0;
void setup()
{
  M5.begin();
  avatar.init();
}
void loop()
{
  M5.update();
  if (M5.BtnA.wasPressed())
  {
    const char* l = lyrics[lyricsIdx++ % lyricsSize];
    avatar.setSpeechText(l);
    avatar.setMouthOpenRatio(0.7);
    delay(200);
    avatar.setMouthOpenRatio(0);
  }
}
