Created
April 29, 2026 09:22
-
-
Save woodif/5e3542b6bc6da8c4f1fefcdcd895e2ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Arduino.h> | |
| #include <U8g2lib.h> | |
| #include <Wire.h> | |
| // --------------------------------------------------- | |
| // กำหนดขา SDA และ SCL ใหม่ตรงนี้ได้ตามใจชอบเลยครับ | |
| // ตัวอย่างนี้ผมสมมติให้ใช้ GPIO 21 และ GPIO 22 | |
| // --------------------------------------------------- | |
| #define CUSTOM_SDA 21 | |
| #define CUSTOM_SCL 22 | |
| // ประกาศใช้งานจอ OLED ชิป SSD1309 ผ่าน Hardware I2C | |
| U8G2_SSD1309_128X64_NONAME0_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); | |
| int counter = 0; | |
| void setup() { | |
| Serial.begin(115200); | |
| Serial.println("Starting OLED Test with Custom I2C Pins..."); | |
| // หัวใจสำคัญอยู่ตรงนี้: สั่งให้ I2C เริ่มต้นทำงานที่ขาที่เรากำหนด | |
| Wire.begin(CUSTOM_SDA, CUSTOM_SCL); | |
| // เริ่มต้นการทำงานของจอ | |
| if (!u8g2.begin()) { | |
| Serial.println("Failed to initialize OLED!"); | |
| while (1); | |
| } | |
| } | |
| void loop() { | |
| u8g2.clearBuffer();y | |
| u8g2.drawFrame(0, 0, 128, 64); | |
| u8g2.setFont(u8g2_font_ncenB14_tr); | |
| u8g2.drawStr(12, 25, "ESP32 Test"); | |
| u8g2.setFont(u8g2_font_ncenB08_tr); | |
| u8g2.drawStr(15, 42, "Custom Pins!"); // เปลี่ยนข้อความเล็กน้อยให้รู้ว่ารันโค้ดใหม่ | |
| u8g2.setCursor(35, 55); | |
| u8g2.print("Count: "); | |
| u8g2.print(counter); | |
| u8g2.sendBuffer(); | |
| counter++; | |
| delay(1000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment