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?

「時:分」ATOMS3 Lite (背面)+SSD1306、時計で遊ぶ。(教育漢字)((S)シンプル)NTP

Last updated at Posted at 2025-12-27

いろいろ注意

  • 過去ログを見よ!!!
  • 適度に修正

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

結果

IMG_0951.jpeg

プログラム





//SSD1306_SNTP_HH_MM_k1_ATOMS3_1


//ヘッダーファイル
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include <time.h>
#include <misakiUTF16.h>  //8x8ドット教育漢字


//定義
#define SCREEN_WIDTH 128     // OLED display width, in pixels
#define SCREEN_HEIGHT 64     // OLED display height, in pixels
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const char *ssid = "ご自宅のSSID";
const char *password = "ご自宅のパスワード";


//2倍角の文字列を表示
//xは、画面上の横の位置
//yは、画面上の縦の位置
//ptrは、表示したい、漢字まじりの文字列
//
void k_print(int x, int y, char *ptr) {

  unsigned char font[8];        // フォント格納バッファ 入力
  unsigned char font2[16 * 2];  // フォント格納バッファ 出力

  while (*ptr) {  // 文字列分ループ

    ptr = getFontData(font, ptr, true);  // 1文字分のフォント取得
    if (!ptr) {
      break;  // エラーの場合は終了
    }  //endif

    for (int i = 0; i < 8; i++) {  //フォントの2倍角化ループ

      int a = font[i];   //入力フォントの読み出し
      int b = (a >> 4);  //入力フォントの読み出し
      int s;             //一時変数
      int j = i << 2;    //2倍角出力フォントのカウンター 4倍 j=i*4


      //上位4ビット b=b+b = b=b<<1
      s = 0;
      s = s | (0b00000001 & b); b = b + b;
      s = s | (0b00000110 & b); b = b + b;
      s = s | (0b00011000 & b); b = b + b;
      s = s | (0b01100000 & b); b = b + b;
      s = s | (0b10000000 & b);
      font2[j + 0] = s;
      font2[j + 2] = s;

      //下位4ビット a=a+a = a=a<<1
      s = 0;
      s = s | (0b00000001 & a); a = a + a;
      s = s | (0b00000110 & a); a = a + a;
      s = s | (0b00011000 & a); a = a + a;
      s = s | (0b01100000 & a); a = a + a;
      s = s | (0b10000000 & a);
      font2[j + 1] = s;
      font2[j + 3] = s;

    }  //for i

    //ビットマップの表示
    display.drawBitmap(x, y, font2, 16, 16, WHITE);
    x = x + 16;

  }  //while

}  //k_print


//初期化
void setup() {

  //I2Cのポートの変更
  Wire.begin(39, 38);  //M5ATOMS3

  // I2Cアドレスは使用するディスプレイに合わせて変更する
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);

  //WiFiの初期化
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  delay(3000);  //決め打ちなので、おかしかったら調整してね! wifiの待ち0.5*6
  configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");

}  //setup


//メインループ
void loop() {

  time_t t;       //経過秒
  struct tm *tm;  //時間の実体とポインター

  t = time(NULL);      //経過秒を取得する
  tm = localtime(&t);  //経過秒を時間の構造体に変換する

  //set time 時間合わせの再設定
  static int set_1H = 0;
  if (set_1H > ((60 * 60) - 1)) {  // 1 hour ?
    set_1H = 0;                    //counter reset
    configTzTime("JST-9", "ntp.nict.jp", "ntp.jst.mfeed.ad.jp");
  }  //endif
  set_1H++;  //カウントアップ


  //開始 画面の表示

  //01234568
  // 11h11m

  // 画面表示をクリア (仮想VRAM)
  display.clearDisplay();

  char str1[3] = { 0, 0, 0 }; //一時文字列

  k_print(16 * 2, 16 * 0, "現在時刻");  //2倍角の文字列を表示

  str1[0] = '0' + (tm->tm_hour) / 10;
  str1[1] = '0' + (tm->tm_hour) % 10;

  k_print(16 * 1, 16 * 2, str1);  //2倍角の文字列を表示
  k_print(16 * 3, 16 * 2, "時");  //2倍角の文字列を表示

  str1[0] = '0' + (tm->tm_min) / 10;
  str1[1] = '0' + (tm->tm_min) % 10;

  k_print(16 * 4, 16 * 2, str1);  //2倍角の文字列を表示
  k_print(16 * 6, 16 * 2, "分");  //2倍角の文字列を表示

  // 描画バッファの内容を画面に表示
  display.display();

  //終了 画面の表示


  delay(1000);  //1秒待つ

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