#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 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void show() { // Often used sequence - Function to simplify code
display.display(); delay(750); display.fillScreen(SSD1306_BLACK);
}
void setup() {
}
void loop() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Old Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Initialise variables
int x0 = 45; // 3 pairs of co-ordinates 0-128
int y0 = 5; //0-64
int x1 = 120;
int y1 = 23;
int x2 = 55;
int y2 = 60;
int w = 45; // width
int h = 45; // height
int r = 20; // radius
int cw = SSD1306_WHITE; // colour white
int cb = SSD1306_BLACK; // colour black
int wait = 750; // 1 second delay
int width = 0;
int i = 0;
int height = 0;
// Basic Draw & Fill
show();
display.fillRoundRect(x0, y0, w, h, 25, cw);
show();
display.fillRoundRect(x0+30, y0+5, w, h, 25, cw);
show();
display.fillRoundRect(x0-30, y0-5, w, h, 25, cw);
show();
display.fillRoundRect(x0+30, y0, w, h, 25, cw);
show();
display.fillRoundRect(x0-30, y0+5, w, h, 25, cw);
show();
display.fillRoundRect(x0, y0, w, h, 25, cw);
show();
display.fillRoundRect(x0+30, y0+5, w, h, 25, cw);
show();
display.fillRoundRect(x0-30, y0-5, w, h, 25, cw);
show();
display.fillRoundRect(x0+30, y0, w, h, 25, cw);
show();
display.fillRoundRect(x0, y0, w, h, 25, cw);
show();
for(i=0; i<h; i+=5) {
display.fillRoundRect(x0, y0+i/2, w, h-i, 25, cw);
display.display(); // Update screen with each newly-drawn line
delay(50);
display.fillScreen(SSD1306_BLACK);
}
for(i=0; i<h; i+=5) {
display.fillRoundRect(x0, 28-i/2, w, height+i, 25, cw);
display.display(); // Update screen with each newly-drawn line
delay(50);
display.fillScreen(SSD1306_BLACK);
}
delay(5000);
for(i=0; i<h; i+=5) {
display.fillRoundRect(x0, y0+i/2, w, h-i, 25, cw);
display.display(); // Update screen with each newly-drawn line
delay(50);
display.fillScreen(SSD1306_BLACK);
}
for(i=0; i<h; i+=5) {
display.fillRoundRect(x0, 28-i/2, w, height+i, 25, cw);
display.display(); // Update screen with each newly-drawn line
delay(50);
display.fillScreen(SSD1306_BLACK);
}
}