/*Serial Peripheral Interface (SPI) is a
synchronous serial communication protocol used by
microcontrollers for communicating with one or
more peripheral devices quickly over short
distances.When using SPI, there is always one
master device (usually a microcontroller) that
controls all peripheral devices.*/
# include <SPI.h>
/*This library allows you to communicate with
I2C / devices. I2C is a serial communication
protocol, so data is transferred bit by bit along a
single wire*/
# include <Wire.h>
/*This library offers a common
graphical syntax and set of functions for all LCD
displays, OLED displays, and LED matrices.*/
# include <Adafruit_GFX.h>
/*This library takes care of
low-level communication with the hardware*/
# include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// -1 indicates that our OLED display does not have a RESET pin.
// represents the internal buffer of the OLED driverv (-1)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
// ● If the OLED displays nothing, check the OLED
// address at 0x3C. In our case, the address is 0x3C.
// ● If we are not able to connect to the display, it prints
// a message on the Serial Monitor.
// ● If something fails, don't proceed further, try to repeat
// the process using for() loop
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("SSD1306 allocation failed");
for(;;);
}
delay(2000);
//if skipped prints at top left corner.
display.setCursor(0, 0);
}
void loop()
{
// clear buffer display, otherwise prints along with adafruit logo
display.clearDisplay();
// (CenterX, CenterY, Radius in Pixels, WHITE);
display.drawCircle(40,30,30,WHITE);
// if skipped cannot see anything
display.display();
delay(1000);
// clear buffer display, otherwise prints along with adafruit logo
display.clearDisplay();
// (CenterX, CenterY, Radius in Pixels, WHITE);
display.fillCircle(40,30,30,WHITE);
// if skipped cannot see anything
display.display();
delay(2000);
// clear buffer display, otherwise prints along with adafruit logo
display.clearDisplay();
// (FirstX, FirstY, SecondX, SecondY,ThirdX, ThirdY, WHITE);
display.drawTriangle(20,40,30,20,40,40,WHITE);
// if skipped cannot see anything
display.display();
delay(1000);
// clear buffer display, otherwise prints along with adafruit logo
display.clearDisplay();
// (FirstX, FirstY, SecondX, SecondY,ThirdX, ThirdY, WHITE);
display.fillTriangle(20,40,30,20,40,40,WHITE);
// if skipped cannot see anything
display.display();
delay(2000);
// clear buffer display, otherwise prints along with adafruit logo
display.clearDisplay();
// t(StartX, StartY, Width in Pixels, Height in Pixels, WHITE);
display.drawRect(10,20,80,20,WHITE);
// if skipped cannot see anything
display.display();
delay(1000);
// clear buffer display, otherwise prints along with adafruit logo
display.clearDisplay();
// t(StartX, StartY, Width in Pixels, Height in Pixels, WHITE);
display.fillRect(10,20,80,20,WHITE);
// if skipped cannot see anything
display.display();
delay(1000);
}