Old Cow Yellow Celebration Week: Bitmaps on your Eductional BoosterPack Screen with Energia

This project is part of Old Cow Yellow Celebration Week (details).

The Educational BoosterPack MKII has a nice color display. 128X128 pixels, with full color support (the driver datasheet says it supports 262K colors). And there is an Energia library.

To celebrate Old Cow Yellow, I'm presenting a way to show bitmaps on that display.

We'll start from any square bitmap you want to load. We'll resize it to the LCD resolution and beam it to the BoosterPack. 


Complexity: low

Software required:

Hardware:

  • BoostXL-EDUMKII

  • A LaunchPad that's compatible with that BoosterPack and has enough memory on board*.

Get the image into your Firmware

Let's start from a square image. As long as you can open that image in Microsoft Paint, you're good.
Resize it to 128*128 by clicking the Change Format icon.
Uncheck Keep the Aspect Ratio. Set unit to Pixels, and enter 128 for Horizontal and Vertical.
Save your image as a 24-bits bitmap (extension: bmp).

Use the Random-I Code Image Generator to conver this bitmap into c code.

Push the Open Image button and find the file you just saved.

Find a useful name for the array that will hold the pixels later on.
I used ocy to celebrate Old Cow Yellow.
You can pick anything that's a valid c++ variable name.
You will use that name later on in your loop() function.

Check the 16-bit format, set Width and Height to 128. Push the Create C Code button.
Copy the content of the pop-up window into your clipboard.

Fire up Energia. This will open a new sketch, and that's a good starting point.
Now add the support libraries for the BoosterPack LCD screen.
Menu: Sketch → Import Library → EduBPMKII_Screen.

Position your cursor just below the last #include line, and paste the content of your clipboard there.
Just below the code you've just pasted, add this code:

Screen_HX8353E myScreen;

void drawBitmap(const unsigned char *bmp)
{
    uint16_t c;
    uint16_t ca;
    unsigned char cu;
    unsigned char cl;

    uint16_t x = bmp[0]+1;
    uint16_t y = bmp[1]+1;
    
    for (uint16_t yy=0; yy<y; yy++) {
        for (uint16_t xx=0; xx<x; xx++) {
            cu = bmp[(yy*2)*x+5+(xx*2)];
            cl = bmp[(yy*2)*x+5+(xx*2)+1];
            c = cu;
            c = c << 8;
            c |= 0x00FF;
            ca = cl;
            ca |= 0xFF00;
            c &= ca;
            myScreen.point(xx, yy, c);
        }
    }
}

Replace the setup() and loop() methods with these lines:

// Add setup code
void setup() {
    myScreen.begin();
    myScreen.setOrientation(0);
}

// Add loop code
void loop() {
    myScreen.clear(whiteColour);
    drawBitmap(ocy);
    delay(2000);
}

Save, Run, Enjoy.