pleasedontcode

# OLED Controller rev_06

Mar 1st, 2026
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: # OLED Controller
  13.     - Source Code NOT compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2026-03-01 16:18:37
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* please, ajuste o código para inicialisação do */
  21.     /* display em 0x3C */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25. // Include necessary libraries for SSD1306 OLED display
  26. #include <Wire.h>
  27. #include <Adafruit_GFX.h>
  28. #include <Adafruit_SSD1306.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void initializeDisplay(void);
  34. void displayWelcomeMessage(void);
  35. void displaySystemInfo(void);
  36.  
  37. /***** DEFINITION OF I2C PINS *****/
  38. // Arduino Pro Mini I2C pins: A4 (SDA), A5 (SCL)
  39. const uint8_t displayOLED_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
  40. const uint8_t displayOLED_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
  41. const uint8_t displayOLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C;
  42.  
  43. /****** DEFINITION OF DISPLAY PARAMETERS *****/
  44. // Display resolution for SSD1306
  45. #define SCREEN_WIDTH 128
  46. #define SCREEN_HEIGHT 64
  47. #define OLED_RESET -1
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  50. // Create display object for SSD1306 at I2C address 0x3C
  51. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  52.  
  53. // Global variable to track display initialization status
  54. boolean displayInitialized = false;
  55.  
  56. void setup(void)
  57. {
  58.     // Initialize Serial communication at 9600 baud rate for debugging
  59.     Serial.begin(9600);
  60.     delay(100);
  61.    
  62.     // Initialize the I2C display at address 0x3C
  63.     initializeDisplay();
  64.    
  65.     // Check if display was successfully initialized
  66.     if (displayInitialized)
  67.     {
  68.         // Display welcome message and system information
  69.         displayWelcomeMessage();
  70.         delay(2000);
  71.        
  72.         // Display system information
  73.         displaySystemInfo();
  74.         delay(2000);
  75.     }
  76.     else
  77.     {
  78.         // If display initialization failed, output error message to Serial
  79.         Serial.println("ERROR: Display initialization failed!");
  80.     }
  81. }
  82.  
  83. void loop(void)
  84. {
  85.     // Main loop - can be extended with additional functionality
  86.    
  87.     // Display current system status every 5 seconds
  88.     if (displayInitialized)
  89.     {
  90.         display.clearDisplay();
  91.         display.setTextSize(1);
  92.         display.setTextColor(SSD1306_WHITE);
  93.         display.setCursor(10, 20);
  94.         display.println("System Running");
  95.         display.setCursor(20, 40);
  96.         display.println("Arduino Pro Mini");
  97.         display.display();
  98.        
  99.         delay(5000);
  100.     }
  101. }
  102.  
  103. // Function to initialize the SSD1306 display at I2C address 0x3C
  104. void initializeDisplay(void)
  105. {
  106.     // The Wire library is used for I2C communication
  107.     // On Arduino Pro Mini: A4 = SDA, A5 = SCL
  108.     // Wire.begin() initializes I2C without parameters uses default pins (A4, A5)
  109.     Wire.begin();
  110.    
  111.     // Add small delay to allow I2C bus to stabilize
  112.     delay(100);
  113.    
  114.     // Initialize the display with I2C address 0x3C
  115.     // SSD1306_SWITCHCAPVCC = internal VCC regulator
  116.     // displayOLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C
  117.     if (!display.begin(SSD1306_SWITCHCAPVCC, displayOLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS))
  118.     {
  119.         // If display initialization fails, output error message and set flag
  120.         Serial.println("SSD1306 allocation failed at address 0x3C");
  121.         Serial.println("Check I2C connection and address");
  122.         displayInitialized = false;
  123.        
  124.         // Do not enter infinite loop - allow program to continue
  125.         return;
  126.     }
  127.    
  128.     // Initialization successful
  129.     Serial.println("SSD1306 display initialized at address 0x3C");
  130.     displayInitialized = true;
  131.    
  132.     // Clear the display buffer and set initial display state
  133.     display.clearDisplay();
  134.     display.setTextSize(1);
  135.     display.setTextColor(SSD1306_WHITE);
  136.     display.setCursor(0, 0);
  137.     display.display();
  138.    
  139.     // Add delay to allow display to stabilize
  140.     delay(100);
  141. }
  142.  
  143. // Function to display welcome message on OLED screen
  144. void displayWelcomeMessage(void)
  145. {
  146.     // Clear display and prepare for new content
  147.     display.clearDisplay();
  148.    
  149.     // Set text parameters for title
  150.     display.setTextSize(2);
  151.     display.setTextColor(SSD1306_WHITE);
  152.     display.setCursor(15, 10);
  153.     display.println("Welcome!");
  154.    
  155.     // Set text parameters for subtitle
  156.     display.setTextSize(1);
  157.     display.setCursor(20, 35);
  158.     display.println("Arduino Pro Mini");
  159.     display.setCursor(15, 50);
  160.     display.println("SSD1306 Display");
  161.    
  162.     // Update display with new content
  163.     display.display();
  164.    
  165.     // Output confirmation message to Serial monitor
  166.     Serial.println("Welcome message displayed on OLED");
  167. }
  168.  
  169. // Function to display system information on OLED screen
  170. void displaySystemInfo(void)
  171. {
  172.     // Clear display and prepare for new content
  173.     display.clearDisplay();
  174.    
  175.     // Set text parameters
  176.     display.setTextSize(1);
  177.     display.setTextColor(SSD1306_WHITE);
  178.    
  179.     // Display system information
  180.     display.setCursor(0, 0);
  181.     display.println("System Information");
  182.     display.println("-----------------");
  183.    
  184.     display.setCursor(0, 20);
  185.     display.println("Board: Arduino Pro Mini");
  186.    
  187.     display.setCursor(0, 30);
  188.     display.println("Display: SSD1306");
  189.    
  190.     display.setCursor(0, 40);
  191.     display.println("I2C Address: 0x3C");
  192.    
  193.     display.setCursor(0, 50);
  194.     display.println("Status: OK");
  195.    
  196.     // Update display with new content
  197.     display.display();
  198.    
  199.     // Output confirmation message to Serial monitor
  200.     Serial.println("System information displayed on OLED");
  201. }
  202.  
  203. /* END CODE */
  204.  
Advertisement
Add Comment
Please, Sign In to add comment