#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 50
#define LOGO_WIDTH 50
static const unsigned char PROGMEM test_bmp[] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0xff, 0x1f, 0xff, 0xc0, 0xff, 0xfc, 0x01, 0xf8, 0x03,
0xff, 0xc0, 0xff, 0xf8, 0x00, 0x60, 0x01, 0xff, 0xc0, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xc0,
0xff, 0xf0, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0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 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0};
static const unsigned char PROGMEM test1_bmp[] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0xff, 0x1f, 0xff, 0xc0, 0xff, 0xfc, 0x01, 0xf8, 0x03,
0xff, 0xc0, 0xff, 0xf8, 0x00, 0x60, 0x01, 0xff, 0xc0, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xc0,
0xff, 0xf0, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0xff, 0xe0, 0x30, 0x00, 0xe0, 0x7f, 0xc0, 0xff, 0xe0,
0xf8, 0x01, 0xf0, 0x7f, 0xc0, 0xff, 0xc0, 0xfc, 0x03, 0xf0, 0x3f, 0xc0, 0xff, 0xc1, 0xfe, 0x07,
0xf8, 0x3f, 0xc0, 0xff, 0xc1, 0xfe, 0x07, 0xf8, 0x3f, 0xc0, 0xff, 0xc1, 0xff, 0x0f, 0xf8, 0x3f,
0xc0, 0xff, 0xc1, 0xff, 0xff, 0xf8, 0x3f, 0xc0, 0xff, 0xc1, 0xff, 0xff, 0xf8, 0x3f, 0xc0, 0xff,
0xe0, 0xff, 0xff, 0xf0, 0x3f, 0xc0, 0xff, 0xe0, 0xff, 0xff, 0xf0, 0x7f, 0xc0, 0xff, 0xe0, 0x7f,
0xff, 0xe0, 0x7f, 0xc0, 0xff, 0xf0, 0x7f, 0xff, 0xe0, 0xff, 0xc0, 0xff, 0xf0, 0x3f, 0xff, 0xc0,
0xff, 0xc0, 0xff, 0xf8, 0x1f, 0xff, 0x81, 0xff, 0xc0, 0xff, 0xf8, 0x1f, 0xff, 0x81, 0xff, 0xc0,
0xff, 0xfc, 0x0f, 0xff, 0x03, 0xff, 0xc0, 0xff, 0xfe, 0x07, 0xfe, 0x07, 0xff, 0xc0, 0xff, 0xfe,
0x01, 0xfc, 0x07, 0xff, 0xc0, 0xff, 0xff, 0x00, 0xf0, 0x0f, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x20,
0x1f, 0xff, 0xc0, 0xff, 0xff, 0xc0, 0x00, 0x3f, 0xff, 0xc0, 0xff, 0xff, 0xf0, 0x00, 0x7f, 0xff,
0xc0, 0xff, 0xff, 0xf8, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xfe, 0x03, 0xff, 0xff, 0xc0, 0xff,
0xff, 0xff, 0x0f, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0};
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
//display.display();
//delay(2000); // Pause for 2 seconds
}
// Clear the buffer
void loop() {
display.clearDisplay();
DateTime now = rtc.now();
//display.drawLine(0, 0, 127,63, SSD1306_WHITE);
//display.drawLine(127, 0, 0,63, SSD1306_WHITE);
display.setTextSize(1);
display.setTextColor(1);
display.setCursor(0,30);
display.print("Current time: ");
display.print(now.year(), DEC);
display.print('/');
display.print(now.month(), DEC);
display.print('/');
display.print(now.day(), DEC);
display.print(" (");
display.print(daysOfTheWeek[now.dayOfTheWeek()]);
display.print(") ");
display.print(now.hour(), DEC);
display.print(':');
display.print(now.minute(), DEC);
display.print(':');
display.print(now.second(), DEC);
display.println();
display.print("Heat Rate");
display.print(random(80,90));
display.drawBitmap(80,10,test_bmp,LOGO_WIDTH,LOGO_HEIGHT,SSD1306_WHITE);
display.display();
delay(100);
display.drawBitmap(80,10,test1_bmp,LOGO_WIDTH,LOGO_HEIGHT,SSD1306_WHITE);
display.display();
delay(100);
}