Skip to content

Commit 5cea57d

Browse files
author
JoelEB
committed
Added drawBitmap function to library
Added drawBitmap function to library as well as an example in the examples folder. Also added getScreenBuffer function from the MicroView library to this library.
1 parent bce22f9 commit 5cea57d

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

Firmware/Arduino/libraries/SFE_MicroOLED/SFE_MicroOLED.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,4 +905,21 @@ void MicroOLED::flipHorizontal(boolean flip) {
905905
else {
906906
command(SEGREMAP | 0x1);
907907
}
908+
}
909+
910+
/*
911+
Return a pointer to the start of the RAM screen buffer for direct access.
912+
*/
913+
uint8_t *MicroOLED::getScreenBuffer(void) {
914+
return screenmemory;
915+
}
916+
917+
/*
918+
Draw Bitmap image on screen. The array for the bitmap can be stored in the Arduino file, so user don't have to mess with the library files.
919+
To use, create uint8_t array that is 64x48 pixels (384 bytes). Then call .drawBitmap and pass it the array.
920+
*/
921+
void MicroOLED::drawBitmap(uint8_t * bitArray)
922+
{
923+
for (int i=0; i<(LCDWIDTH * LCDHEIGHT / 8); i++)
924+
screenmemory[i] = bitArray[i];
908925
}

