動作確認
ESP-WROOM-02
Timeライブラリを使って時計情報を表示しようとしている。
hour, minute, secondは0パディングで表示したいのだが、それをSerial.println()で行う場合、自作関数で実装している例が見つかる。
ビルトイン関数はないものか。
printf()に関して以下のリンクを見つけた。
http://playground.arduino.cc/Main/Printf
試しにFマクロを使う以下の方法を試してみた。
It can also transparently support using the F() macro to put the printf() formatting strings into flash.
Serial.printf(F("Hello World\n"));
Serial.printf(F("Value is:%3d\n"), value);
esp8266_160619_timeLib.ino
#include <TimeLib.h>
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.printf( F("%02d:%02d:%02d"), hour(), minute(), second() );
Serial.printf( F(",%02d/%02d/%04d"), day(), month(), year() );
Serial.println();
delay(3000);
}
以下のエラーが出た
exit status 1
no matching function for call to 'HardwareSerial::printf(const __FlashStringHelper*, int, int, int)'
0パディングは自作関数にするのが楽かもしれない。