Módulo 2 – Aula 8: Programando o Display OLED

Na aula 8 do módulo 2 você vai aprender como utilizar o display OLED com o Arduino.

Para aprender a criar sua propia imagem no display OLED, acesse o post “Como criar imagens em display OLED“, da Maker Hero Gedeane Kenshima.

Exercício 1:

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

#define OLED_LARGURA 128 // Largura display, em pixels
#define OLED_ALTURA 64 // Altura display, em pixels

#define OLED_RESET     -1 // Declara pino reset para I2C. Será o mesmo reset da placa 
#define OLED_ADDRESS 0x3C // Define o endereço I2C do display OLED 
Adafruit_SSD1306 oled(OLED_LARGURA, OLED_ALTURA, &Wire, OLED_RESET); // Cria um objeto chamado OLED

void setup(){
  
 oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS); // SSD1306_SWITCHCAPVCC = gera uma tensão de exibição de 3,3V internamente
 oled.clearDisplay(); // Apaga qualquer informação que está no display
 
 oled.setTextColor(SSD1306_WHITE); // Define a cor do texto
 oled.setTextSize(1); // Define o tamanho do texto
 oled.setCursor(0,0); // Define a posição inicial do texto
 oled.print("Ola mundo!"); // Define a frase que será apresentada no display
 oled.display(); // Imprime no display as informações anteriores
}

void loop(){
  
}

Exercício 2:

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

#define OLED_LARGURA 128 // Largura display, em pixels
#define OLED_ALTURA 64 // Altura display, em pixels

#define OLED_RESET     -1 // Declara pino reset para I2C. Será o mesmo reset da placa 
#define OLED_ADDRESS 0x3C // Define o endereço I2C do display OLED 
Adafruit_SSD1306 oled(OLED_LARGURA, OLED_ALTURA, &Wire, OLED_RESET); // Cria um objeto chamado OLED

void setup(){
  
 oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS); // SSD1306_SWITCHCAPVCC = gera uma tensão de exibição de 3,3V internamente
 oled.clearDisplay(); // Apaga qualquer informação que está no display
 
 oled.drawPixel(0, 0, SSD1306_WHITE); // Define a posição do pixel (x, y)
 oled.display(); // Imprime no display as informações anteriores

 //oled.drawLine(0, 0, 128, 0, SSD1306_WHITE); // Define a posição inicial e final da linha (x1, y1, x2, y2)
 //oled.display(); // Imprime no display as informações anteriores

 //oled.drawRect(0, 0, 128, 64, SSD1306_WHITE); // Define a posição inicial, largura e altura (x, y, largura, altura)
 //oled.display(); // Imprime no display as informações anteriores

 //oled.fillRect(0, 0, 128, 64, SSD1306_WHITE); // Define a posição inicial, largura e altura (x, y, largura, altura)
 //oled.display(); // Imprime no display as informações anteriores

 //oled.drawCircle(64, 32, 32, SSD1306_WHITE); // Define a posição do centro e raio (x, y, raio)
 //oled.display(); // Imprime no display as informações anteriores
 
 //oled.fillCircle(64, 32, 32, SSD1306_WHITE); // Define a posição do centro e raio (x, y, raio)
 //oled.display(); // Imprime no display as informações anteriores

 //oled.drawRoundRect(0, 0, 128, 64, 10, SSD1306_WHITE); // Define a posição inicial e raio dos cantos (x, y, raio dos cantos)
 //oled.display(); // Imprime no display as informações anteriores
 
 //oled.fillRoundRect(0, 0, 128, 64, 10, SSD1306_WHITE); // Define a posição inicial e raio dos cantos (x, y, raio dos cantos) 
 //oled.display(); // Imprime no display as informações anteriores
  
 //oled.drawTriangle(64, 0, 0, 63, 127, 63, SSD1306_WHITE); // Define a posição de cada extremidade (x1, y1, x2, y2, x3, y3)
 //oled.display(); // Imprime no display as informações anteriores

 //oled.fillTriangle(64, 0, 0, 63, 127, 63, SSD1306_WHITE); // Define a posição de cada extremidade (x1, y1, x2, y2, x3, y3)
 //oled.display(); // Imprime no display as informações anteriores
 
 //oled.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Define a cor do texto e a cor do fundo
 //oled.setTextSize(1); // Define o tamanho do texto
 //oled.setCursor(0,0); // Define a posição inicial do texto
 //oled.print("Ola mundo!"); // Define a frase que será apresentada no display
 //oled.display(); // Imprime no display as informações anteriores

}


void loop(){
  
}

Exercício 3:

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

#define OLED_LARGURA 128 // Largura display, em pixels
#define OLED_ALTURA 64 // Altura display, em pixels

#define OLED_RESET     -1 // Declara pino reset para I2C. Será o mesmo reset da placa 
#define OLED_ADDRESS 0x3C // Define o endereço I2C do display OLED 
Adafruit_SSD1306 oled(OLED_LARGURA, OLED_ALTURA, &Wire, OLED_RESET); // Cria um objeto chamado OLED

// Altura e largura logo (alterar tamanho se necessário)
#define LOGO_LARGURA  128 // Largura da imagem, em pixels
#define LOGO_ALTURA   64 // Altura da imagem, em pixels

// Códigos hexadecimais para a imagem
static const unsigned char PROGMEM FilipeFlop[] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x0f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xf8, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x1f, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfe, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0x1b, 0xbd, 0xcf, 0x1e, 0x2f, 0x9c, 0x7f, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0x1b, 0xbd, 0xc6, 0x1c, 0x27, 0x0c, 0x3f, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xbd, 0xd2, 0x7d, 0xe7, 0x2c, 0xbf, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xbd, 0xd2, 0x7d, 0xe7, 0x2c, 0xbf, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xbd, 0xd2, 0x7d, 0xe7, 0x2c, 0xbf, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0x7b, 0xbd, 0xd2, 0x7d, 0xe7, 0x2c, 0x3f, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0x3b, 0xbd, 0xc6, 0x3c, 0x67, 0x2c, 0x7f, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xbd, 0xde, 0x7d, 0xe7, 0x2c, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xbd, 0xde, 0x7d, 0xe7, 0x2c, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xbd, 0xde, 0x7d, 0xe7, 0x2c, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0xbd, 0xde, 0x7d, 0xe7, 0x2c, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xfe, 0xfb, 0x8d, 0xde, 0x1d, 0xe1, 0x0c, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};

void setup(){
  
 oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS); // SSD1306_SWITCHCAPVCC = gera uma tensão de exibição de 3,3V internamente
 oled.clearDisplay(); // Apaga qualquer informação que está no display

 oled.drawBitmap(0, 0, FilipeFlop, LOGO_LARGURA, LOGO_ALTURA, SSD1306_WHITE); //Define a imagem que será impressa no display 
                                                                              //(x, y, nome da imagem, largura da imagem, altura da imagem)
 oled.display();  // Imprime no display as informações anteriores
}

void loop(){
  
}