#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 screen(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
screen.begin(SSD1306_SWITCHCAPVCC, 0x3C);
screen.clearDisplay();
// Draw a single pixel in white
screen.drawPixel(64, 32, WHITE); // (x, y, colour)
screen.display();
delay(1000);
// Draw line
screen.clearDisplay();
screen.drawLine(0, 64, 127, 0, WHITE); //(x1, y1, x2, y2, colour)
// you define two points of where the start and end of the line are, and the Arduino fills in the inbetween (well, the AdaFruit GFX library does anyway)
screen.display();
delay(1000);
// Draw rectangle
screen.clearDisplay(); // can delete these lines if you want to keep the shapes on the screen
screen.drawRect(20, 20, 50, 40, WHITE); // (x1, y1, width, height, colour)
screen.display();
delay(1000);
// Fill rectangle
screen.fillRect(20, 20, 50, 20, WHITE); // same as drawing a rectangle
screen.display();
delay(1000);
// Draw round rectangle
screen.clearDisplay();
screen.drawRoundRect(20, 20, 50, 20, 5, WHITE); // (x1, y1, height, width, radius, colour)
screen.display();
delay(1000);
// Fill round rectangle
screen.clearDisplay();
screen.fillRoundRect(20, 20, 50, 20, 5, WHITE); // same as drawing a rounded rectangle
screen.display();
delay(1000);
// Draw circle
screen.clearDisplay();
screen.drawCircle(64, 32, 20, WHITE); // (x, y, radius, colour)
screen.display();
delay(1000);
// Fill circle
screen.fillCircle(64, 32, 20, WHITE); // same as drawing a circle
screen.display();
delay(1000);
// Draw triangle
screen.clearDisplay();
screen.drawTriangle(64, 20, 30, 50, 100, 50, WHITE); // (x1, y1, x2, y2, x3, y3, colour)
// defining each corner of the triangle
screen.display();
delay(1000);
// Fill triangle
screen.fillTriangle(64, 20, 30, 50, 100, 50, WHITE);
screen.display();
delay(1000);
}
void loop() {
// Invert and restore display, pausing in-between
screen.invertDisplay(true);
delay(500);
screen.invertDisplay(false);
delay(500);
}