Skip to content

Instantly share code, notes, and snippets.

@feerrenrut
Created September 9, 2015 12:25
Show Gist options
  • Save feerrenrut/79d0f9b2f9704914c70d to your computer and use it in GitHub Desktop.
Save feerrenrut/79d0f9b2f9704914c70d to your computer and use it in GitHub Desktop.
Draw Bitmap Piccolino
/* Draws a bitmap at the specified location
** x is horizontal distance from the left of the screen to the left of the image
** y is virtical distance from the top of the screen to the top of the image
** bitmap is a pointer to the start of the image data
** w is the width in pixels of the image
** h is the height in pixels of the image
*
** remarks: the image data contains pixels represented with a single bit. 1 representing white pixels.
** 8 pixels are expected per byte and the data is interpreted horizontally (each byte represents
** 8 horizontal pixels) thus the width of the image must be a multiple of 8.
*/
void drawBitmap(int16_t x, int16_t y, const unsigned char *bitmap, int16_t w, int16_t h) {
int16_t i, j, byteWidth = (w + 7) / 8;
for(j=0; j<h; j++) {
for(i=0; i<w; i++ ) {
if(0 == (pgm_read_byte(bitmap + j * byteWidth + i / 8) & (128 >> (i & 7)))) {
display.drawPixel(x+i, y+j, WHITE);
}
}
}
display.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment