Is that C, or Basic?
Neither.
Javascript
but why?
Maybe this helps to visualise the process of scrolling.
Imagine the IP address in a 15 character fixed frame. Further imagine a display frame moving from left to right to capture characters out of that IP address frame.
The coloured boxes represent characters and the empty boxes are blanks.
The code that matches this is as follows:
void setup() {
Serial.begin( 115200 ) ;
Serial.println( "IP" ) ;
char ip[16] = "192.168.107.128" ; // pad right blank if ip < 15 chars
for ( int i = 0 ; i < 24 ; i++ ) {
for ( int j = 0 ; j < 8 ; j++ ) {
int offset = i + j ;
Serial.print ( ( offset < 8 || offset > 23 ) ? ' ' : ip[ offset - 8 ] ) ;
}
Serial.println() ;
}
}
void loop() {}
Wow. Yes, that works.
I think I see how you cheated with the display size and what to show. That is the j loop.
While the i loop is for scrolling.
Now all I guess I need to do is work on the Serial.print line and work out how to use that to send stuff to the display.
Yes, I will need extra code for the decimal point detection.
In the code I posted this was done retrospectively. I guess it isn't too much to do it looking in front of where it is.
Thanks @6v6gt . I'll sit here and try to get it all happening.
This line has me stumped.
Serial.print ( ( offset < 8 || offset > 23 ) ? ' ' : ip[ offset - 8 ] ) ;
Is that saying print a space if/while offset < 8 or if offset > 23?
Just trying to convert that to code which I send to display stuff on the LED/display is not easy for me to translate from that to what I need to do.
And how to make a loop from that to include in the bigger loop/s...... head exploding.
I think you understood it.
It is a short hand if / else statement but returning a value. This is the long hand version.
if ( offset < 8 || offset > 23 ) Serial.print( ' ' ) ;
else Serial.print( ip[ offset - 8 ] ) ;
In principle, the logic of the scrolling is similar to that of @red_car with the exception that the array holding the IP address does not need to be padded to handle the trailing spaces in the display.
Ok. All good.
But something else (now) has me confused.
Where in your new code is the previous value moved from its old position to the new position?
Or is that included in the Serial.print line?
This is how I stuck your code in the program - no offence.
I declared/set things before it gets here.
void another()
{
for ( int i = 0 ; i < 24 ; i++ )
{
for ( int j = 0 ; j < 8 ; j++ )
{
int offset = i + j ;
//Serial.println(offset);
//
//Serial.print ( ( offset < 8 || offset > 23 ) ? ' ' : ip[ offset - 8 ] ) ;
Serial.print ( ( offset < 8 || offset > 23 ) ? ' ' : message2[ offset - 8 ] ) ;
//
MAX7219senddata(1 , message2[ offset - 8 ]);
//
}
Serial.println() ;
delay(800);
}
}
Yeah, it will only print at position 1 but that is because I can't get my head around how to expand that tricky line you used to work with the display.
I honestly have no idea how to expand that out.
Serial.print ( ( offset < 8 || offset > 23 ) ? ' ' : message2[ offset - 8 ] ) ;
assuming message2[] is a char array:
char temp ;
if ( offset < 8 || offset > 23 ) temp = ' ' ;
else temp = message2[ offset - 8 ] ) ;
MAX7219senddata(1 , temp );
assuming
message2[]is a char array:
Correct. I just changed its name from ip[] to message2[] to keep the names similar.
char temp ;
if ( offset < 8 || offset > 23 ) temp = ' ' ;
else temp = message2[ offset - 8 ] ) ;
MAX7219senddata(1 , temp );
Um, temp needs to be 15. Sending a space the display shows a 0 and that is very messy.
So I guess all I need to do is change it to:
if ( offset < 8 || offset > 23 ) temp = 15 ;
Yeah?
All these tricks you are showing me: I can't translate them to the code needed to control the display.
Yes they work as they are, but that is more/only decorative and only show proof of concept to me.
I'll stick that in and see what happens.
Oh.....
else temp = message2[ offset - 8 ] ) ;
That ) is wrong - yes?
I just based it on your cosntruct here :
//
MAX7219senddata(1 , message2[ offset - 8 ]);
//
and assumed you intended to pass a single character:
Anyway, which library are you using for the functions such as MAX7219senddata() ?
You can try this :
void another()
{
for ( int i = 0 ; i < 24 ; i++ )
{
char disp[9] = { 0 } ;
for ( int j = 0 ; j < 8 ; j++ )
{
int offset = i + j ;
//Serial.println(offset);
//
//Serial.print ( ( offset < 8 || offset > 23 ) ? ' ' : ip[ offset - 8 ] ) ;
Serial.print ( ( offset < 8 || offset > 23 ) ? ' ' : message2[ offset - 8 ] ) ;
disp[ j ] = ( offset < 8 || offset > 23 ) ? ' ' : message2[ offset - 8 ] ;
}
//
MAX7219senddata(1 , disp ); // assuming this method takes a character array.
//
Serial.println() ;
delay(800);
}
}
That's half the problem... they are not using a library. They are interfacing with the display directly at a very low level... a bit at a time. This data sheet is useful but possibly beyond the OP.
https://www.jaycar.com.au/medias/sys_master/images/images/9594887012382/XC3714-dataSheetMain.pdf
Sending 0x0F (15) to the display effectively clears that digit.
Setting the high bit (0x80) (+ 128) for any digit sets the decimal point.
@red_car
Correct. I have that PDF file.
@6v6gt
As red_car said: There is on library.
I have added lines to print things and I am starting to see a pattern develop which may be useful. But I fear/feel I am really making my life harder than it needs to be.
Your code - again: no offence - is sending a lot of < 0 values to the display which I am not sure are helping.
I'll look at your newer code now and report back.
Um.... You've thrown me a curve ball with char disp[9] = { 0 } ;.
Where is the message (or message2) used with the IP number?
Sorry... Here's a screen shot.
And again: thanks.
I understand this could nearly be called bit bashing as I am sending the digits to the display one at a time and with a fair bit of overhead.... Positioning etc.
I can't find an easy way out and although it is making my life miserable (wink) I am wanting to become better.
I also get that I can't be good at everything.
This is just the tip alas, as I need to rewrite a lot of the main code so I can control what is displayed.
(Going a bit off topic)
Ultimately I will have 2 of these displays.
One on top of the other.
The whole thing will be divided into 4 x 4 digits.
I send messages to the arduino with the starting position of the message and it is displayed in that quadrant.
The IP display is for diagnostic stuff when needed - and it is longer than 8 digits.
I thought scrolling it would be better than just whacking it on the display.
But sorry, that is distant future ambitions for this.
I'm hoping I have enough tools already to handle those things.
Just this tricky thing with the display is a bit beyond what I am used to.
The reason you are getting this is because the display routine is expecting a byte, not a char. If you change the definition of disp[] this should work. The display needs to be sent bytes as it uses all 8 bits of the data.
... and it can only handle 1 byte at a time... you cannot pass it an array.
Sorry, I understand what you are meaning, but not what you are saying.
(Or is that the other way around? Dunno)
I don't know how to do that.
You cannot do this:
MAX7219senddata(1 , disp ); // assuming this method takes a character array. i.e. a string.
This is trying to send multiple characters to the routine.
The routine can only handle 1 at a time... you must pass each digit... like in my previous example. Each digit must be a byte type, not a char type.
char disp[9] = { 0 } ; .
I know that I can (working) send it something like:
23 and if the pointer is set to ... say.... position 5 (room to show all digits) I will see 23 on the display.
I can send it 1234567 and I will see those numbers on the display.
I don't need to send them individually.
But that is a whole other story. Though I could cut up the IP address into ever increasing numbers and send them that way.
But I think that would be just as complicated as this way with it's own set of problems.
I don't even know what this means?
How do you do this? The routines you have shown only handle 1 digit at a time?
I could send you the working flow that shows the temperature derived from a sensor connected to the arduino.
It gets it and displays it. I am not sure on the actual way it does it, but I am 99% sure I don't need to bit bash the numbers to the display.
I just give the temperature to a variable and call the routine to display it.
But it is an abortion of code.........
And I won't bother sending all the includes etc.
Just so you can see how it gets to display a multi-digit number.

