1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5StampS3、スタックチャンで文字列を表示して遊ぶ。

Last updated at Posted at 2025-03-05

注意、いろいろ

  • 過去ログを見よ!!!
  • 3.1.3
  • 「絶滅メディア博物」「スタックチャンフェス」

結果

image_original (53).jpg

プログラム



//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);
  }
}


1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?