/*********
Complete project details at https://randomnerdtutorials.com
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 128x32 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)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Espresso cup bitmap (48x32 pixels) from espresso_cup.png
const unsigned char espressoCupBitmap[] PROGMEM = {
0b00000000, 0b00111100, 0b00000000,
0b00000000, 0b01111110, 0b00000000,
0b00000000, 0b01111110, 0b00000000,
0b00000000, 0b01111110, 0b00000000,
0b00000000, 0b01111110, 0b00000000,
0b00000000, 0b01111110, 0b00000000,
0b00000000, 0b00111100, 0b00000000,
0b00000000, 0b00011000, 0b00000000,
0b00001111, 0b11111111, 0b11110000,
0b00011111, 0b11111111, 0b11111000,
0b00111000, 0b00000000, 0b00011100,
0b01110000, 0b00000000, 0b00001110,
0b01110000, 0b00000000, 0b00001110,
0b01110000, 0b00000000, 0b00001110,
0b01110000, 0b00000000, 0b00001110,
0b01110000, 0b00000000, 0b00001110,
0b01110000, 0b00000000, 0b00001110,
0b01110000, 0b00000000, 0b00001110,
0b00111000, 0b00000000, 0b00011100,
0b00011100, 0b00000000, 0b00111000,
0b00001111, 0b11111111, 0b11110000,
0b00000111, 0b11111111, 0b11100000
};
// Steam bitmap (24x16 pixels) from espresso_steam.png
const unsigned char steamBitmap[] PROGMEM = {
0b00000011, 0b00000000,
0b00000111, 0b10000000,
0b00001111, 0b11000000,
0b00000111, 0b10000000,
0b00000011, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000001, 0b10000000,
0b00000011, 0b11000000,
0b00000001, 0b10000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000
};
int steamOffset = 0; // Controls steam movement
bool movingRight = true;
void setup() {
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
}
void loop() {
display.clearDisplay();
// Draw espresso cup at bottom center
display.drawBitmap(40, 32, espressoCupBitmap, 48, 32, WHITE);
// Draw moving steam centered above the cup
display.drawBitmap(52 + steamOffset, 10, steamBitmap, 24, 16, WHITE);
display.display();
// Move steam left and right
if (movingRight) {
steamOffset += 2;
if (steamOffset > 2) movingRight = false;
} else {
steamOffset -= 2;
if (steamOffset < -2) movingRight = true;
}
delay(500);
}