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