I bought this feather wing along with a huzzah ESP32 hoping to build a simple wifi clock
#include "time.h"
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix = Adafruit_7segment();
char TimeHHMM[6]; // format time from NTP server
matrix.drawColon(true);
it calls getLocalTime(&timeinfo) to get the current time and formats it into a char array TimeHHMM
matrix.print(TimeHHMM); // fails to compile
when i compile I get an error:
no matching function for call to 'print(char [6])'
How can I print hhmm on the 7 segment display ? do I need to convert it another format or specify a format type on the matrix.print line ?
thanks
Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWing
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
- dastels
- Posts: 15658
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
The method you want expects a const char* and you are passing an array of char (i.e. char[]) which is functionally the same as char*. Try explicitedly casting:
Dave
Code: Select all
matrix.print((const char*)TimeHHMM);
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
Hi Dave
I tried this
matrix.print((const char*)TimeHHMM);
and got a different compiler error
no matching function for call to 'print(const char*)'
thanks
I tried this
matrix.print((const char*)TimeHHMM);
and got a different compiler error
no matching function for call to 'print(const char*)'
thanks
- dastels
- Posts: 15658
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
My bad. I misread the signature. Try: .
That might work. I don't see the difference, but C++ can be far more opinionated than C.
Dave
Code: Select all
matrix.print((const char[])TimeHHMM);
That might work. I don't see the difference, but C++ can be far more opinionated than C.
Dave
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
Hi Dave
got a different compiler error:
ISO C++ forbids casting to an array type 'const char []'
could I somehow convert the char array to a integer ? Not sure how it would handle not having a leading zero on the display, right justify, e.g. 730 vs 0730 (I'm not a programmer, lol)
as a side note I have used the ESP32 and OLED feather wing on lots of other projects and pretty sure I could just display the char array on the oled. Maybe the 7 segment library is different.
thanks
got a different compiler error:
ISO C++ forbids casting to an array type 'const char []'
could I somehow convert the char array to a integer ? Not sure how it would handle not having a leading zero on the display, right justify, e.g. 730 vs 0730 (I'm not a programmer, lol)
as a side note I have used the ESP32 and OLED feather wing on lots of other projects and pretty sure I could just display the char array on the oled. Maybe the 7 segment library is different.
thanks
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
this seems to work: although not sure what will happen when the hours are less than 12
int n;
Serial.println(TimeHHMM);
n = atoi(TimeHHMM);
Serial.println(n);
matrix.print(n,DEC);
matrix.writeDisplay();
int n;
Serial.println(TimeHHMM);
n = atoi(TimeHHMM);
Serial.println(n);
matrix.print(n,DEC);
matrix.writeDisplay();
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
forgot the matrix.drawColon(true);
starting to like a clock now :)
guess I'll have wait until the morning to see if it right justifies 3 digits
starting to like a clock now :)
guess I'll have wait until the morning to see if it right justifies 3 digits
- jimk123
- Posts: 708
- Joined: Sun Dec 26, 2010 7:04 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
as a test I hard coded this and it display right justified ' 7:33' so I think it is good to go
Thanks Dave for all your suggestions !
n=733;
matrix.print(n,DEC);
Thanks Dave for all your suggestions !
n=733;
matrix.print(n,DEC);
- dastels
- Posts: 15658
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin
Like I said, C++ is rather opinionated at times. Glad you got it working!
Dave
Dave
Please be positive and constructive with your questions and comments.