1

I'm trying to display the current time on the OLED board attached to my Particle Photon.

void loop() {
  time_t time = Time.now();
  Time.format(time, '%Y-%m-%dT%H:%M:%S%z');
  displayString(time);
}

int displayString(String text) {
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println(text);
  display.display();

  return 1;
}

I have confirmed that displayString works. As it is an embedded device, you don't have access to the regular time library, however the Photon has it's own.

https://docs.particle.io/reference/firmware/core/#time

I'm getting the error Invalid conversion from int to const char*.


Edit: For anyone else who comes across this, I discovered that while undocumented, if you do not provide a time it will use the current time, so you can just do:

String time = Time.format("%d/%m/%y %H:%M:%S");

The uppercase String type is intentional, see String class.

Benedict Lewis
  • 2,733
  • 7
  • 37
  • 78

1 Answers1

2

This is likely because in this line:

Time.format(time, '%Y-%m-%dT%H:%M:%S%z');

you specify the format string as a multi-character char, not a string. Try:

Time.format(time, "%Y-%m-%dT%H:%M:%S%z"); // Note the double quotation marks

Just for some more information about multi-character chars read here: What do single quotes do in C++ when used on multiple characters?

Also pay attention to your compiler warnings, you should have received this:

warning: multi-character character constant

Which would have alerted you to this problem.

Community
  • 1
  • 1
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
  • I didn't catch that at first glance, nice eyes. – zackery.fix Dec 29 '15 at 19:02
  • For anyone else who comes across this, I discovered that while undocumented, if you do not provide a time it will use the current time, so you can just do: `String time = Time.format("%d/%m/%y %H:%M:%S");`. – Benedict Lewis Dec 30 '15 at 16:05