It took some effort to restrain myself from adding too much extra fluff to the “Hello World” example. The purpose of that tutorial was to show the minimum to get something on-screen, and nothing more.
Now we’ve got something on screen, though, we have the basis for something we can experiment on. We can start adding some teletext control codes – how Teletext does colours and other effects.
Download this Arduino sketch and open it in the Arduino IDE.
This example evolves from “Hello World”. I’ve removed most of the comments, moved the initialisation code into its own function, added a “print string at location” function, and implemented a scrolltext … just for the fun of it.
When running, it looks like this:
Teletext Control Codes
To change colours, make text double-height or use graphics, we must embed “control codes” into the data. We send these as a byte, just like characters – they’re values which don’t have a “visible” representation. This means these commands have nothing to represent them on-screen … but they affect what gets drawn afterwards.
For example – here are the command codes to change the colour of text. You send one of these bytes, and then subsequent text will appear in that colour:
Each line of a teletext screen always begins in “white text” mode by default, so we don’t need to explicitly set it if we’re showing white text. But for other colours, we just write the byte to register 11, just as if we were printing text.
If you look at my uses of the WriteText function, you’ll see that I’m embedding one of these control codes at the beginning of each line I want to print. For example:
WriteText(5, 8, "\003This text is YELLOW.");
The first byte in that string is 3 – which will instruct the SAA5246 to draw subsequent text in yellow.
The scrolltext takes this idea further by frequently changing the text colour throughout the line of text:
In this example, the string starts with a control byte of 1 (meaning “red text”) then the characters ‘R’, ‘e’ and ‘d’, then a control byte of 2 (meaning “green text”) then the characters ‘G’, ‘r’ … you get the idea.
Now would be a good time to start experimenting with the control codes. Particularly: double-height, flashing, and graphics modes. Have a look at page 28 of the SAA5246 datasheet (a link to the same document is also on the project page). The leftmost two columns of that table describe the purposes of the command codes between 0 and 31.
I’ll do a separate tutorial on graphics mode.