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 Marquee
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2025-10-11 15:38:26
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* 我想要用ESP32微控制器加上OLED螢幕的Arduino程式碼,並且要在螢幕上產生修平科技大學智慧 */
- /* 車輛系的字樣,並且加上跑馬燈,然後請提前幫排除問題1.避免程式碼生成後螢幕出現白點亂碼2.避免少字體 */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- /****** DEFINITIONS *****/
- #ifndef SCREEN_WIDTH
- #define SCREEN_WIDTH 128
- #endif
- #ifndef SCREEN_HEIGHT
- #define SCREEN_HEIGHT 64
- #endif
- #define OLED_RESET -1
- #define OLED_ADDRESS 0x3C
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- // Marquee text (ASCII fallback for reliable rendering)
- static const char marqueeText[] = "Xiping Tech Univ Smart Vehicle Dept ";
- static int marqueeX = 0;
- static unsigned long lastMarqueeUpdate = 0;
- static const unsigned long MARQUEE_DELAY = 70; // adjust speed (ms)
- void setup() {
- // Initialize I2C and OLED
- if(!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS)) {
- // Try alternative address commonly used by some modules
- if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) {
- // If still failing, loop forever
- for(;;);
- }
- }
- // prevent white dots by turning off charge pump briefly during init
- display.clearDisplay();
- display.display();
- // Optional small welcome sequence
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.println("Initializing OLED...");
- display.display();
- delay(800);
- // Show a simple, reliable heading (ASCII fallback)
- display.clearDisplay();
- display.setCursor(0, 0);
- display.setTextSize(1);
- display.println("Xiping Tech Univ");
- display.println("Smart Vehicle Dept");
- display.display();
- delay(1200);
- // Clear to start marquee
- display.clearDisplay();
- display.display();
- }
- void loop() {
- unsigned long now = millis();
- if(now - lastMarqueeUpdate >= MARQUEE_DELAY) {
- lastMarqueeUpdate = now;
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- // Marquee: draw text with horizontal offset
- int y = 28;
- display.setCursor(-marqueeX, y);
- display.print(marqueeText);
- display.display();
- // Update offset
- marqueeX++;
- int textW;
- int16_t x1, y1;
- uint16_t wText, hText;
- // Measure text width
- display.getTextBounds(marqueeText, 0, y, &x1, &y1, &wText, &hText);
- textW = (int)wText;
- if(marqueeX > textW) marqueeX = 0;
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment