The result of this is a number. 12129 to be precise.
/b will be 12130.
And any consecutive letter adds +1 until I get /z (which equals 12154).
I can also print(’/A’) (capitol letter), which ranges from 12097-12122 for capitol Z.
ranges /0 to /9 prints out: 12080 to 12089
/10 to /19 prints out ranges 12592 to 12601.
/20 to /29 = 12136 - 12145
What is their name (what are they called), and what is the logic in all this?
Meaning, why is printing out these ‘slash letters’ or ‘slash numbers’, printing out 5 digit numbers?
And on what is this counting based?
I tried Hexadecimal numbers (00-FF) but it appears that the jump from 09 to 0A isn’t consecutive.
I don’t understand in what application this can be used, and how the counting works.
Sure, a-z is +1 number, easy.
Also from 0-9.
But there’s a large jump from 9 to 10. And /9 does not equal /09.
So far it appears that the numbering system goes:
I suppose after Z comes characters.
Could this be a form of ASCII table numbering?
A ‘slash character’ s capped an escape sequence. The slash means that whatever is next will be replaced with it To create a special character or so something special. For instance, you can’t just push ENTER within your string to include a linebreak. Instead, you use the sequence \n to do that. There are some more useful ones like \t for tabs. To print a slash within a string, you need to use two slashes. \\ To include a quotation symbol ("), you use a slash before it. \" This is sometimes just called escaping characters amd a lot of languages use it.
True. Not only Arduino, it does it in normal C++ if you do cout << '/a' << endl;. I don’t know what’s going on, thought such char literal was illegal. I looked for a while on Google, in source codes and C++ specs, but wasn’t able to find it. @Pharap, do you know what’s going on here?
The forward slash is completely irrelevant.
What we’re looking at here is called a “multicharacter literal”.
It has a value of type int (which is why numbers are printed instead of characters, it’s calling print(int), not print(char)) and the exact value is actually implementation defined.
Yes the back slashes I understand. Very few uses for them other than \n.
Although \a \b \e \f \g and \t give special characters on the screen.
It would be perhaps shorter to code using /a if you need the exact value of 12129, but it would be more tedious than writing the full number.
Would it save any memory doing things this way? Like, say, a game that’s maxed out on memory, saving bits by using this method?
When doing console programming on desktop, \r will erase the current line of text to allow you to continually overwrite a line.
Various console programs abuse that to create loading bars and counters that update themselves.
\a is supposed to make a console/terminal make a noise of some description, but it doesn’t always work.
(It still makes a noise on Windows 8, but it’s a tad quiet.)
The Arduboy will ignore that though.
\t is a horizontal tab.
I’m not sure how the Arduboy reacts to those, I think it either gives a regular space or ignores them.
\b is a backspace.
The Arduboy would no doubt ignore the original meaning because it can’t really ‘undraw’ a character after the character has been drawn.
\f is a form feed, which again doesn’t make sense on Arduboy so it just gets printed verbatim.
\e only works because the compiler is GCC.
I’m surprised that \g works. I have no idea what that would do because it’s non-standard.
Bear in mind that the Arduboy’s default font is based on the code page 437 character set:
If you go to the ‘Character Set’ section and cross reference it with an ASCII table then you should see why you get the characters that you do when using character escapes.
It would be shorter, but you shouldn’t do it because it’s cryptic.
Code should be explicit with its intent, it shouldn’t try to hide what it’s trying to do.
Laziness is the enemy of clean code.
No, none whatsover.
The type of the expression is int, so the literal will be interpreted as the same integer value regardless of whether it’s done as an integer literal or a multicharacter literal.
(I’d probably be a cross between DI Humphrey Goodman and DI Richard Poole. Grumpy, intelligent and eccentric in equal measure.)
There is no difference.
The axes are in hexadecimal, you need to compare to the hexadecimal column of the ASCII table.
For example, \a is BEL (bell) in the ascii table, which is 7 in hex, or more fully 0x07.
If you use that on the code page 437 table to take the first row (0_) and the 8th column (_7) then you get a dot, which is exactly what prints when you do arduboy.print('\a');.
And then just keep practising. Eventually it becomes second nature.
If you have trouble converting and you’re on Windows then you can use the Windows calculator, go to View > Programmer and you’ll get access to programmer mode which has a lot of common operations that programmers like to do.
I’m not sure what exactly you’re asking.
char c = static_cast<char>(65);
int i = static_cast<int>('A');
You have to find them in the code page 437 table (though I’m not sure the Arduboy implemented the whole of code page 437 so some might not be present).
Looking at the table the second one (╬) looks like C_, _E, or 0xCE so you’d do arduboy.print(static_cast<char>(0xCE));, or arduboy.print('\xCE');.
I believe code page 437 is implemented completely.
However, the implementation consists of characters that are 8 pixels high by 5 pixels wide. The write() (and thus print()) function adds an extra vertical single pixel space after the end of each character to separate them. This means that the line drawing characters from 0xB3 to 0xDA will not touch horizontally, as they are intended to. The font would have to be 8 x 6, with the spacing pixel included as part of each character itself, in order for this to work properly.
Also, the characters \n (0x0A, ◘) and \r (0x0D, ♪) cannot be displayed using write()/print() because they are handled specially, as mentioned previously.