With some basic knowledge of how the IS31FL3728 works, let’s tackle how to get it displaying LED patterns, numbers and colors.

Background
I2C Basics
Changing the I2C Library
IS31FL3728 Datasheet
Bit Shifting
Bit Masking


IS31FL3728 Register Used for Display LED Patterns and Digits

There are eight registers available that control chunks of LEDs, and those chunks are divided up by digit on the seven segment display, and by color on the bar graph.

Item Register Address
Bar Graph – Red 0x01
Bar Graph – Green 0x02
Bar Graph – Blue 0x03
Digit 0 0x08
Digit 1 0x07
Digit 2 0x06
Digit 3 0x05
Misc. LEDs 0x04

 

 

Each register is 8 bits long, with each bit controlling the on / off state of the LEDs in it’s respective chunk. They are mapped out as follows.

I2C Display v2 Digit Map
I2C Display v2 Digit Map

If you wanted the second digit from the left to display the number “3”, you would write a value to register 0x07 that corresponds to the first, second, third, fourth and seventh bit being set equal to 1 and all the others equal to 0 (remember, when determining bit position, you count from right to left starting with 0): B10011110. Converting that to hex = 0x9E.


All the Hex Numbers

By going through each number 0-9 and then the hex characters A-F, you can quickly build a table of bit patterns that can be written to the digit registers to display a specific number. I’ve gone and figured them all out for you.

CharacterBinaryHexDecimal
0B011111100x7E123
1B000011000x0C012
2B101101100xB6182
3B100111100x9E158
4B110011000xCC204
5B110110100xDA218
6B111110100xFA250
7B000011100x0E014
8B111111100xFE254
9B110111100xDE222
AB111011100xEE238
bB111110000xF8248
CB011100100x72114
dB101111000xBC188
EB111100100xF2242
FB111000100xE2226

Note that the hex characters for b and d are lower case because B looks just like 8 and D looks just like 0.

A Constant Array

Since the values are sequential 0-15 (or just 0-9 if you don’t care about hex values), you can just load them into an array, and provided you prepare the array in an organized fashion, you’ll be able to grab the pattern you want by placing that value at the corresponding index.

By placing that in the declarations area of your sketch, you’ll be able to write a number pattern to the display from anywhere in your sketch.

To make developing patterns a little easier, I’ve put together this excel file that allows you to set the pattern you want to see, then spits out the hex / binary / decimal value that is the equivalent of it. It also has the number patterns listed above, and the color codes listed below: I2C_Display_v2_Pattern_Generator

RGB LEDs

The RGB LEDs in the bar graph at the top are pretty easy to write to, since they are laid out exactly the same as the bits of their register addresses. So if you wanted to turn on the third red LED from the left and the sixth blue LED, you would send the value B00000100 to register 0x01 and value B01000000 to register 0x03.

By combining multiple colors at once at each pixel location, you can create more than just Red, Blue and Green, you can have Cyan, Magenta, Yellow and White as well.

  • RED + BLUE = MAGENTA
  • RED + GREEN = YELLOW
  • BLUE + GREEN = CYAN
  • RED + BLUE + GREEN = WHITE

The trick is figuring out how to easily change between those values.

Displaying RGB LED Patterns Control

The method I came up with is to write a function that takes the pixel position you want to change, and the color you want to change it to. It makes extensive use of bit masking and bit shifting you may want to review those pages if you haven’t used those techniques in a while.

The first difficulty that we run into is that the column registers are write-only. So once you’ve sent a pattern to a register for display, you can’t read that register back to see what’s playing there. That means we have to keep track of it ourselves. So in our declarations area, we’ll create some byte variables to hold the current pattern for us to manipulate, along with some user friendly values for the ISSI I2C Address and the registers we need to play with. There also needs to be a variable created for the shutdown pin so we can control it.

Our setup is pretty straight forward: drive the shutdown pin high, configure I2C appropriately, configure the ISSI for 8×8 matrix mode with no audio in normal operation, and set the brightness to the lowest value. Finally, we need to blank the display, because it maintains the state of its registers through pretty much any event besides power off. Remember you have to send dummy data to the update register in order for the display to actually show the new patterns.

setRGB Function

Our function needs to accept two parameters: the position of the pixel we want to change the color of, and the color we want to change it to. The pixel position is easy, 7-0 corresponds to the way the LEDs are laid out on the physical PCB, so we’ll call that pixelPosition. For the color value, we have 8 different colors we can select from 0 to 7, so that means we can cover all of those with a three bit value, that we’ll call pixelColor. Since RGB is easy to remember, we’ll use that pattern for the number that we send. So if we want to turn a pixel MAGENTA, then Red would be 1, Green would be 0, and Blue would be 1: B101, hex 0x03.

To make it easy for us to reference, we can define the color values up in the declarations area with human readable names.

Within the function, the first thing we need to do is separate out the individual states of each color channel. We can do that by ANDing the pixel color a few times with a mask for each color position, then shifting the value over to the 1s place.

Now that we know what we want to do with each color, we have to update those pattern variables we created in the declarations area. If the value is a 0, then we need to make sure that bit is cleared in the pixelPosition that was sent, if the value is a 1, then we need to set the bit in that pixel position.

Now that we have our colors determined, and moved to the current location in the pixel map, all we have left to do is write those values to the RGB registers, and send the update command.

Main Loop

Within our loop, let’s just test that we got everything right by writing one color to each pixel, from black to white.

When you run the full sketch, you should see each pixel displaying a different color from our gamut of 8 colors.

Full Sketch

If you prefer something a bit more dynamic, change your main loop to the following

For more I2C Display tutorials, Click Here.

Previous Post
I2C Display v2 Tutorial 01: IS31FL3728 Display Driver
Next Post
I2C Display v2 Tutorial 03: Larson Scanner
You might also like
Menu