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、スタックチャンで時間を表示する。(SNTP)

Last updated at Posted at 2025-03-07

注意、いろいろ

  • 過去ログを見よ!!!
  • 3.1.3
  • 書き換えてください。

const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";


結果

image_original (54).jpg

image_original (55).jpg

プログラム




//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




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?