LoginSignup
1
2

More than 5 years have passed since last update.

Arduino > printf()関数 > 奥が深い > F()マクロ: コンパイルエラー

Last updated at Posted at 2016-06-19
動作確認
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パディングは自作関数にするのが楽かもしれない。

1
2
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
2