Skip to content

Instantly share code, notes, and snippets.

@bboyho
Created February 16, 2024 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bboyho/ac1491c7adaf202c81b68cd08a24e447 to your computer and use it in GitHub Desktop.
Save bboyho/ac1491c7adaf202c81b68cd08a24e447 to your computer and use it in GitHub Desktop.
/*
Example-03_Bitmap_MOD_Water_Droplet.ino
This demo shows how to write a converted monochrome bitmap on the display.
We scaled and converted open source emoji's down to fit the size of the OLED.
The chosen bitmaps will be used with the Qwiic Soil Moisture Sensor.
Note: Make sure to be careful about adding too many bitmaps. You may run out
out of memory!
This library configures and draws graphics to OLED boards that use the
SSD1306 display hardware. The library only supports I2C.
SparkFun sells these at its website: www.sparkfun.com
Do you like this library? Help support SparkFun. Buy a board!
Micro OLED https://www.sparkfun.com/products/14532
Transparent OLED https://www.sparkfun.com/products/15173
"Narrow" OLED https://www.sparkfun.com/products/17153
Modified by Bobby Chan @ SparkFun Electronics, February 2024
Written by Kirk Benell @ SparkFun Electronics, March 2022
Repository:
https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
Documentation:
https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
SparkFun code, firmware, and software is released under the [MIT License](http://opensource.org/licenses/MIT).
*/
#include <SparkFun_Qwiic_OLED.h> //http://librarymanager/All#SparkFun_Qwiic_Graphic_OLED
// The Library supports three different types of SparkFun boards. The demo uses the following
// defines to determine which device is being used. Uncomment the device being used for this demo.
//QwiicMicroOLED myOLED;
// QwiicTransparentOLED myOLED;
QwiicNarrowOLED myOLED; //<= This code was written specifically for the Narrow OLED,
//you'll need to adjust position of the bitmaps for the other sizes
// Let's draw a truck - use our built in bitmap
//#include "res/qw_bmp_truck.h"
//#include "res/qw_bmp_sparkfun.h"
#include "icon.h" //.h file to hold the converted images.
int width;
int height;
void setup() {
Serial.begin(115200);
Serial.println("Running Bitmap OLED example");
Wire.begin();
Wire.setClock(400000); // Optional increase I2C to 400kHz
// Initalize the OLED device and related graphics system
if (myOLED.begin() == false) {
Serial.println("Device begin failed. Freezing...");
while (true)
;
}
Serial.println("Begin success");
// save device dims for the test routines
width = myOLED.getWidth();
height = myOLED.getHeight();
myOLED.erase(); //clear display
}
void loop() {
//Draw bitmap on OLED
displayBitmap(0, 0, Water_Droplet_Full_SMALL_Width, Water_Droplet_Full_SMALL_Height, Water_Droplet_Full_SMALL);
displayBitmap(21, 0, Flower_SMALL_31x32_Width, Flower_SMALL_31x32_Height, Flower_SMALL_31x32);
displayBitmap(53, 0, Water_Droplet_Empty_SMALL_Width, Water_Droplet_Empty_SMALL_Height, Water_Droplet_Empty_SMALL);
displayBitmap(74, 0, Wilted_Flower_SMALL_31x32_Width, Wilted_Flower_SMALL_31x32_Height, Wilted_Flower_SMALL_31x32);
// There's nothing on the screen yet - Now send the graphics to the device
myOLED.display();
delay(500);
}
//Wrapper to avoid needing to pass width/height data twice
void displayBitmap(uint8_t x, uint8_t y, uint8_t imageWidth, uint8_t imageHeight, uint8_t *imageData) {
myOLED.bitmap(x, y, x + imageWidth, y + imageHeight, imageData, imageWidth, imageHeight);
}
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
// The following emoji's below were modified, scaled,
// and converted into small bitmaps from OpenMoji:
// https://openmoji.org/
uint8_t Water_Droplet_Empty_SMALL [] = {
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x30, 0x0C, 0x06, 0x01, 0x01, 0x06, 0x0C, 0x30, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x0E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x0C, 0x70, 0xC0, 0x00, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFC, 0x01, 0x07, 0x08, 0x10,
0x20, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x20, 0x10, 0x08, 0x07, 0x01
};
int Water_Droplet_Empty_SMALL_Height = 32;
int Water_Droplet_Empty_SMALL_Width = 20;
uint8_t Water_Droplet_Full_SMALL [] = {
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFE, 0xFC, 0xF0, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xC0, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x01, 0x07, 0x0F, 0x1F,
0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x01
};
int Water_Droplet_Full_SMALL_Height = 32;
int Water_Droplet_Full_SMALL_Width = 20;
uint8_t Flower_SMALL_31x32 [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xF0, 0x18, 0x08,
0x08, 0x0C, 0xC2, 0x23, 0xA1, 0x61, 0xC3, 0x02, 0x7C, 0x78, 0xCC, 0xA8, 0x38, 0x00, 0x00, 0x00,
0x00, 0x7C, 0xC4, 0x04, 0x04, 0x0C, 0x08, 0x18, 0x30, 0xE0, 0x80, 0x00, 0x01, 0x7E, 0xC4, 0x83,
0x0E, 0x18, 0x10, 0x33, 0x36, 0xB6, 0x53, 0x50, 0x40, 0xE0, 0x31, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0x06, 0x0C, 0x08, 0x18, 0x10, 0x10, 0x30, 0x3F, 0x00, 0xC0, 0x70, 0x18, 0x05, 0x01,
0x03, 0x03, 0x03, 0x01, 0x04, 0x08, 0x08, 0x08, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int Flower_SMALL_31x32_Height = 32;
int Flower_SMALL_31x32_Width = 31;
uint8_t Wilted_Flower_SMALL_31x32 [] = {
0x00, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x18, 0x04, 0x06, 0x02, 0x03, 0x01, 0x01, 0x01, 0x03, 0x02,
0x02, 0x04, 0x08, 0x30, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x87, 0x1E, 0x70, 0x80, 0x00, 0x00, 0x00, 0xF8, 0x8C, 0x04, 0x04, 0xC0, 0x7C,
0x06, 0x61, 0x21, 0x31, 0x91, 0x11, 0x11, 0x32, 0xAC, 0x48, 0x08, 0x18, 0x30, 0xE0, 0x3C, 0x67,
0x61, 0x30, 0x1F, 0x07, 0x00, 0x03, 0x1E, 0xF0, 0x80, 0x00, 0x00, 0x00, 0x0F, 0x19, 0x20, 0x60,
0x60, 0x66, 0x25, 0x65, 0x4D, 0x8B, 0x84, 0x87, 0x80, 0xC0, 0x72, 0x1F, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
0x2E, 0x26, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int Wilted_Flower_SMALL_31x32_Height = 32;
int Wilted_Flower_SMALL_31x32_Width = 31;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment