WeMos (c7) Web Clock

TM1637 7段4桁LED表示はできたけど、もっと何かWeb関係のものができないかと考えていて、時刻の表示くらいできると思って、やってみた。

WeMos (5) TM1637 7段4桁LED表示

WiFiManagerを利用してWiFiに接続。

結線ができるだけ省けると考えて、GPIOのPinから給電を試してみた。

プログラムはこれ、D4の隣はGNDだから、D4をVCCとして利用する様にプログラミングする。

#include <TM1637Display.h>
#include <time.h>
#include "WiFiManager.h"  
 
const int CLK = D2; //Set the CLK pin connection to the display
const int DIO = D3; //Set the DIO pin connection to the display
const int VCC = D4; //Set the VCC pin connection to the display
 
int numCounter = 0;
int numTime = 0;
String time_value;
 
TM1637Display display(CLK, DIO); //set up the 4-Digit Display.
 
void setup()
{
  Serial.begin(115200);
  Serial.println("Hello!");

  WiFiManager wifiManager;
  if(!wifiManager.autoConnect()) {
    Serial.println("failed to connect and hit timeout");
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(1000);
  } 

  configTime(0 * 3600, 0, "pool.ntp.org", "time.nist.gov");

  pinMode(VCC, OUTPUT);
  digitalWrite(VCC, HIGH);
  display.setBrightness(0x04); //set the diplay to 0..7 brightness
}
 
 
void loop()
{
  for(numCounter = 0; numCounter < 1000; numCounter++) //Iterate numCounter
  {
    time_t now = time(nullptr);
    String time = String(ctime(&now));
    Serial.println("time:" + time);

    time_t utc, local;
    struct tm *tm_now;
    utc = now;
    local = utc + 9 *60 * 60;   // Tokyo time
    tm_now = localtime(&local);
    numTime = tm_now->tm_hour * 100 + tm_now->tm_min;
    Serial.printf("numTime: %d  ¥n", numTime);

    display.showNumberDecEx(numTime, 0x40); //Display the numCounter value;
    delay(500);
    display.showNumberDecEx(numTime, 0); //Display the numCounter value;
    delay(500);
  }
}

実動する画面:

デスクトップPCの肩に乗せた様子。