#include <WiFi.h>
#include <time.h>
int SEC, MIN, HOUR, DAY, MON, YEAR, WDAY;
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, 4,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
void setup() {
Serial.begin(115200);
//wifi接続
WiFi.begin("Wokwi-GUEST", "", 6);
// WiFi.begin("m_netu", "8888888888"); //SSID,password
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(500);
}
Serial.println("Connected to the WiFi network!");
//タイムサーバーより時間取得
configTime(9 * 3600L, 0, "ntp.nict.jp", "time.google.com", "ntp.jst.mfeed.ad.jp"); //NTPの設定
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(40);
matrix.setTextColor(colors[0]);
}
int x = matrix.width();
int pass = 0;
void loop() {
//TIME(); //現在詳細時刻取得
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(F("Howdy"));
if(--x < -36) {
x = matrix.width();
if(++pass >= 3) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(10);
}
void TIME() { //現在詳細時刻取得
time_t t = time(NULL); //time_t 型の時刻を取得する
struct tm *tm; //struct tm 型に変更
tm = localtime(&t); //struct tm を変数に変換
SEC = tm->tm_sec ; /* seconds after the minute [0-60] */
MIN = tm->tm_min ; /* minutes after the hour [0-59] */
HOUR = tm->tm_hour; /* hours since midnight [0-23] */
DAY = tm->tm_mday; /* day of the month [1-31] */
MON = tm->tm_mon + 1; /* months since January [0-11] */
YEAR = tm->tm_year+1900;/* years since 1900 */
const char* WD[7] = {"日","月","火","水","木","金","土"};
WDAY = tm->tm_wday; /* days since Sunday [0-6] */
Serial.print(YEAR);
Serial.print("年");
Serial.print(MON);
Serial.print("月");
Serial.print(DAY);
Serial.print("日 ");
Serial.print( "(" );
Serial.print( WD[WDAY]);
Serial.print( ")" );
Serial.print(HOUR);
Serial.print(":");
Serial.print(MIN);
Serial.print(":");
Serial.println(SEC);
}