Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWing

by jimk123 on Thu Dec 02, 2021 7:28 pm

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

jimk123
 
Posts: 345
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by dastels on Thu Dec 02, 2021 7:58 pm

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:

Code: Select all | TOGGLE FULL SIZE
matrix.print((const char*)TimeHHMM);

Dave

dastels
 
Posts: 8396
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by jimk123 on Thu Dec 02, 2021 8:07 pm

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

jimk123
 
Posts: 345
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by dastels on Thu Dec 02, 2021 8:48 pm

My bad. I misread the signature. Try:
Code: Select all | TOGGLE FULL SIZE
matrix.print((const char[])TimeHHMM);
.

That might work. I don't see the difference, but C++ can be far more opinionated than C.

Dave

dastels
 
Posts: 8396
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by jimk123 on Thu Dec 02, 2021 8:57 pm

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

jimk123
 
Posts: 345
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by jimk123 on Thu Dec 02, 2021 9:08 pm

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();

jimk123
 
Posts: 345
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by jimk123 on Thu Dec 02, 2021 9:13 pm

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

jimk123
 
Posts: 345
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by jimk123 on Thu Dec 02, 2021 9:16 pm

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);

jimk123
 
Posts: 345
Joined: Sun Dec 26, 2010 7:04 pm

Re: Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWin

by dastels on Thu Dec 02, 2021 10:50 pm

Like I said, C++ is rather opinionated at times. Glad you got it working!

Dave

dastels
 
Posts: 8396
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.