-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_oleds_Adafruit_SSD1306.ino
95 lines (79 loc) · 2.15 KB
/
two_oleds_Adafruit_SSD1306.ino
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
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define I2C_FREQ 400000
#define SDA_1 21
#define SCL_1 22
#define SDA_2 18
#define SCL_2 19
TwoWire I2C_1 = TwoWire(0);
TwoWire I2C_2 = TwoWire(1);
int zz;
int past = millis();
Adafruit_SSD1306 OLED1 = Adafruit_SSD1306(128, 32, &I2C_1);
Adafruit_SSD1306 OLED2 = Adafruit_SSD1306(128, 32, &I2C_2);
void setup() {
I2C_1.begin(SDA_1, SCL_1);
I2C_2.begin(SDA_2, SCL_2);
// put your setup code here, to run once:
OLED1.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
OLED2.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
OLED1.display();
OLED2.display();
delay(1000);
// Clear the buffer.
OLED1.clearDisplay();
OLED1.display();
OLED2.clearDisplay();
OLED2.display();
// text display tests
OLED1.setTextSize(1);
OLED1.setTextColor(SSD1306_WHITE);
OLED1.setCursor(0, 0);
OLED1.print("This is some text");
OLED1.print("it works!");
OLED1.println("more text here");
OLED1.println("and even more");
OLED1.setCursor(0, 0);
OLED1.display(); // actually display all of the above
// text display tests
// OLED2.invertDisplay(true);
OLED2.setTextSize(2);
OLED2.setTextColor(SSD1306_WHITE);
OLED2.setCursor(0, 0);
OLED2.println("This is");
OLED2.println("OLED 2");
OLED2.setCursor(0, 0);
OLED2.display(); // actually display all of the above
delay(2000);
OLED1.clearDisplay();
OLED1.display();
OLED2.clearDisplay();
OLED2.display();
}
void loop() {
// put your main code here, to run repeatedly:
// OLED1.clearDisplay();
// OLED1.display();
// OLED2.clearDisplay();
// OLED2.display();
int now = millis();
OLED1.setCursor(0, 0);
OLED2.setCursor(0, 0);
OLED1.fillRect(0, 0, 128, 32, BLACK);
OLED2.fillRect(0, 0, 128, 32, BLACK);
OLED1.println("OLED 1 " + String(1000 - zz));
OLED1.println("123456789012345678901");
OLED1.println("ABCDEFGHIJKLMNOPQRSTU");
OLED1.println(String(now - past));
OLED2.println("OLED 2");
OLED2.println(String(zz));
// delay(100);
// yield();
OLED1.display();
OLED2.display();
zz++;
if (zz > 1000) { zz = 0; }
past = now;
}