Advertisement
pleasedontcode

OLED Hello rev_01

Oct 19th, 2024
79
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 Hello
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-19 21:02:45
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* just check that the display works in a espduino 32 */
  21.     /* hw 707 (almost the same that d1 r32) whit a simple */
  22.     /* code. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Wire.h>
  27. #include <Adafruit_SSD1306.h>    // https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
  28. #include <U8g2_for_Adafruit_GFX.h> // https://github.com/olikraus/U8g2_for_Adafruit_GFX
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF I2C PINS *****/
  35. const uint8_t SSD1306_I2C_PIN_SDA = 21; // SDA pin
  36. const uint8_t SSD1306_I2C_PIN_SCL = 22; // SCL pin
  37. const uint8_t SSD1306_I2C_SLAVE_ADDRESS = 60; // I2C address
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  40. Adafruit_SSD1306 display(SSD1306_I2C_SLAVE_ADDRESS); // Initialize the display object
  41. U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; // Initialize U8g2 for Adafruit GFX
  42.  
  43. void setup(void)
  44. {
  45.     // Initialize the display
  46.     display.begin(SSD1306_SWITCHCAPVCC, SSD1306_I2C_SLAVE_ADDRESS); // Start the display
  47.     display.clearDisplay(); // Clear the display buffer
  48.  
  49.     // Connect U8g2 procedures to Adafruit GFX
  50.     u8g2_for_adafruit_gfx.begin(display); // Initialize U8g2 with the display object
  51.    
  52.     // Example to set font and display text
  53.     u8g2_for_adafruit_gfx.setFontMode(1); // Use U8g2 transparent mode
  54.     u8g2_for_adafruit_gfx.setFontDirection(0); // Left to right
  55.     u8g2_for_adafruit_gfx.setForegroundColor(WHITE); // Set text color to white
  56.     u8g2_for_adafruit_gfx.setFont(u8g2_font_helvR14_tf); // Select a font
  57.     u8g2_for_adafruit_gfx.setCursor(0, 20); // Set cursor position
  58.     u8g2_for_adafruit_gfx.print(F("Hello World")); // Print text
  59.     display.display(); // Make everything visible
  60.     delay(2000); // Delay for 2 seconds
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // Main code to run repeatedly
  66.     display.clearDisplay(); // Clear the display buffer
  67.     u8g2_for_adafruit_gfx.setCursor(0, 20); // Set cursor position
  68.     u8g2_for_adafruit_gfx.print(F("Hello World")); // Print text
  69.     display.display(); // Make everything visible
  70.     delay(2000); // Delay for 2 seconds
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement