Custom Screen Characters for Maker Screen

Maker Screen has lots of characters built in (it has its own microchip, too!). That saves you from having to create the code for the letter "A" or "2" every time you want to use it. Maker Screen contains A-Z, a-z, 0-9, and a number of other characters.

There are also 8 blank spots on the screen's microchip where you can define your own characters. A character is defined as one 8X5 block of pixels on the screen, so you don't have very many spaces to play with.

To create a custom character, you will "draw" it with 0s and 1s using an array. It's difficult to 'see' the character at first, but try uploading the program below to see some custom characters in action, then read on about what it takes to make one.

//Include the MakerScreenXVI library to use the methods designed for it. #include "MakerScreenXVI.h" //Create an object in the LCD library named lcd. You can name it almost anything MakerScreenXVI lcd; byte smiley[8] = { 0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b10001, 0b01110, 0b00000 }; //name the 'slot' where the smiley is stored. Up to 8 custom characters byte smileyID = 1; //naming the custom characters makes code easier to read //value of smileyID should match the value in createChar() below. void setup() { //Always type name.begin() in setup to set the screen's default settings lcd.begin(); // create a new character in the empty 'slot 1' of the lcd screen lcd.createChar(1, smiley); } void loop() { //set the cursor in the upper left of the screen lcd.setCursor(0,0); //change these to see where the smiley is placed. lcd.write(smileyID); //.write() the name of the character's 'slot' } // (c) 2017 Let's Start Coding. License:

The custom characters use a special format. In code terms, you are creating an array (a list) of bytes that is 8 bytes long. That's where you get the notation byte name [8] = { . The beginning of each line is 0b, which tells the compiler "The next thing you see is going to be binary numbers". 

Each character can only be five pixels wide- look very closely at your screen and you'll see the five pixels. You use a combination of five 0s and 1s to 'draw' the character. Each "1" is going to be a darkened pixel. Each "0" is not darkened. 

After you have defined all 8 rows of pixels for your character (again, you can see the pixels on your screen if you look closely), you close the array with the }; .

Before you start drawing your custom characters in the program, you need to:

1) Tell the code which numbered empty slot should hold your new custom character.

2) Give that slot a name so that when you draw your custom character, you are using the name of the character, not just a number (it will get confusing).

The trick is that step two happens above step one in the code itself.

First, step two. When you are creating variables for your custom characters, they should be related to the name of the array, but they cannot be the same as the array- that variable name is already used. Using nameID as the variable name helps keep everything straight. The number you assign to nameID can range from 0 to 7, since you have eight blank spots on the screen for custom characters. It doesn't matter which number you give it, just remember that number.

Now for step one. In the void setup() section of the code, you use the lcd.CreateChar() method to tell the code which blank slot you want to fill and then which array you want in that slot. Do this for each of the custom characters you created. The 'slot number' must match the value you gave to nameID. The array name must match exactly the name you gave when you 'drew' you character with code.

Once all of that is complete, you can draw your custom character on the screen with the lcd.write() method. To draw it, you will use lcd.write(nameID). Remember, nameID corresponds to the 'slot' your custom character is in. You could type lcd.write(slotNumber), but then you have to mentally keep track of which slot number corresponds to which character.

It takes some work to set up a custom character (thank goodness the screen already has the alphabet programmed in!) but once you have it set up, you can use the characters in fun ways like you will in Jump Man.