//balloon_sntp_1_M5StampS3_2
//インクルド
#include <M5UnitGLASS2.h>
#include <M5Unified.h>
#include <Avatar.h>
#include <WiFi.h>
#include <time.h>
//定義
using namespace m5avatar; //ネームスペース
Avatar avatar; //アバターの実体の定義
const char* lyrics[] = {"今何時","何時カナ","時間"};//ポインター配列
const int lyricsSize = sizeof(lyrics) / sizeof(char*);//配列の個数
int lyricsIdx = 0;//カウンター
#define JST 3600*9
const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";
//初期化
void setup(){
//WiFiの初期化
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
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);//日本語フォント
delay(3000);//決め打ちなので、おかしかったら調整してね! wifiの待ち0.5*6
configTime( JST, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
}//setup
//メインループ
void loop(){
time_t t; //経過秒
struct tm *tm; //時間の実体とポインター
t = time(NULL); //経過秒を取得する
tm = localtime(&t); //経過秒を時間の構造体に変換する
//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); //口を閉じる
delay(2000);//1秒待つ
//時間
char hh[20];
sprintf(hh,"%02d:%02d",tm->tm_hour, tm->tm_min);
avatar.setSpeechText(hh); //テキストの表示
avatar.setMouthOpenRatio(0.7); //口を動かす
delay(200);//0.2秒待つ
avatar.setMouthOpenRatio(0); //口を閉じる
//}//if
delay(4000);//3秒待つ
}//loop