-
Notifications
You must be signed in to change notification settings - Fork 2
/
oledi2c_double.h
107 lines (88 loc) · 2.17 KB
/
oledi2c_double.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET -1 // no reset
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_SSD1306 display2(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void oled1(bool init){
Wire.begin(D1,D2); Wire.setClock(400000L); // set i2c speed 400khz
if(init)display.begin(SSD1306_SWITCHCAPVCC, 0x3c,false); // initialize with the I2C addr 0x3D (for the 128x64)
}
void oled2(bool init){
Wire.begin(D5,D6); Wire.setClock(400000L); // set i2c speed 400khz
if(init)display2.begin(SSD1306_SWITCHCAPVCC, 0x3c,false); // initialize with the I2C addr 0x3D (for the 128x64)
}
uint16_t curX = 0;
uint16_t curY = 0;
void flusholed1(){
display.display();
oled2(false);
// display.clearDisplay();
curX = display.getCursorX();
curY = display.getCursorY();
Serial.println(curX);
Serial.println(curY);
// display.clearDisplay();
// display.setCursor(0,curY); //reset line
}
void flusholed2(){
display2.display();
oled1(false);
// display2.clearDisplay();
}
void clearDisplays(){
oled2(false);
display.setCursor(0,0);
display.clearDisplay();
display.display();
oled1(false);
display2.setCursor(0,0);
display2.clearDisplay();
display2.display();
}
void clearLine(){
display.setCursor(curX,curY);
}
void testScroll(){
for(int i = 0;i<200;i++){
display.println(i*345345);
flusholed1();
display2.println(i*435234523);
flusholed2();
yield();
}
delay(0);
}
void init_oled(){
oled1(true);
oled2(true);
#ifndef _Adafruit_SSD1306_H_
display.setTextScroll(true);
display2.setTextScroll(true);
#endif
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display2.clearDisplay();
display2.setTextSize(1);
display2.setTextColor(WHITE);
display2.setCursor(0,0);
oled1(false);
display.println("Booting oled 1....");
flusholed1();
display2.println("Booting oled 2....");
flusholed2();
oled1(false);
display.println("0123456789");
flusholed1();
display2.println("101112131415161718");
flusholed2();
// testScroll();
delay(2000);
clearDisplays();
delay(2000);
}