/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
#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
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#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 NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
0b00000001, 0b11000000,
0b00000001, 0b11000000,
0b00000011, 0b11100000,
0b11110011, 0b11100000,
0b11111110, 0b11111000,
0b01111110, 0b11111111,
0b00110011, 0b10011111,
0b00011111, 0b11111100,
0b00001101, 0b01110000,
0b00011011, 0b10100000,
0b00111111, 0b11100000,
0b00111111, 0b11110000,
0b01111100, 0b11110000,
0b01110000, 0b01110000,
0b00000000, 0b00110000 };
static const uint8_t ICON_WIFIROUND [] PROGMEM = { 0b00000000, 0b00000000, 0b00000011, 0b11000000, 0b00011111, 0b11111000, 0b00111100, 0b00111100, 0b01110000, 0b00001110, 0b01100111, 0b11100110, 0b00001111, 0b11110000, 0b00011000, 0b00011000, 0b00000011, 0b11000000, 0b00000111, 0b11100000, 0b00001100, 0b00110000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000011, 0b11000000, 0b00000001, 0b10000000, 0b00000000, 0b0000000 };
static const uint8_t ICON_CLEAR [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b0000000 };
static const uint8_t ICON_WIFI_100 [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00000000, 0b00001110, 0b00000000, 0b00001110, 0b00000000, 0b00001110, 0b00000000, 0b11101110, 0b00000000, 0b11101110, 0b00000000, 0b11101110, 0b00001110, 0b11101110, 0b00001110, 0b11101110, 0b00001110, 0b11101110, 0b11101110, 0b11101110, 0b11101110, 0b11101110, 0b11101110, 0b11101110, 0b11101110, 0b11101110, 0b00000000, 0b0000000 };
static const uint8_t ICON_WIFI_75 [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11100000, 0b00000000, 0b11100000, 0b00000000, 0b11100000, 0b00001110, 0b11100000, 0b00001110, 0b11100000, 0b00001110, 0b11100000, 0b11101110, 0b11100000, 0b11101110, 0b11100000, 0b11101110, 0b11100000, 0b11101110, 0b11101110, 0b00000000, 0b0000000 };
static const uint8_t ICON_WIFI_50 [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001110, 0b00000000, 0b00001110, 0b00000000, 0b00001110, 0b00000000, 0b11101110, 0b00000000, 0b11101110, 0b00000000, 0b11101110, 0b00000000, 0b11101110, 0b11101110, 0b00000000, 0b0000000 };
static const uint8_t ICON_WIFI_25 [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11100000, 0b00000000, 0b11100000, 0b00000000, 0b11100000, 0b00000000, 0b11101110, 0b11101110, 0b00000000, 0b0000000 };
static const uint8_t ICON_WIFI_0 [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11101110, 0b11101110, 0b00000000, 0b0000000 };
static const uint8_t ICON_COMM_CFG [] PROGMEM = { 0b00000000, 0b00000000, 0b00000111, 0b11000000, 0b00001100, 0b01100000, 0b00001100, 0b01100000, 0b00000000, 0b01100000, 0b00000000, 0b01100000, 0b00000000, 0b11000000, 0b00000001, 0b10000000, 0b00000001, 0b10000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b11101110, 0b11101110, 0b00000000, 0b0000000 };
static const uint8_t ICON_COMM_NO [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00011000, 0b00111000, 0b00111000, 0b00011100, 0b01110000, 0b00001110, 0b11100000, 0b00000111, 0b11000000, 0b00000011, 0b10000000, 0b00000111, 0b11000000, 0b00001110, 0b11100000, 0b00011100, 0b01110000, 0b00111000, 0b00111000, 0b00110000, 0b00011000, 0b00000000, 0b00000000, 0b11101110, 0b11101110, 0b00000000, 0b0000000 };
static const uint8_t ICON_READING [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, 0b11100000, 0b00011111, 0b11111000, 0b00111000, 0b00011100, 0b01100001, 0b10000110, 0b01000011, 0b11000010, 0b01000011, 0b11000010, 0b01100001, 0b10000110, 0b00111000, 0b00011100, 0b00011111, 0b11111000, 0b00000111, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b0000000 };
static const unsigned char ICON_SETUP [] PROGMEM = { 0b00000010, 0b01000000, 0b00010111, 0b11101000, 0b00011111, 0b11111000, 0b01111111, 0b11111110, 0b00111100, 0b00111100, 0b01111000, 0b00011110, 0b11110000, 0b00001111, 0b01110000, 0b00001110, 0b01110000, 0b00001110, 0b11110000, 0b00001111, 0b01111000, 0b00011110, 0b00111100, 0b00111100, 0b01111111, 0b11111110, 0b00011111, 0b11111000, 0b00010111, 0b11101000, 0b00000010, 0b0100000 };
static const uint8_t ICON_LOOP [] PROGMEM = { 0b00000000, 0b00000000, 0b00000111, 0b11100000, 0b01001100, 0b00111000, 0b01111000, 0b00001100, 0b01110000, 0b00000100, 0b01111000, 0b00000110, 0b00000000, 0b00000010, 0b00000000, 0b00000010, 0b01000000, 0b00000000, 0b01000000, 0b00000000, 0b01100000, 0b00011110, 0b00100000, 0b00001110, 0b00110000, 0b00011110, 0b00011100, 0b00110010, 0b00000111, 0b11100000, 0b00000000, 0b0000000 };
static const uint8_t ICON_SLEEP [] PROGMEM = { 0b00000000, 0b00000000, 0b01111100, 0b00000000, 0b00000100, 0b00000000, 0b00001000, 0b11111000, 0b00010000, 0b00010000, 0b00100000, 0b00100000, 0b01111100, 0b01000000, 0b00000000, 0b11111000, 0b00000111, 0b00000000, 0b00000001, 0b00000000, 0b00000010, 0b00001110, 0b00000111, 0b00000010, 0b00000000, 0b00000100, 0b00000000, 0b00001110, 0b00000000, 0b00000000, 0b00000000, 0b0000000 };
static const uint8_t ICON_SENDING [] PROGMEM = { 0b00000000, 0b00000000, 0b00111001, 0b11110000, 0b01000110, 0b00001000, 0b10000000, 0b00000110, 0b10001100, 0b00000010, 0b01010010, 0b00001100, 0b00100001, 0b11110000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000011, 0b11000000, 0b00000111, 0b11100000, 0b00000001, 0b10000000, 0b00000001, 0b10000000, 0b01111111, 0b10000000, 0b01111111, 0b00000000, 0b00000000, 0b0000000 };
static const uint8_t ICON_MQTT_OK [] PROGMEM = { 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b10100100, 0b01000100, 0b11101010, 0b01000100, 0b10101010, 0b11101110, 0b10101010, 0b01000100, 0b10101010, 0b01000100, 0b10101010, 0b01000100, 0b10101010, 0b01000100, 0b10101010, 0b01000100, 0b10101010, 0b01000100, 0b10100110, 0b00100010, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b0000000 };
static const uint8_t ICON_MQTT_KO [] PROGMEM = { 0b00000000, 0b00000000, 0b01000000, 0b00000010, 0b00100000, 0b00000100, 0b10010100, 0b01001000, 0b11101010, 0b01010100, 0b10100100, 0b10101110, 0b10101010, 0b01000100, 0b10101001, 0b10000100, 0b10101001, 0b10000100, 0b10101010, 0b01000100, 0b10100100, 0b00100100, 0b10101010, 0b01010100, 0b10010110, 0b00101010, 0b00100001, 0b00000100, 0b01000000, 0b00000010, 0b00000000, 0b0000000 };
static const unsigned char ICON_MQTT2_OK [] PROGMEM = { 0b00000000, 0b00000000, 0b00101000, 0b00111000, 0b01010100, 0b01001000, 0b01010100, 0b01001000, 0b01010110, 0b00111000, 0b00000000, 0b00001000, 0b00000000, 0b00011100, 0b00000000, 0b00001000, 0b00000000, 0b00000000, 0b00010000, 0b00010000, 0b00111100, 0b00111100, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010010, 0b00010010, 0b00001100, 0b00001100, 0b00000000, 0b0000000 };
static const unsigned char ICON_MQTT2_KO [] PROGMEM = { 0b00000000, 0b00000000, 0b01001000, 0b00111010, 0b00100100, 0b01000100, 0b01010100, 0b01001000, 0b01001010, 0b00010000, 0b00000100, 0b00101000, 0b00000010, 0b01011100, 0b00000001, 0b10001000, 0b00000001, 0b10000000, 0b00010010, 0b01010000, 0b00110100, 0b00101100, 0b00001000, 0b00010000, 0b00010000, 0b00001000, 0b00100010, 0b00010100, 0b01001100, 0b00001010, 0b00000000, 0b0000000 };
void printBMP(int16_t x, int16_t y, const uint8_t icon[])
//void printBMP(int x, int y, char icon[])
{
clearBMP(x, y);
display.drawBitmap(x, y, icon, LOGO_WIDTH, LOGO_HEIGHT, 1);
display.display();
}
void clearBMP(int16_t x, int16_t y)
{
display.fillRect(x, y, LOGO_WIDTH, LOGO_HEIGHT, 0);
}
void SetStatusRunning(int SetupOrLoop)
{
clearBMP(7*16, 0);
if(SetupOrLoop == 1)
printBMP(7*16, 0, ICON_LOOP);
else
printBMP(7*16, 0, ICON_SETUP);
}
#define STATUS_COMM_CFG 0
#define STATUS_COMM_NO -1
#define STATUS_COMM_OK 1
#define STATUS_COMM_WIFI_0 2
#define STATUS_COMM_WIFI_25 3
#define STATUS_COMM_WIFI_50 4
#define STATUS_COMM_WIFI_75 5
#define STATUS_COMM_WIFI_100 6
void SetStatusComm(int Status)
{
uint16_t x = 0, y = 0;
clearBMP(x, y);
switch(Status)
{
case STATUS_COMM_CFG:
printBMP(x, y, ICON_COMM_CFG);
break;
case STATUS_COMM_NO:
printBMP(x, y, ICON_COMM_NO);
break;
case STATUS_COMM_OK:
// printBMP(x, y, ICON_COMM_OK);
break;
case STATUS_COMM_WIFI_0:
printBMP(x, y, ICON_WIFI_0);
break;
case STATUS_COMM_WIFI_25:
printBMP(x, y, ICON_WIFI_25);
break;
case STATUS_COMM_WIFI_50:
printBMP(x, y, ICON_WIFI_50);
break;
case STATUS_COMM_WIFI_75:
printBMP(x, y, ICON_WIFI_75);
break;
case STATUS_COMM_WIFI_100:
printBMP(x, y, ICON_WIFI_100);
break;
}
}
#define STATUS_SENSORS_READ 0
#define STATUS_READING_SENSORS 1
void SetStatusReadingSensors(int Status)
{
uint8_t x = 32, y = 0;
clearBMP(x, y);
switch(Status)
{
case STATUS_READING_SENSORS:
printBMP(x, y, ICON_READING);
break;
}
}
#define STATUS_DATA_SENT 0
#define STATUS_SENDING_DATA 1
void SetStatusSendData(int Status)
{
uint8_t x = 48, y = 0;
clearBMP(x, y);
switch(Status)
{
case STATUS_SENDING_DATA:
printBMP(x, y, ICON_SENDING);
break;
}
}
#define STATUS_SLEEPING 0
#define STATUS_GOING_TO_SLEEP 1
void SetStatusSleep(int Status)
{
uint8_t x = 64, y = 0;
clearBMP(x, y);
switch(Status)
{
case STATUS_GOING_TO_SLEEP:
printBMP(x, y, ICON_SLEEP);
break;
}
}
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
}
// 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
display.clearDisplay();
// testdrawbitmap(); // Draw a small bitmap image
// display.drawBitmap(x, y, icon, LOGO_WIDTH, LOGO_HEIGHT);
// Invert and restore display, pausing in-between
// display.invertDisplay(true);
// delay(1000);
// display.invertDisplay(false);
// delay(1000);
SetStatusRunning(0);
SetStatusComm(STATUS_COMM_CFG);
delay(2000);
SetStatusComm(STATUS_COMM_NO);
delay(2000);
printBMP(16, 0, ICON_MQTT2_KO);
SetStatusComm(STATUS_COMM_WIFI_0);
delay(2000);
SetStatusComm(STATUS_COMM_WIFI_25);
delay(2000);
SetStatusComm(STATUS_COMM_WIFI_50);
delay(2000);
SetStatusComm(STATUS_COMM_WIFI_75);
delay(2000);
SetStatusComm(STATUS_COMM_WIFI_100);
printBMP(16, 0, ICON_MQTT2_OK);
delay(2000);
SetStatusRunning(1);
}
void loop() {
SetStatusReadingSensors(1);
delay(2000);
SetStatusReadingSensors(0);
SetStatusSendData(1);
delay(2000);
SetStatusSendData(0);
SetStatusSleep(1);
delay(2000);
SetStatusSleep(0);
}
// void testdrawbitmap(void) {
// display.clearDisplay();
// display.drawBitmap(
// (display.width() - LOGO_WIDTH ) / 2,
// (display.height() - LOGO_HEIGHT) / 2,
// logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
// display.display();
// delay(1000);
// }