forked from kjhughes097/pi-ssd1306-oled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay-a.cpp
54 lines (38 loc) · 1.3 KB
/
display-a.cpp
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
// Ken Hughes
// July 2016
#include <unistd.h>//Needed for I2C port
#include <fcntl.h>//Needed for I2C port
#include <sys/ioctl.h>//Needed for I2C port
#include <linux/i2c-dev.h>//Needed for I2C port
#include <stdio.h>
#include <string.h>
void writeI2C(unsigned char* data, int bytes) {
int i2cAddress = 0x3C;
int i2cHandle;
char *deviceName = (char*)"/dev/i2c-1";
if ((i2cHandle = open(deviceName, O_RDWR)) < 0) {
printf("error opening I2C\n");
}
else {
if (ioctl(i2cHandle, I2C_SLAVE, i2cAddress) < 0) {
printf("Error at ioctl\n");
}
else {
write(i2cHandle, data, bytes);
}
// Close the i2c device bus
close(*deviceName);
}
}
int main() {
// initialise the display
unsigned char initSequence[26] = {0x00,0xAE,0xA8,0x1F,0xD3,0x00,0x40,0xA1,0xC8,0xDA,0x02,0x81,0x8F,
0xA4,0xA6,0xD5,0x80,0x8D,0x14,0xD9,0x22,0xD8,0x30,0x20,0x00,0xAF};
writeI2C(initSequence, 26);
// set the range we want to use (whole display)
unsigned char setFullRange[7] = {0x00,0x21,0x00,0x7F,0x22,0x00,0x03};
writeI2C(setFullRange,7);
// send the letter A to the display
unsigned char letterA[5] = {0x40,0x7E,0x12,0x12,0x7E};
writeI2C(letterA,5);
}