#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];
}
static int last_time;
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
for(;;); // Don't proceed, loop forever
}
if (!rtc.begin()) {
Serial.flush();
abort();
}
pinMode(8, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
last_time = millis();
display.clearDisplay();
}
bool btnClicked;
int16_t i;
int current_time;
bool heartState0 = true , heartState1 = true;
int screen, prevScreen;
bool prevTopBtn, prevBotBtn;
bool calledScreen[3];
int letter_load;
void loop() {
current_time = millis();
bool topBtn = digitalRead(8);
bool botBtn = digitalRead(12);
if (topBtn == LOW || botBtn == LOW) {
if (topBtn == LOW && botBtn == LOW) return;
// Serial.println(letter_load);
if (botBtn == LOW && letter_load != 75) {
letter_load += 1;
} else if (topBtn == LOW) {
letter_load -= 1;
if (letter_load == 0) {
prevScreen = screen;
screen -= 1;
calledScreen[prevScreen] = false;
}
}
// if (screen == 1) {
// if (botBtn == LOW && letter_load != 75) {
// letter_load += 1;
// } else if (topBtn == LOW) {
// letter_load -= 1;
// if (letter_load == 0) {
// prevScreen = screen;
// screen -= 1;
// calledScreen[prevScreen] = false;
// }
// }
// }
// else {
// letter_load = 0;
// prevScreen = screen;
// if (botBtn == LOW && prevBotBtn == HIGH) {
// screen += 1;
// } else if (topBtn == LOW && prevTopBtn == HIGH) {
// screen -= 1;
// }
// calledScreen[prevScreen] = false;
// }
}
// if (screen < prevScreen) {
// if (screen == 0 && !calledScreen[0]) {
// letteranimation(0);
// }
// } else if (screen > prevScreen) {
// if (screen == 1 && !calledScreen[1]) {
// letteranimation(1);
// }
// }
// if (screen == 0) drawowo();
// else if (screen == 1) showletter();
// calledScreen[screen] = true;
// prevTopBtn = topBtn;
// prevBotBtn = botBtn;
showletter();
// date();
// drawowo();
// Serial.print(screen);
// Serial.print(" ");
// Serial.print(prevScreen);
// Serial.print(" ");
// Serial.println(calledScreen[screen]);
}
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;
if (current_time - last_time <= 1000 && heartState0) {
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH0 ) / 2,
(display.height() - LOGO_HEIGHT0) / 2,
heartoutline0, LOGO_WIDTH0, LOGO_HEIGHT0, 1);
display.display();
heartState0 = false;
} else if (current_time - last_time >= 1000 && current_time - last_time <= 1500 && heartState1)
{
display.clearDisplay();
display.drawBitmap(
(display.width() - LOGO_WIDTH1 ) / 2,
(display.height() - LOGO_HEIGHT1) / 2,
heartoutline1, LOGO_WIDTH1, LOGO_HEIGHT1, 1);
display.display();
heartState1 = false;
} else if (current_time - last_time > 1500) {
last_time = current_time;
heartState0 = true;
heartState1 = true;
}
}
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();
}
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(bool direction){
if (direction) {
int i;
for (i = 0; i < display.height() + 5 - i / 2; 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();
}
}
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);
} else {
int i = 46;
for (int a = display.height() + 20; a >= 0; 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();
}
i--;
for (; i >= 0; 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();
}
}
delay(1);
}
}
void showletter () {
display.setTextColor(SSD1306_BLACK);
display.setTextSize(0.5);
if (letter_load == 0) {
for (; letter_load <= 25; letter_load++) {
display.clearDisplay();
display.setCursor(15, 80 - letter_load);
display.drawRect(0 , 75 - letter_load, display.width(), 100, 1);
display.fillRect(0 , 75 - letter_load, display.width(), 100, 1);
display.print(F("Lorem ipsum dolor sit amet, consectetur adipiscing elit. \
Maecenas laoreet ipsum eget hendrerit semper. Nunc ultrices quam a ante finibus maximus. \
Sed fermentum iaculis tortor in scelerisque. Donec ante urna, efficitur varius ligula eu,\
egestas posuere nunc. Suspendisse metus neque, pellentesque et ipsum pellentesque, mattis\
elementum mauris. Cras scelerisque mi porta, elementum diam ut, scelerisque ex.\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus mattis libero vel enim\
molestie, at efficitur est sagittis. Morbi elementum dolor hendrerit dapibus semper."));
display.display();
}
}
display.clearDisplay();
display.setCursor(15, 80 - letter_load);
display.drawRect(0 , 75 - letter_load, display.width(), 100, 1);
display.fillRect(0 , 75 - letter_load, display.width(), 100, 1);
display.print(F("Lorem ipsum dolor sit amet, consectetur adipiscing elit. \
Maecenas laoreet ipsum eget hendrerit semper. Nunc ultrices quam a ante finibus maximus. \
Sed fermentum iaculis tortor in scelerisque. Donec ante urna, efficitur varius ligula eu,\
egestas posuere nunc. Suspendisse metus neque, pellentesque et ipsum pellentesque, mattis\
elementum mauris. Cras scelerisque mi porta, elementum diam ut, scelerisque ex.\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus mattis libero vel enim\
molestie, at efficitur est sagittis. Morbi elementum dolor hendrerit dapibus semper."));
display.display();
display.display();
}