Firmware/Arduino/libraries/SFE_MicroOLED/SFE_MicroOLED.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ class MicroOLED : public Print{
164164
void circleFill(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t mode);
165165
void drawChar(uint8_t x, uint8_t y, uint8_t c);
166166
void drawChar(uint8_t x, uint8_t y, uint8_t c, uint8_t color, uint8_t mode);
167-
void drawBitmap(void);
167+
void drawBitmap(uint8_t * bitArray);
168168
uint8_t getLCDWidth(void);
169169
uint8_t getLCDHeight(void);
170170
void setColor(uint8_t color);
171171
void setDrawMode(uint8_t mode);
172+
uint8_t *getScreenBuffer(void);
172173

173174
// Font functions
174175
uint8_t getFontWidth(void);
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/******************************************************************************
2+
MicroOLED_Hello.ino
3+
SFE_MicroOLED Hello World Demo
4+
Joel Bartlett @ SparkFun Electronics
5+
Original Creation Date: January 20, 2015
6+
7+
This sketch shows you how to draw a 64x48 pixel Bitmap image on the MicroOLED.
8+
9+
Hardware Connections:
10+
We'll be using the SPI interface on the MicroOLED, though it
11+
also supports I2C (and a really messy parallel). If you want
12+
to swap in I2C, read through the comments to find out how.
13+
14+
MicroOLED ------------- Arduino
15+
GND ------------------- GND
16+
VDD ------------------- 3.3V (VCC)
17+
D1/MOSI ----------------- D11 (don't change)
18+
D0/SCK ------------------ D13 (don't change)
19+
D2
20+
D/C ------------------- D8 (can be any digital pin)
21+
RST ------------------- D9 (can be any digital pin)
22+
CS ------------------- D10 (can be any digital pin)
23+
24+
Development environment specifics:
25+
IDE: Arduino 1.0.5
26+
Hardware Platform: MicroOLED Breakout
27+
Arduino Pro 3.3V/8MHz
28+
29+
Note: The display on the MicroOLED is a 1.8V-3.3V device only.
30+
Don't try to connect a 5V Arduino directly to it! Use level
31+
shifters in between the data signals if you have to resort to
32+
a 5V board.
33+
34+
This code is beerware; if you see me (or any other SparkFun
35+
employee) at the local, and you've found our code helpful,
36+
please buy us a round!
37+
38+
Distributed as-is; no warranty is given.
39+
*******************************************************************************/
40+
#include <Wire.h> // Include Wire if you're using I2C
41+
#include <SPI.h> // Include SPI if you're using SPI
42+
#include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library
43+
44+
//////////////////////////
45+
// MicroOLED Definition //
46+
//////////////////////////
47+
#define PIN_RESET 9 // Connect RST to pin 9 (req. for SPI and I2C)
48+
#define PIN_DC 8 // Connect DC to pin 8 (required for SPI)
49+
#define PIN_CS 10 // Connect CS to pin 10 (required for SPI)
50+
#define DC_JUMPER 0
51+
// Also connect pin 13 to SCK and pin 11 to MOSI
52+
53+
//////////////////////////////////
54+
// MicroOLED Object Declaration //
55+
//////////////////////////////////
56+
// Declare a MicroOLED object. The parameters include:
57+
// 1 - Reset pin: Any digital pin
58+
// 2 - D/C pin: Any digital pin (SPI mode only)
59+
// 3 - CS pin: Any digital pin (SPI mode only, 10 recommended)
60+
MicroOLED oled(PIN_RESET, PIN_DC, PIN_CS);
61+
//MicroOLED oled(PIN_RESET, DC_JUMPER); // Example I2C declaration
62+
63+
// I2C is great, but will result in a much slower update rate. The
64+
// slower framerate may be a worthwhile tradeoff, if you need more
65+
// pins, though.
66+
67+
//------------------------------------------------------------------------------
68+
// File generated by LCD Assistant
69+
// http://en.radzio.dxp.pl/bitmap_converter/
70+
//------------------------------------------------------------------------------
71+
//This is the array that holds the Bitmap image. The easiest way to convert a bmp
72+
//to an array is to use the LCD Assistant linked above.
73+
uint8_t bender [] = {
74+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xBF, 0xDF, 0x5F, 0x5F, 0x5F, 0x5F,
75+
0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F,
76+
0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F,
77+
0x5F, 0xDF, 0xBF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
78+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xF9, 0xFE, 0x07, 0x01, 0x00, 0x00, 0xF8, 0xFE, 0xFF,
79+
0xFF, 0xFF, 0x1F, 0x1F, 0x1F, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x00,
80+
0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0x1F, 0x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6F, 0xEE, 0x00, 0xDE, 0xDE, 0xDE, 0xDD, 0x00, 0xDD, 0xDD, 0xDD, 0xDD, 0x00, 0xDD, 0xDD,
92+
0xDD, 0xC5, 0xC1, 0x00, 0xC9, 0xC5, 0xC1, 0x01, 0xC8, 0xC4, 0x42, 0x80, 0xC0, 0xE8, 0xE4, 0xE2,
93+
0xE0, 0xE0, 0xEF, 0xEF, 0xE6, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
94+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
95+
0xFF, 0xFF, 0xFE, 0xFE, 0xFD, 0xFD, 0xFD, 0xFB, 0xF8, 0xFB, 0xFB, 0xFB, 0xFB, 0xF8, 0xFB, 0xFB,
96+
0xFB, 0xFB, 0xFB, 0xF8, 0xFB, 0xFD, 0xFD, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
97+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
98+
};
99+
100+
101+
void setup()
102+
{
103+
// These three lines of code are all you need to initialize the
104+
// OLED and print the splash screen.
105+
106+
// Before you can start using the OLED, call begin() to init
107+
// all of the pins and configure the OLED.
108+
oled.begin();
109+
// clear(ALL) will clear out the OLED's graphic memory.
110+
// clear(PAGE) will clear the Arduino's display buffer.
111+
oled.clear(ALL); // Clear the display's memory (gets rid of artifacts)
112+
// To actually draw anything on the display, you must call the
113+
// display() function.
114+
oled.display();
115+
delay(1000);//pause for the splash screen
116+
//Note: You can change the spalsh screen by editing the array founf in the library source code
117+
118+
oled.clear(PAGE);//clear the screen before we draw our image
119+
oled.drawBitmap(bender);//call the drawBitmap function and pass it the array from above
120+
oled.display();//display the imgae
121+
}
122+
123+
void loop()
124+
{
125+
}

0 commit comments

Comments
 (0)