-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSD1306.h
More file actions
165 lines (128 loc) · 4.12 KB
/
SSD1306.h
File metadata and controls
165 lines (128 loc) · 4.12 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* File: SSD1306.h
* Author: philippe SIMIER Lycée Touchard
*
* Created on 5 octobre 2024, 09:01
* This is a library for our Monochrome OLEDs based on SSD1306 drivers
*/
#include <iostream>
#include "i2c.h"
#include <cstring> // Nécessaire pour utiliser memset
#include <sstream>
#include <iomanip>
#include "oled_fonts.h"
#define SSD1306_I2C_ADDRESS 0x3C
#define SSD1306_128_64
#if defined SSD1306_128_32
#define WIDTH 128
#define HEIGHT 32
#endif
#if defined SSD1306_128_64
#define WIDTH 128
#define HEIGHT 64
#endif
#if defined SSD1306_96_16
#define WIDTH 96
#define HEIGHT 16
#endif
#if defined SSD1306_128_64 && defined SSD1306_128_32
#error "Only one SSD1306 display can be specified at once in SSD1306.h"
#endif
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
#error "At least one SSD1306 display must be specified in SSD1306.h"
#endif
#if defined SSD1306_128_64
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64
#endif
#if defined SSD1306_128_32
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 32
#endif
#if defined SSD1306_96_16
#define SSD1306_LCDWIDTH 96
#define SSD1306_LCDHEIGHT 16
#endif
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COLUMNADDR 0x21
#define SSD1306_PAGEADDR 0x22
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
#define SSD1306_CHARGEPUMP 0x8D
#define SSD1306_EXTERNALVCC 0x1
#define SSD1306_SWITCHCAPVCC 0x2
// Scrolling #defines
#define SSD1306_ACTIVATE_SCROLL 0x2F
#define SSD1306_DEACTIVATE_SCROLL 0x2E
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
//#define rotation 2
#define BLACK 0
#define WHITE 1
#define INVERSE 2
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
class SSD1306 {
public:
SSD1306(int8_t address = SSD1306_I2C_ADDRESS);
SSD1306(const SSD1306& orig) = delete;
virtual ~SSD1306();
void begin(unsigned int switchvcc = SSD1306_SWITCHCAPVCC);
void clear();
void invert(unsigned int i);
void display();
void flipScreenVertically();
void setCursor(const int x, const int y);
void drawPixel(int x, int y, unsigned int color);
void setTextSize(int _size);
void drawChar(int x, int y, unsigned char c, int color, int size);
void fillRect(int x, int y, int w, int h, int fillcolor);
void drawFastHLine(int x, int y, int w, unsigned int color);
void write(const char c);
void write(const char *str);
void write(const std::string &str);
void write(const int n);
void write(const double n);
void scrollRight(unsigned int start, unsigned int stop);
void scrollLeft(unsigned int start, unsigned int stop);
void scrollStop(void);
SSD1306& operator<<(SSD1306& (*)(SSD1306&));
SSD1306& operator<<(const std::string&);
SSD1306& operator<<(const int);
SSD1306& operator<<(const double);
SSD1306& operator<<(const char);
SSD1306& operator<<(const char *);
SSD1306& operator<<(const bool);
private:
i2c *deviceI2C; // file descriptor
bool presence;
int vccstate;
int cursor_y;
int cursor_x;
int size;
int interligne;
int rotation;
int pixel[1024]; // Tableau des pixels
void swap(int &x, int &y);
};
SSD1306& display(SSD1306& sx);
SSD1306& clear(SSD1306& sx);