Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: # OLED Controller
- - Source Code NOT compiled for: Arduino Pro Mini 5V
- - Source Code created on: 2026-03-01 16:18:37
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* please, ajuste o código para inicialisação do */
- /* display em 0x3C */
- /****** END SYSTEM REQUIREMENTS *****/
- // Include necessary libraries for SSD1306 OLED display
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void initializeDisplay(void);
- void displayWelcomeMessage(void);
- void displaySystemInfo(void);
- /***** DEFINITION OF I2C PINS *****/
- // Arduino Pro Mini I2C pins: A4 (SDA), A5 (SCL)
- const uint8_t displayOLED_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
- const uint8_t displayOLED_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
- const uint8_t displayOLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C;
- /****** DEFINITION OF DISPLAY PARAMETERS *****/
- // Display resolution for SSD1306
- #define SCREEN_WIDTH 128
- #define SCREEN_HEIGHT 64
- #define OLED_RESET -1
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- // Create display object for SSD1306 at I2C address 0x3C
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- // Global variable to track display initialization status
- boolean displayInitialized = false;
- void setup(void)
- {
- // Initialize Serial communication at 9600 baud rate for debugging
- Serial.begin(9600);
- delay(100);
- // Initialize the I2C display at address 0x3C
- initializeDisplay();
- // Check if display was successfully initialized
- if (displayInitialized)
- {
- // Display welcome message and system information
- displayWelcomeMessage();
- delay(2000);
- // Display system information
- displaySystemInfo();
- delay(2000);
- }
- else
- {
- // If display initialization failed, output error message to Serial
- Serial.println("ERROR: Display initialization failed!");
- }
- }
- void loop(void)
- {
- // Main loop - can be extended with additional functionality
- // Display current system status every 5 seconds
- if (displayInitialized)
- {
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(SSD1306_WHITE);
- display.setCursor(10, 20);
- display.println("System Running");
- display.setCursor(20, 40);
- display.println("Arduino Pro Mini");
- display.display();
- delay(5000);
- }
- }
- // Function to initialize the SSD1306 display at I2C address 0x3C
- void initializeDisplay(void)
- {
- // The Wire library is used for I2C communication
- // On Arduino Pro Mini: A4 = SDA, A5 = SCL
- // Wire.begin() initializes I2C without parameters uses default pins (A4, A5)
- Wire.begin();
- // Add small delay to allow I2C bus to stabilize
- delay(100);
- // Initialize the display with I2C address 0x3C
- // SSD1306_SWITCHCAPVCC = internal VCC regulator
- // displayOLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C
- if (!display.begin(SSD1306_SWITCHCAPVCC, displayOLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS))
- {
- // If display initialization fails, output error message and set flag
- Serial.println("SSD1306 allocation failed at address 0x3C");
- Serial.println("Check I2C connection and address");
- displayInitialized = false;
- // Do not enter infinite loop - allow program to continue
- return;
- }
- // Initialization successful
- Serial.println("SSD1306 display initialized at address 0x3C");
- displayInitialized = true;
- // Clear the display buffer and set initial display state
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(SSD1306_WHITE);
- display.setCursor(0, 0);
- display.display();
- // Add delay to allow display to stabilize
- delay(100);
- }
- // Function to display welcome message on OLED screen
- void displayWelcomeMessage(void)
- {
- // Clear display and prepare for new content
- display.clearDisplay();
- // Set text parameters for title
- display.setTextSize(2);
- display.setTextColor(SSD1306_WHITE);
- display.setCursor(15, 10);
- display.println("Welcome!");
- // Set text parameters for subtitle
- display.setTextSize(1);
- display.setCursor(20, 35);
- display.println("Arduino Pro Mini");
- display.setCursor(15, 50);
- display.println("SSD1306 Display");
- // Update display with new content
- display.display();
- // Output confirmation message to Serial monitor
- Serial.println("Welcome message displayed on OLED");
- }
- // Function to display system information on OLED screen
- void displaySystemInfo(void)
- {
- // Clear display and prepare for new content
- display.clearDisplay();
- // Set text parameters
- display.setTextSize(1);
- display.setTextColor(SSD1306_WHITE);
- // Display system information
- display.setCursor(0, 0);
- display.println("System Information");
- display.println("-----------------");
- display.setCursor(0, 20);
- display.println("Board: Arduino Pro Mini");
- display.setCursor(0, 30);
- display.println("Display: SSD1306");
- display.setCursor(0, 40);
- display.println("I2C Address: 0x3C");
- display.setCursor(0, 50);
- display.println("Status: OK");
- // Update display with new content
- display.display();
- // Output confirmation message to Serial monitor
- Serial.println("System information displayed on OLED");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment