How can you do a bar space in the program. I want to print in a IP address and the tittle must be in the center. Something like this:
Tittle
print 1
print 2
etc...
How can you do a bar space in the program. I want to print in a IP address and the tittle must be in the center. Something like this:
Tittle
print 1
print 2
etc...
Serial.print(" ");
or
Serial.print(' ');
If you need more spaces
for (int i=0; i<iSpacedNeeded; i++) Serial.print(' ');
Is that what you wanted to know?
The space bar is ASCII --- > 0x20. If you want to know the ASCII value of a "space bar"
AnddyPR:
How can you do a bar space in the program. I want to print in a IP address and the tittle must be in the center. Something like this:Tittle
In the center of what?
You need to know the width of your display area before you can center the title. If you're displaying on a physical display on the Arduino, of course you can assume the size. But if you're printing to the serial monitor, your sketch has no way of knowing how wide the monitor window is. In that case you might decide just to pretend it's 80 columns wide, or whatever.
If you are printing a fixed string, you can just include the required number of spaces in the string e.g.
serial.println(" Title")
This does mean your display strings are longer and consume more RAM. If that's an issue you can center the strings dynamically as below.
To center the strings dynamically you measure the length of the string, subtract it from the width of your display and halve the result. That is the number of spaces you need to print in front of your string to center it. You can either just put a for loop and print each space separately, or use printf type formatting to control the output field width.
Thanks a lot man,but I haven't try it yet because of a problem. When I connect the Arduino to the laptop the device manager doesn't detect it. What could be that?
USB drivers not installed?
Yes the Arduino was working perfectly,but out of nothing its stop working
a generic printHeader function can be usefull , something like this ( not tested)
void printHeader(char * left, char* middle, char* right, int width)
{
uint8_t m = strlen(middle);
uint8_t spaces1 = (width - m)/2 - strlen(left);
uint8_t spaces2 = (width - m+1)/2 - strlen(right); // the +1 corrects if middle is a string with odd number of chars
Serial.print(left);
for (; spaces1 >0; spaces1--) Serial.print(' ');
Serial.print(middle);
for (; spaces2 >0; spaces2--) Serial.print(' ');
Serial.print(right);
}