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?

M5NanoC6、8x8 Puzzle Unit (Unit Puzzle ?)で時計。(SNTP)

Posted at

x 過去ログを見よ!!!

書き換える


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

結果

イメージ

image_original (43).jpg

プログラム




//RGBLED8x8_SNTP_M5NanoC6_1


//インクルド
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <WiFi.h>
#include <time.h>


//定義
#define MAX_X 8
#define MAX_Y 8
#define NUM_LEDS 64
Adafruit_NeoPixel strip(NUM_LEDS, 2, NEO_GRB + NEO_KHZ800);
#define JST 3600 * 9

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

unsigned char Pixel[8][8][3]; //キャラクターRAM(カラー)

// 'font8x8_0_9', 8x64px
unsigned char font8x8_0_9 [] =
{
  0x81, 0x7c, 0x7a, 0x76, 0x6e, 0x5e, 0x3e, 0x81, //0
  0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, //1
  0x81, 0x7e, 0xfe, 0xfe, 0xc1, 0xbf, 0x7f, 0x00, //2
  0x81, 0x7e, 0xfe, 0xc0, 0xfe, 0xfe, 0x7e, 0x81, //3
  0xe3, 0xdb, 0xbb, 0x7b, 0x00, 0xfb, 0xfb, 0xfb, //4
  0x00, 0x7f, 0x7f, 0x01, 0xfe, 0xfe, 0x7e, 0x81, //5
  0x81, 0x7e, 0x7f, 0x01, 0x7e, 0x7e, 0x7e, 0x81, //6
  0x00, 0x7e, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, //7
  0x81, 0x7e, 0x7e, 0x81, 0x7e, 0x7e, 0x7e, 0x81, //8
  0x81, 0x7e, 0x7e, 0x7e, 0x80, 0xfe, 0x7e, 0x81, //9
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  //: ' '
};


//ネオピクセルに転送後に表示
void NeoPixe_OUT() {

  int k = 0;
  for (int y = 0; y < MAX_Y; y++) {
    for (int x = 0; x < MAX_X; x++) {

      strip.setPixelColor(k++, strip.Color(
        Pixel[y][x][0], Pixel[y][x][1], Pixel[y][x][2]));

      //Serial.print('.');

    } //for j
    //Serial.println();
  } //for i
  //Serial.println();

  strip.show();

}  //NeoPixe_OUT


//8x8文字の表示
void ch_8x8(char ch, int c1, int c2, int c3){

  ch = (ch - '0') * 8;
  for (int y = 0; y < MAX_Y; y++) {
    int a = font8x8_0_9[ch++];
    for (int x = 0; x < MAX_X; x++) {

      if ( ((a << x) & 0x80) != 0) {
        Pixel[y][x][0] = 0;
        Pixel[y][x][1] = 0;
        Pixel[y][x][2] = 0;
      } else {
        Pixel[y][x][0] = c1;
        Pixel[y][x][1] = c2;
        Pixel[y][x][2] = c3;
      } //if

    } //for j
  } //for i

  NeoPixe_OUT(); //RBG LEDに出力

} //ch_8x8


void puts_8x8(const char *str1){

  //文字の中身がゼロか
  while (*str1) {

    //一文字出力
    ch_8x8(*str1 ++, 5, 5, 5);
    delay(3000);  //3秒待つ

  }//while

}//ns_puts


//初期化
void setup() {

  //ネオピクセルの設定
  strip.begin();
  strip.show();

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

  ////シリアルポートの設定
  //Serial.begin(9600);
  //Serial.println();
  //for (int i = 0; i < 9; i++) {
  //  Serial.print('.');
  //  delay(500); //接続待ち
  //} //for
  //Serial.println();

} //main


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

  //時計の処理 ↓ここから
  time_t t;      //経過秒
  struct tm *tm; //時間の実体とポインター
  //static const char *wd[7] = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };

  t = time(NULL);     //経過秒を取得する
  tm = localtime(&t); //経過秒を時間の構造体に変換する
  //Serial.printf(" %04d/%02d/%02d(%s) %02d:%02d:%02d\n",
  //              tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  //              wd[tm->tm_wday],
  //              tm->tm_hour, tm->tm_min, tm->tm_sec);

  //表示変換する パック二進化十進を文字列にする
  char cn1[16];  //桁
  cn1[0] = '0' + (tm->tm_hour) / 10; //0 時 上位
  cn1[1] = '0' + (tm->tm_hour) % 10; //1 時 下位
  cn1[2] = ':';
  cn1[3] = '0' + (tm->tm_min) / 10; //2 分 上位
  cn1[4] = '0' + (tm->tm_min) % 10; //3 分 下位
  cn1[5] = ':';
  cn1[6] = ':';
  cn1[7] = 0;

  //時計の処理 ↑ここまで

  puts_8x8(cn1); //時刻を表示する
  //puts_8x8("20:52::");

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