/******************************************************************************
This Arduino sketch sets up and uses an OLED display (128x64 pixels) to show text and a counter.
The code uses several libraries such as SPI, Wire, Adafruit_GFX, and Adafruit_SSD1306.
The display is initialized in the setup() function, and a "Hello, world!" message and a
"test" message are shown on the screen.
In the loop() function, the display is cleared, and the value of the variable x is
printed at coordinates (0, 20) on the screen. The value of x is incremented every
second, and the display is updated accordingly.
The code uses the SSD1306 library and the Adafruit_GFX library to handle the OLED display.
It initializes the display, sets rotation, displays text messages, and updates the display
with the value of the counter.
Note: The provided code is only a part of a larger program
, and its functionality may depend on other parts of the code not shown here.
**********************************************************************/
#include <SPI.h>
#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
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int x = 0;
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.setRotation(4); //sets rotation 1 through 4
display.display();
delay(1000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw text
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(10,0); // Start at top-left corner
display.print("BY ARVIND");
delay(300);
display.setCursor(0,30);
display.print("seconds");
delay(300);
display.setCursor(0,50);
display.print("counter");
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000);
display.setTextSize(6);
}
void loop() {
display.clearDisplay();
display.setCursor(0,20);
display.print(x);
display.display();
delay(1000);
x++;
}