#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "RTClib.h"
RTC_DS1307 rtc;
#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
};
#define OWO_HEIGHT 10
#define OWO_WIDTH 60
static const unsigned char PROGMEM owo [] = {
// 'owo', 60x10px
0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x3f, 0x00, 0x00, 0x60, 0x40, 0x00, 0x0f, 0xc0,
0x7f, 0x80, 0x00, 0xe0, 0x60, 0x00, 0x1f, 0xe0, 0xff, 0xc0, 0x01, 0xe0, 0x70, 0x00, 0x3f, 0xf0,
0xff, 0xc0, 0x01, 0xc0, 0x38, 0x00, 0x3f, 0xf0, 0xff, 0xc0, 0x01, 0x86, 0x08, 0x00, 0x3f, 0xf0,
0xff, 0xc0, 0x03, 0xc7, 0x3c, 0x00, 0x3f, 0xf0, 0x7f, 0x80, 0x01, 0xff, 0xf0, 0x00, 0x1f, 0xe0,
0x3f, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x0f, 0xc0, 0x1e, 0x00, 0x00, 0x18, 0x20, 0x00, 0x07, 0x80
};
static const char *weekdays[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char *months[] = {
"", "January" , "February" , "March" , "April" , "May" , "June" , "July",
"August" , "September" , "October" , "November" , "December"
};
static const char *daySuffixLookup[] = {
"th" , "st" , "nd" , "rd" , "th",
"th" , "th" , "th" , "th" , "th"
};
static const char *daySuffix(int n)
{
if(n % 100 >= 11 && n % 100 <= 13)
return "th";
return daySuffixLookup[n % 10];
}
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
}
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
pinMode(8, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
display.clearDisplay();
}
bool btnClicked;
int16_t i;
void loop() {
// if (!btnClicked) testdrawbitmap();
// bool topBtn = digitalRead(8);
// bool botBtn = digitalRead(12);
// if (topBtn == LOW || botBtn == LOW) {
// btnClicked = true;
// if (topBtn == LOW && botBtn == LOW) return;
// if (botBtn == LOW) {
// Serial.println("open");
// letteranimation();
// }
// }
// date();
// drawowo();
letteranimation();
}
void testscrolltext() {
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() {
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);
}
void drawowo() {
display.clearDisplay();
DateTime now = rtc.now();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
char hour[3];
itoa(now.hour(), hour, 10);
String minute = String(now.minute());
if (minute.length() == 1) minute = '0' + minute;
drawCentreString(String(hour) + ":" + minute, 5);
display.drawBitmap(
(display.width() - OWO_WIDTH ) / 2,
(display.height() - OWO_HEIGHT) / 2,
owo, OWO_WIDTH, OWO_HEIGHT, 1);
display.setTextSize(1.5);
drawCentreString(String(weekdays[now.dayOfTheWeek()]) + ", " + String(months[now.month()])
+ " " + String(now.day()) + String(daySuffix(now.day())), 45);
display.display();
delay(1000);
}
void letter(){
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();
}
void date() {
DateTime now = rtc.now();
display.clearDisplay();
display.setTextSize(1.5);
display.setTextColor(SSD1306_WHITE);
display.setCursor(5,5);
display.println("Current time: ");
display.print(now.day(), DEC);
display.print('/');
display.print(now.month(), DEC);
display.print('/');
display.println(now.year(), DEC);
display.print(now.hour(), DEC);
display.print(':');
display.print(now.minute(), DEC);
display.print(':');
display.print(now.second(), DEC);
display.println();
display.display();
}
void drawCentreString(const String &buf, int y)
{
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(buf, 0, 0, &x1, &y1, &w, &h); // calc width of new string
display.setCursor((display.width() - w) / 2, y);
display.print(buf);
}
void letteranimation(){
// for (int i = 0; i <= display.height(); i++) {
// if (i < display.height()/2+5-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.fillTriangle(10,8+i/2,display.width()-10,8+i/2,display.width()/2,display.height()/2+i/2, 1);
// display.display();
// } else if (i < display.height() + 5 - 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.fillTriangle(10,8+i/2,display.width()-10,8+i/2,display.width()/2,display.height()/2+i/2, 1);
// display.display();
// } else {
// for (int a = 0; a <= display.height() + 20; a++) {
// display.clearDisplay();
// display.drawRect(5,5+i/2 + a,display.width()-9,display.height()-10, 1);
// display.drawTriangle(5,5+i/2 + a,display.width()-5,5+i/2 + a,display.width()/2,display.height()/2+10-i + a, 1);
// display.drawTriangle(5,5+i/2 + a,display.width()-5,5+i/2 + a,display.width()/2,display.height()/2+i/2 + a, 1);
// display.fillTriangle(10,8+i/2 + a,display.width()-10,8+i/2 + a,display.width()/2,display.height()/2+i/2 + a, 1);
// display.display();
// }
// }
// delay(1);
// }
for (int i = display.height(); i >= 0; i--) {
display.clearDisplay();
display.drawRect(10,10,display.width()-19,i/2-2, 1);
display.fillRect(10,10,display.width()-19,i/2-2, 1);
display.display();
}
delay(1);
}