FORGE
disparity between the number of elements and the
number of bits we’re representing is because we’re
using hexadecimal to describe the same data as
‘char’ rather than raw binary, and each element is
equivalent to a byte/8 bits. Multiply the 32 elements
by those 8 bits and you get 256, so we’re not
losing or compressing any data, only displaying
them more efficiently. Efficiency is also why we
use the ‘PROGMEM’ keyword when declaring the
array. Arduino has different types of memory, and
PROGMEM represents the flash storage rather than
the SRAM used to store our program variables. As we
saw in the previous tutorial that dealt with lists and
pointers, SRAM quickly fills with any normal project,
and each Arduino has much more flash storage than
SRAM. Using PROGMEM instead of SRAM is perfect
for larger arrays, such as the one we’re using to
hold a bitmap. The only limits are that PROGMEM
variables must be global or defined as ‘static’.
Thanks to the Adafruit graphics library we’re already
using to drive our screen, rendering the bitmap array
to the screen is easy, taking just a single line, which
we’re putting within its own function that takes an x
and y location for where we want the image drawn:
void displayShip(int x, int y) {
display.drawBitmap(x, y, shipBMP, 16, 16, 1);
}
Thanks to the Adafruit graphics library, we’re
already using to drive our screen, rendering the
bitmap array to the screen is easy
”
”
Left
Playing your game
is the best way
of improving it,
especially when it
comes to fine-tuning
the control system
Above
An online bitmap
converter, such as
hsmag.cc/vfYQyz,
can let you invert an
image and preview
the text output so you
can make sure it will
work with the screen