#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/*
* Connections
* SSD1306 OLED | Arduino Uno
* ---------------------------
* VCC | +5V (Vcc/power/+ve)
* GND | GND (Ground/-ve/0v)
* SCL | A5 (Serial Clock Line)
* SDA | A4 (Serial Data Line)
*/
const int SCREEN_WIDTH = 128; // OLED display width, in pixels
const int SCREEN_HEIGHT = 64; // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 400; //the value is a number of milliseconds
bool displayLogo1 = true; // Flag to track which logo is currently displayed
#define myLogo_HEIGHT 23
#define myLogo_WIDTH 25
static const unsigned char PROGMEM Water_heater[] =
{
0x07, 0xff, 0xff, 0xff, 0xf8, 0x04, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x20, 0x14, 0x18,
0x14, 0x00, 0x20, 0x36, 0xd0, 0x14, 0x00, 0x50, 0x22, 0x10, 0x14, 0x00, 0x50, 0x22, 0x20, 0x17,
0x00, 0x88, 0x41, 0x20, 0x14, 0x00, 0x88, 0x41, 0x20, 0x1c, 0x00, 0x88, 0x41, 0x20, 0x1f, 0x01,
0x04, 0x41, 0x20, 0x1c, 0x01, 0x04, 0x41, 0x20, 0x1c, 0x02, 0x02, 0x41, 0x20, 0x3e, 0x02, 0x02,
0x41, 0x10, 0x7f, 0x02, 0x02, 0x22, 0x10, 0x7f, 0x01, 0x04, 0x22, 0xd8, 0x3e, 0x00, 0x88, 0x36,
0x08, 0x1c, 0x00, 0x70, 0x14, 0x04, 0x00, 0x00, 0x00, 0x08, 0x07, 0xff, 0xff, 0xff, 0xf8
};
static const unsigned char PROGMEM Solar_heater[] =
{
0x00, 0x92, 0x00, 0x00, 0x54, 0x00, 0x01, 0xbb, 0x00, 0xff, 0xff, 0x00, 0x84, 0x21, 0x00, 0x42,
0x10, 0x80, 0x42, 0x10, 0x80, 0x41, 0x08, 0x40, 0x21, 0x08, 0x40, 0x21, 0x04, 0x20, 0x10, 0x84,
0x20, 0x10, 0x82, 0x10, 0x10, 0x42, 0x10, 0x08, 0x42, 0x08, 0x08, 0x21, 0x08, 0x04, 0x21, 0x08,
0x04, 0x20, 0x84, 0x04, 0x10, 0x84, 0x03, 0xff, 0xfc
};
static const unsigned char PROGMEM myLogo_1[] =
{
0x00, 0x7f, 0xff, 0x80, 0x01, 0xff, 0xff, 0x80, 0x03, 0xff, 0xff, 0x80, 0x0f, 0xf0, 0xff, 0x80,
0x0f, 0xf0, 0x3f, 0x80, 0x1f, 0xf0, 0x1f, 0x80, 0x3f, 0xf0, 0x0f, 0x80, 0x39, 0xf0, 0x0f, 0x80,
0x30, 0xfe, 0x1e, 0x00, 0x70, 0x7f, 0xff, 0x00, 0x70, 0x77, 0xff, 0x00, 0x70, 0x63, 0xff, 0x00,
0x70, 0x77, 0xff, 0x00, 0x70, 0x7f, 0xff, 0x00, 0x31, 0xfe, 0x3e, 0x00, 0xff, 0xf0, 0x1e, 0x00,
0xff, 0xf0, 0x0e, 0x00, 0xff, 0xf0, 0x1c, 0x00, 0xff, 0xf0, 0x30, 0x00, 0xff, 0xf0, 0xf8, 0x00,
0xff, 0xff, 0xe0, 0x00, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xff, 0x00, 0x00
};
static const unsigned char PROGMEM myLogo_2[] =
{
0x00, 0x7f, 0xff, 0x80, 0x01, 0xff, 0xff, 0x80, 0x03, 0xff, 0xff, 0x80, 0x0f, 0x8f, 0xff, 0x80,
0x0e, 0x0f, 0xff, 0x80, 0x1c, 0x0f, 0xff, 0x80, 0x30, 0x0f, 0xff, 0x80, 0x3e, 0x0f, 0xff, 0x80,
0x3f, 0x3f, 0xee, 0x00, 0x7f, 0xff, 0x07, 0x00, 0x7f, 0xf7, 0x07, 0x00, 0x7f, 0xe3, 0x07, 0x00,
0x7f, 0xf7, 0x07, 0x00, 0x7f, 0xff, 0x07, 0x00, 0x3e, 0x3f, 0xc6, 0x00, 0xf8, 0x0f, 0xee, 0x00,
0xf8, 0x0f, 0xfe, 0x00, 0xfc, 0x0f, 0xfc, 0x00, 0xfe, 0x0f, 0xf8, 0x00, 0xff, 0x0f, 0xf8, 0x00,
0xff, 0xff, 0xe0, 0x00, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xff, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
while(true);
}
display.clearDisplay();
display.cp437(true);
startMillis = millis(); //initial start time
}
void loop() {
pumpWorking();
display.drawBitmap(65, 0, Water_heater, 40, 19, 1);
display.drawBitmap(3, 0, Solar_heater, 22, 19, 1);
display.display();
display.setTextSize(2); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 22);
display.print("98");
display.setTextSize(1);
display.print((char)0xF8);
display.print("C");
display.setCursor(42, 22);
display.setTextSize(6);
display.print("37");
display.setTextSize(1);
display.print((char)248);
display.print("C");
display.display(); // Show initial text
}
void pumpWorking (){
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started)
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
if (displayLogo1) {
display.fillRect(4, 40, myLogo_WIDTH, myLogo_HEIGHT, 0);
display.drawBitmap(4, 40, myLogo_1, myLogo_WIDTH, myLogo_HEIGHT, 1);
display.drawFastHLine(21, 4, 43, 1);
display.drawFastHLine(26, 15, 38, 1);
display.display();
}
else {
display.fillRect(4, 40, myLogo_WIDTH, myLogo_HEIGHT, 0);
display.drawBitmap(4, 40, myLogo_2, myLogo_WIDTH, myLogo_HEIGHT, 1);
display.drawFastHLine(21, 4, 43, 0);
display.drawFastHLine(26, 15, 38, 0);
display.display();
}
displayLogo1 = !displayLogo1;
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}