把四脚OLED程序改成七脚OLED程序
时间: 2024-05-10 13:18:46 浏览: 126
好的,将四脚OLED程序改成七脚OLED程序需要以下步骤:
1. 在Arduino IDE中打开四脚OLED程序,将其中的定义OLED的代码段复制到新的Arduino文件中。
2. 在新的Arduino文件中,添加以下代码段来定义7脚OLED屏幕的引脚:
```c++
#define OLED_SDA 2 //定义OLED SDA引脚
#define OLED_SCL 3 //定义OLED SCL引脚
#define OLED_RST 4 //定义OLED RST引脚
#define OLED_DC 5 //定义OLED DC引脚
#define OLED_CS 6 //定义OLED CS引脚
#define OLED_EN 7 //定义OLED EN引脚
```
3. 找到OLED初始化函数,并修改其中的引脚定义,如下所示:
```c++
void OLED_Init(void)
{
...
//原来的代码:
//Wire.beginTransmission(OLED_ADDR);
//Wire.write(0x00);
//Wire.write(0xAE);
//Wire.write(0xD5);
//Wire.write(0x80);
//Wire.write(0xA8);
//Wire.write(0x3F);
//Wire.write(0xD3);
//Wire.write(0x00);
//Wire.write(0x40);
//Wire.write(0x8D);
//Wire.write(0x14);
//Wire.write(0x20);
//Wire.write(0x00);
//Wire.write(0xA1);
//Wire.write(0xC8);
//Wire.write(0xDA);
//Wire.write(0x12);
//Wire.write(0x81);
//Wire.write(0xCF);
//Wire.write(0xD9);
//Wire.write(0xF1);
//Wire.write(0xDB);
//Wire.write(0x40);
//Wire.write(0xA4);
//Wire.write(0xA6);
//Wire.write(0xAF);
//Wire.endTransmission();
//新的代码:
Wire.beginTransmission(OLED_ADDR);
Wire.write(0x00);
Wire.write(0xAE);
Wire.write(0xD5);
Wire.write(0x80);
Wire.write(0xA8);
Wire.write(0x3F);
Wire.write(0xD3);
Wire.write(0x00);
Wire.write(0x40);
Wire.write(0x8D);
Wire.write(0x14);
Wire.write(0x20);
Wire.write(0x00);
Wire.write(0xA1);
Wire.write(0xC8);
Wire.write(0xDA);
Wire.write(0x12);
Wire.write(0x81);
Wire.write(0xCF);
Wire.write(0xD9);
Wire.write(0xF1);
Wire.write(0xDB);
Wire.write(0x40);
Wire.write(0xA4);
Wire.write(0xA6);
Wire.write(0xAF);
Wire.endTransmission();
}
```
在新代码中,我们将OLED的引脚连接到了7脚,这样程序就能够正常地控制7脚OLED屏幕了。
4. 最后,将新的代码上传到Arduino板子中,连接7脚OLED屏幕和Arduino,测试程序是否正常工作。
这样就完成了将四脚OLED程序改成七脚OLED程序的过程。
阅读全文