Drawing with Arduino and the OLED.

The little OLED that we are using with the Arduino comes with a library that makes drawing relatively simple.

Well Рit makes simple drawing very simple Рand the simplest abstraction we can work out for our drawings the better.

Abstraction is the process of breaking our instructions into the best possible steps for creating something in the most efficient and effective way.

When drawing on such a little screen this is especially important.

Perhaps the best most common abstraction you would be familiar with is the smiley face. With three simple strikes of the pen when can create a wide range of expressions. Happyface, Angryface, Sadface… and many more. All we need is three pen strokes to accurately communicate a set of expressions and emotions.

That is really good abstraction.

On the little OLED and library we are using we really only have very simple shapes, lines, and dots to draw with. Here is the list;

Rectangles (and squares),
Circles
Triangles (only big triangles are clear)
Lines
Pixels (dots).

That is all we’ve got to draw with.

This is how we draw them. I’ve written them in as code and commented all but one out. You can explore these shapes and how they are drawn by taking the forward slashes out and adding them to the lines you no longer need.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(4);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initiate the display
  display.clearDisplay();
}

void loop() {

   // display.drawRect(50,30,20,20,1);
   // display.drawLine(50,30,80,10,1);
   // display.drawTriangle(50,30,80,10,10,10,1);
   // display.drawPixel(30,30,1);

   display.drawCircle(50,30,20,1);
   display.display();
}