IOT Virtual Lab
Interfacing OLED Display with Arduino:
ARDUINO CODE
#include
#include
#include
#include
#define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET 4 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Function to display full line word-by-word with animation void animateLine(String line, int x, int y, int wordDelay) { display.setCursor(x, y); String word = ""; for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if (c == ' ' || i == line.length() - 1) { if (i == line.length() - 1) word += c; // Include last character display.print(word + " "); display.display(); delay(wordDelay); word = ""; } else { word += c; } } } void setup() { Serial.begin(9600); if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { Serial.println(F("SSD1306 allocation failed")); while (true); } display.clearDisplay(); display.display(); delay(1000); } void loop() { display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); // First message: split into 2 lines manually animateLine("Welcome to IOT", 0, 10, 400); animateLine("Virtual Lab", 0, 20, 400); delay(1000); // pause between messages display.clearDisplay(); // Second message: also split to fit OLED screen animateLine("This is a sample", 0, 10, 300); animateLine("program of OLED", 0, 20, 300); animateLine("Display", 0, 30, 300); delay(1500); // pause before repeating }
Start Simulation
Click the pushbutton!