Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWing

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Adafruit 4-Digit 7-Segment LED Matrix Display FeatherWing

Post by jimk123 »

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

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

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

Post by dastels »

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

matrix.print((const char*)TimeHHMM);
Dave

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

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

Post by jimk123 »

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

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

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

Post by dastels »

My bad. I misread the signature. Try:

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

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

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

Post by jimk123 »

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

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

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

Post by jimk123 »

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

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

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

Post by jimk123 »

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

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

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

Post by jimk123 »

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

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

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

Post by dastels »

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

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”