#include <SPI.h> // Not needed with I2C
#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(2000); display.fillScreen(SSD1306_BLACK);
}
void setup() {
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 = 5; // 3 pairs of co-ordinates
int y0 = 5;
int x1 = 120;
int y1 = 23;
int x2 = 55;
int y2 = 60;
int w = 105; // width
int h = 55; // height
int r = 30; // radius
int cw = SSD1306_WHITE; // colour white
int cb = SSD1306_BLACK; // colour black
int wait = 500; // 2 second delay
// Title screen
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(cw);
display.setCursor(28,25);
display.println("Screen");
display.setCursor(28,33);
display.println("Primitives");
display.fillScreen(cw); // Fill screen WHITE
display.display(); delay(wait);
display.fillScreen(cb); // Fill screen BLACK
display.display();
// Basic Draw & Fill
show();
display.drawCircle(63, 31, r, cw);
show();
display.fillCircle(63, 31, r, cw);
show();
display.drawCircle(31, 31, r, cw);
show();
}
void loop() {
// put your main code here, to run repeatedly:
}