#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define LOGO_HEIGHT0 24
#define LOGO_WIDTH0 24
static const unsigned char PROGMEM heartoutline0[] =
{ 0x00, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x1F, 0xC3, 0xF8, 0x30, 0x66, 0x0C, 0x60, 0x3C, 0x06, 0x40,
0x18, 0x02, 0xC0, 0x00, 0x03, 0xC0, 0x00, 0x03, 0x80, 0x00, 0x01, 0xC0, 0x00, 0x03, 0xC0, 0x00,
0x03, 0x40, 0x00, 0x02, 0x60, 0x00, 0x06, 0x30, 0x00, 0x0C, 0x18, 0x00, 0x18, 0x0C, 0x00, 0x30,
0x06, 0x00, 0x60, 0x03, 0x00, 0xC0, 0x01, 0x81, 0x80, 0x00, 0xC3, 0x00, 0x00, 0x66, 0x00, 0x00,
0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
#define LOGO_HEIGHT1 26
#define LOGO_WIDTH1 26
static const unsigned char PROGMEM heartoutline1 [] = {
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x0f, 0xe1, 0xfc, 0x00, 0x38, 0x33, 0x87, 0x00,
0x30, 0x1e, 0x01, 0x80, 0x60, 0x0c, 0x01, 0x80, 0x40, 0x00, 0x00, 0x80, 0xc0, 0x00, 0x00, 0xc0,
0xc0, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0xc0,
0x40, 0x00, 0x00, 0x80, 0x60, 0x00, 0x01, 0x80, 0x30, 0x00, 0x03, 0x00, 0x18, 0x00, 0x06, 0x00,
0x0c, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x18, 0x00, 0x03, 0x00, 0x30, 0x00, 0x01, 0x80, 0x60, 0x00,
0x00, 0xc0, 0xc0, 0x00, 0x00, 0x61, 0x80, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
//testscrolltext(); // Draw scrolling text
//letteranimation();
testdrawbitmap(); // Draw a small bitmap image
//letter();
}
void loop() {
}
void letteranimation(void){
int16_t i;
for(i=0; i<=display.height()/2+5-i/2; i+=2) {
display.clearDisplay();
display.drawRect(5,5+i/2,display.width()-9,display.height()-10, 1);
display.fillTriangle(5,5+i/2,display.width()-5,5+i/2,display.width()/2,display.height()/2+10-i, 1);
display.drawTriangle(5,5+i/2,display.width()-5,5+i/2,display.width()/2,display.height()/2+i/2, 1);
display.display();
delay(1);
}
for(i=display.height()/2+5-i/2; i<=display.height(); i+=2) {
display.clearDisplay();
display.drawRect(5,5+i/2,display.width()-9,display.height()-10, 1);
display.drawTriangle(5,5+i/2,display.width()-5,5+i/2,display.width()/2,display.height()/2+10-i, 1);
display.drawTriangle(5,5+i/2,display.width()-5,5+i/2,display.width()/2,display.height()/2+i/2, 1);
display.display();
delay(1);
}
}
void testscrolltext(void) {
display.clearDisplay();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(10, 0);
display.println(F("hi"));
display.display(); // Show initial text
delay(100);
}
void testdrawbitmap(void) {
int16_t i;
display.clearDisplay(); // Clear display buffer
//for(i=0; i<4; i+=1) {
// display.drawLine(0, 0, i, display.height()-1, SSD1306_WHITE);
// display.display(); // Update screen with each newly-drawn line
// delay(1);
//}
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH0 ) / 2,
(display.height() - LOGO_HEIGHT0) / 2,
heartoutline0, LOGO_WIDTH0, LOGO_HEIGHT0, 1);
display.display();
delay(1000);
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH1 ) / 2,
(display.height() - LOGO_HEIGHT1) / 2,
heartoutline1, LOGO_WIDTH1, LOGO_HEIGHT1, 1);
display.display();
delay(500);
testdrawbitmap();
}
void letter(void){
display.clearDisplay();
display.setTextSize(1.5);
display.setTextColor(SSD1306_WHITE);
display.setCursor(5,5);
display.println(F("Dear \n Phuong Thao \n My beloved one"));
display.display();
}