Thursday 7 June 2018

OLED display - Part 1 - The display function & basic shapes

OLEDs need only 4 pins

Arduino VCC -> OLED Module VCC
Arduino GND -> OLED Module GND
Arduino 4 -> OLED Module SDA
Arduino 5 -> OLED Module SCK
 
 
 In order for your OLED to display an image, animation, or text you need to be familiar
with the display function.
 
display() 

    display.clearDisplay() – all pixels are off
    display.setTextColor(WHITE)
    display.setTextColor(BLACK, WHITE); // 'inverted' text   FontColor,BackgroundColor
    display.drawPixel(x,y, color) – plot a pixel in the x,y coordinates
    display.setTextSize(n) – set the font size, range from 1 to 8
    display.setCursor(x,y) – coordinates to start writing text
    display.print(“message”) – print the characters at location x,y
    display.println("Hello world!");
    display.startscrollright(x, y);
    display.stopscroll();
    display.startscrollleft(x , y);
   display.startscrolldiagright(0x00, 0x07);   
   display.display() – call this method for the changes to make effect 
 
There are also a number of  basic shape functions worth remembering
 
Rectangle 
display.drawRect(X, Y, Width, Height, Colour);
 
Round Rectangle 
display.drawRoundRect(X, Y, Width, Height,radius of round corner, Colour);
 
Circle 
display.drawCircle(20, 35, 20, WHITE);
// (X, Y, radius, Colour);
 
Filled Circle 
display.fillCircle(20, 35, 20, WHITE);
// (X, Y, radius, Colour);
 
 
Triangle 
display.drawTriangle(30, 15, 0, 60, 60, 60, WHITE);
// (x0, y0, x1, y1, x2 , y2, colour).
// (X0,y0) represents top vertex, 
// (x1,y1) represents left vertex and (x2,y2) represents right vertex.
 
Filled Triangle 
display.fillTriangle(30, 15, 0, 60, 60, 60, WHITE);
 
 
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

The Basic code needs :
 
// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <SPI.h>
#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()   
{                
  // initialize with the I2C addr 0x3C
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  

  // Clear the buffer.
  display.clearDisplay();

// write your main code & display functions here

}

void loop() {}

// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
An example for a circle (filled and hollow) 
and some scrolling text is below



// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <SPI.h>
#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()   
{                
  // initialize with the I2C addr 0x3C
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  

  // Clear the buffer.
  display.clearDisplay();

// write your main code & display functions here
 
display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Circle");
  display.drawCircle(20, 35, 20, WHITE);
  display.display();
  delay(2000);
  display.clearDisplay();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Filled Circle");
  display.fillCircle(20, 35, 20, WHITE);
  display.display();
  delay(2000);
  display.clearDisplay();

// Scroll part of the screen
display.setCursor(0,0);
display.setTextSize(1);
display.println("Scroll line 1");
display.println("line 2");
display.println("line 3");
display.println("line 4");
display.display();

display.startscrollright(0x00, 0x00);
display.startscrollleft(0x01, 0x00);
display.startscrollleft(0x02, 0x00);
display.startscrollright(0x03, 0x00);

delay(10000);
  display.clearDisplay();

// Scroll full screen
display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(1);
display.println("jondent");
display.println("synth");
display.println("blog");
display.display();
display.startscrollright(0x00, 0x07);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x07);
delay(2000);
display.stopscroll();
delay(1000);    
display.startscrolldiagright(0x00, 0x07);
delay(2000);
display.startscrolldiagleft(0x00, 0x07);
delay(2000);
display.stopscroll();
 

}

void loop() {}
// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Links
These two website are indispensable.
 
-------------------------------------------------------------------------------------------

----------------------------------------------------------
 
 
 ---------------------------------
-------------------------------------

No comments:

Post a Comment