2.Basic drawBitmap example

Drawing a bitmap on the Pokitto screen

In this example we draw a small Pokitto icon (by @trelemar) on the left upper corner (coordinates 0,0) of the Pokitto screen.

The screen mode used is the default mode 2, which is 110 pixels wide, 88 pixels high and has 16 colors

Link to project on Pokitto mbed Community Team Page:


##Project settings (My_settings.h)

#define PROJ_HIRES 0            //1 = high resolution (220x176) , 0 = 110x88 fast mode
#define PROJ_ENABLE_SOUND 1     // 0 = all sound functions disabled

##Program file (bitmap.cpp)

#include "Pokitto.h" // include Pokitto library
#include "pokitto_icon.h" // include the Pokitto icon graphics file
Pokitto::Core mygame; //create Pokitto application instance
int main () {
    mygame.begin(); // start the application
    mygame.display.load565Palette(pokitto_icon_pal); //load the palette for the image
    mygame.display.bgcolor=1; // set color 1 (purple) as background
    /* the "while" loop runs as long as the program is running */
    while (mygame.isRunning()) {
        /* mygame.update() is processed whenever it is time to update the screen */
        if (mygame.update()) {
            mygame.display.drawBitmap(0,0,pokitto_icon); // draw the pokitto_icon graphic
    return 0; // this is "good programming manners". Program informs it ended without errors

Nice icon you have there! :smiley:


When mbed is back up and running, can we get the code pasted into a code box here on the forum, just in case mbed goes down again?

I’d do it myself, but this doesn’t appear to be a wiki.

I dont see anything in the code that turns the background pink/purple, where is this color coming from ?

That’s because the palette loaded to draw the image contains that color, and happens to be the index of the background color.

Understood, but where in the code does it tell Pokitto that it should make the background that color ?

You are right. That bit of code is not there. I will add it


I see it was added :

mygame.display.bgcolor=1; // set color 1 (purple) as background

But i am i bit confused, i used the mbed site to edit and compile a .bin based of this.(used your link) The color purple was already present at that point. Yet the code for this was not.

Was the background color inside the pokitto lib somehow ? And now you added it to the api ? @jonne

I have not checked. For some reason bgcolor=1 automatically in the mbed online PokittoLib. But I have no time to track it down, I will at some point

Ok, you dont have to track it down for me :smile:
I am just trying to figure out how it all works and this showing up without code for it was really strange.
But i do understand now that in the pokitto lib there is stuff that can do this.

Do i understand correctly that color 1 is the first color in the pallete that is specified ?

I’m 90% sure that the palette is zero-indexed.
The rule of thumb when programming is ‘assume zero-indexing unless otherwise specified’.

Well, i think this falls in the other 10 % :smile: This is the first color in the pallete.

I will try setting it to 2 tonight, that should change the color.

Unless I’m reading it wrong or missing something, the source code seems to imply otherwise:

Well, euhh i barely understand most of that…

But i will try to set it to 0 and see what happens.

Setting it to 0 gives a purple background, 1 also gives a purple background.
Setting 2 gives a nice bleu color(4195). So 0 and 1 seems to pick the first color in the pallete, then 2 picks the next and so on.

No. 0 picks the first color and 1 the second and so on.

Something else is different, either the display.invisiblecolor or display.persistence

1 Like

So there is still something wrong in the background that is causing purple to be displayed when using 0 and 1?

No there is nothing wrong. Something is just initialized in different order. I know the palette functions work 100% because Pixonia uses them to the max.

Now you are forcing me to debug this :grinning:

I need to write a tutorial on colors

1 Like

Hahaha, sorry about that :blush:

I did a quick test by modifying the hello world example.

As intended:

  • not pressing anything choses colour 0, which is magenta
  • pressing A chooses colour 1, which is a sort of black
  • pressing B chooses colour 2, which is Pokitto green.
#include "Pokitto.h"

Pokitto::Core game;

const uint16_t palette[] =

int main (void)

	while (game.isRunning())
		if (game.update())
			else if(game.bBtn())

	return 1;

And crucially changing My_settings.h to define PROJ_HIRES as 0:
(The code doesn’t work in hires mode. I don’t know why but I’m sure there’s a rational explanation.)

    @file     My_settings.h
    @author   XX

    @section HOW TO USE My_settings

   My_settings can be used to set project settings inside the mbed online IDE


#define PROJ_HIRES 0            //1 = high resolution (220x176) , 0 = low resolution fast mode (110x88)
#define PROJ_ENABLE_SOUND 1     // 0 = all sound functions disabled


If this doesn’t work for you, something else is up.
Note that I’m using Embitz, so there could be some differences if you’re using the online compiler.