Created
January 31, 2022 03:15
-
-
Save dj1711572002/4f2da24c13e5b6a5ad8dd33acefbf089 to your computer and use it in GitHub Desktop.
Arduino DUAL OLED DISPLAY AKIZUKI test
This file contains 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 <Wire.h> | |
//#define OLED_ADRS 0x3C //SA0=L(SA0=H の場合は 0x3D) | |
int OLED_ADRS=0x3C; | |
int OLED_ADRS1=0x3D; | |
int DisplayON = 0x0F; | |
int ClearDisplay = 0x01; | |
int ReturnHome = 0x02; | |
void setup() { | |
Wire.begin(); //Wire ライブラリを初期化し、I2C マスタとしてバスに接続 | |
init_oled(0x3C); | |
init_oled(0x3D); | |
} | |
void loop() { | |
//1行目書き込み | |
char moji[] = "I2C0OLED WHITE12345"; | |
char moji1[]="I2C1OLED WHITE12345"; | |
for(int i = 0; i < 20; i++) { | |
writeData(moji[i],0x3C); | |
writeData(moji1[i],0x3D); | |
} | |
//2行目書き込み | |
writeCommand(0x20+0x80,0x3C); //2 行目の先頭 | |
writeCommand(0x20+0x80,0x3D); //2 行目の先頭 | |
for(int i = 0; i < 20; i++) { | |
writeData(i+0xB1,0x3C); | |
writeData(i+0xB1,0x3D); | |
} | |
contrast_max(0x3C); //輝度を最大に設定 | |
contrast_max(0x3D); //輝度を最大に設定 | |
while(1){} | |
} | |
//----main end---- | |
//------------------------------------- | |
void writeData(byte t_data, int adr) | |
{ | |
Wire.beginTransmission(adr); //OLED_ADRS); | |
Wire.write(0x40); | |
Wire.write(t_data); | |
Wire.endTransmission(); | |
delay(1); | |
} | |
//------------------------------------ | |
void writeCommand(byte t_command,int adr) | |
{ | |
Wire.beginTransmission(adr);//OLED_ADRS); | |
Wire.write(0x00); | |
Wire.write(t_command); | |
Wire.endTransmission(); | |
delay(10); | |
} | |
//--------------------------- | |
void contrast_max(int adr){ | |
writeCommand(0x2a,adr);//RE=1 | |
writeCommand(0x79,adr);//SD=1 | |
writeCommand(0x81,adr);//コントラストセット | |
writeCommand(0xFF,adr);//輝度MAX | |
writeCommand(0x78,adr);//SD を0にもどす | |
writeCommand(0x28,adr); //2C=高文字 28=ノーマル | |
delay(100); | |
} | |
//-------------------------------- | |
void init_oled(int adr) | |
{ | |
delay(100); | |
writeCommand(ClearDisplay,adr); // Clear Display | |
delay(20); | |
writeCommand(ReturnHome,adr); // ReturnHome | |
delay(2); | |
writeCommand(DisplayON,adr); // Send Display on command | |
delay(2); | |
writeCommand(ClearDisplay,adr); // Clear Display | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment