Viking Skull Lamp  V1.0.1
Loading...
Searching...
No Matches
oled.hpp
Go to the documentation of this file.
1/*
2 * Created on May 28 2022
3 *
4 * Copyright (c) 2022 - Daniel Hajnal
5 * hajnal.daniel96@gmail.com
6 * This file is part of the Viking Skull Lamp project.
7 * Modified 2022.06.27
8*/
9
10/*
11MIT License
12Copyright (c) 2022 Daniel Hajnal
13Permission is hereby granted, free of charge, to any person obtaining a copy
14of this software and associated documentation files (the "Software"), to deal
15in the Software without restriction, including without limitation the rights
16to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17copies of the Software, and to permit persons to whom the Software is
18furnished to do so, subject to the following conditions:
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27SOFTWARE.
28*/
29
30#ifndef OLED_HPP__
31#define OLED_HPP__
32
33#include "Arduino.h"
34#include "Wire.h"
35#include "stdint.h"
36
38#define SSD1306_WIDTH 128
39
41#define SSD1306_HEIGHT 32
42
48const uint8_t ASCII[] PROGMEM = {
49 0x00, 0x00, 0x00, 0x00, 0x00 // 0x20 Space
50 ,0x00, 0x00, 0x5f, 0x00, 0x00 // 0x21 !
51 ,0x00, 0x07, 0x00, 0x07, 0x00 // 0x22 "
52 ,0x14, 0x7f, 0x14, 0x7f, 0x14 // 0x23 #
53 ,0x24, 0x2a, 0x7f, 0x2a, 0x12 // 0x24 $
54 ,0x23, 0x13, 0x08, 0x64, 0x62 // 0x25 %
55 ,0x36, 0x49, 0x55, 0x22, 0x50 // 0x26 &
56 ,0x00, 0x05, 0x03, 0x00, 0x00 // 0x27 '
57 ,0x00, 0x1c, 0x22, 0x41, 0x00 // 0x28 (
58 ,0x00, 0x41, 0x22, 0x1c, 0x00 // 0x29 )
59 ,0x14, 0x08, 0x3e, 0x08, 0x14 // 0x2a *
60 ,0x08, 0x08, 0x3e, 0x08, 0x08 // 0x2b +
61 ,0x00, 0x50, 0x30, 0x00, 0x00 // 0x2c ,
62 ,0x08, 0x08, 0x08, 0x08, 0x08 // 0x2d -
63 ,0x00, 0x60, 0x60, 0x00, 0x00 // 0x2e .
64 ,0x20, 0x10, 0x08, 0x04, 0x02 // 0x2f /
65 ,0x3e, 0x51, 0x49, 0x45, 0x3e // 0x30 0
66 ,0x00, 0x42, 0x7f, 0x40, 0x00 // 0x31 1
67 ,0x42, 0x61, 0x51, 0x49, 0x46 // 0x32 2
68 ,0x21, 0x41, 0x45, 0x4b, 0x31 // 0x33 3
69 ,0x18, 0x14, 0x12, 0x7f, 0x10 // 0x34 4
70 ,0x27, 0x45, 0x45, 0x45, 0x39 // 0x35 5
71 ,0x3c, 0x4a, 0x49, 0x49, 0x30 // 0x36 6
72 ,0x01, 0x71, 0x09, 0x05, 0x03 // 0x37 7
73 ,0x36, 0x49, 0x49, 0x49, 0x36 // 0x38 8
74 ,0x06, 0x49, 0x49, 0x29, 0x1e // 0x39 9
75 ,0x00, 0x36, 0x36, 0x00, 0x00 // 0x3a :
76 ,0x00, 0x56, 0x36, 0x00, 0x00 // 0x3b ;
77 ,0x08, 0x14, 0x22, 0x41, 0x00 // 0x3c <
78 ,0x14, 0x14, 0x14, 0x14, 0x14 // 0x3d =
79 ,0x00, 0x41, 0x22, 0x14, 0x08 // 0x3e >
80 ,0x02, 0x01, 0x51, 0x09, 0x06 // 0x3f ?
81 ,0x32, 0x49, 0x79, 0x41, 0x3e // 0x40 @
82 ,0x7e, 0x11, 0x11, 0x11, 0x7e // 0x41 A
83 ,0x7f, 0x49, 0x49, 0x49, 0x36 // 0x42 B
84 ,0x3e, 0x41, 0x41, 0x41, 0x22 // 0x43 C
85 ,0x7f, 0x41, 0x41, 0x22, 0x1c // 0x44 D
86 ,0x7f, 0x49, 0x49, 0x49, 0x41 // 0x45 E
87 ,0x7f, 0x09, 0x09, 0x09, 0x01 // 0x46 F
88 ,0x3e, 0x41, 0x49, 0x49, 0x7a // 0x47 G
89 ,0x7f, 0x08, 0x08, 0x08, 0x7f // 0x48 H
90 ,0x00, 0x41, 0x7f, 0x41, 0x00 // 0x49 I
91 ,0x20, 0x40, 0x41, 0x3f, 0x01 // 0x4a J
92 ,0x7f, 0x08, 0x14, 0x22, 0x41 // 0x4b K
93 ,0x7f, 0x40, 0x40, 0x40, 0x40 // 0x4c L
94 ,0x7f, 0x02, 0x0c, 0x02, 0x7f // 0x4d M
95 ,0x7f, 0x04, 0x08, 0x10, 0x7f // 0x4e N
96 ,0x3e, 0x41, 0x41, 0x41, 0x3e // 0x4f O
97 ,0x7f, 0x09, 0x09, 0x09, 0x06 // 0x50 P
98 ,0x3e, 0x41, 0x51, 0x21, 0x5e // 0x51 Q
99 ,0x7f, 0x09, 0x19, 0x29, 0x46 // 0x52 R
100 ,0x46, 0x49, 0x49, 0x49, 0x31 // 0x53 S
101 ,0x01, 0x01, 0x7f, 0x01, 0x01 // 0x54 T
102 ,0x3f, 0x40, 0x40, 0x40, 0x3f // 0x55 U
103 ,0x1f, 0x20, 0x40, 0x20, 0x1f // 0x56 V
104 ,0x3f, 0x40, 0x38, 0x40, 0x3f // 0x57 W
105 ,0x63, 0x14, 0x08, 0x14, 0x63 // 0x58 X
106 ,0x07, 0x08, 0x70, 0x08, 0x07 // 0x59 Y
107 ,0x61, 0x51, 0x49, 0x45, 0x43 // 0x5a Z
108 ,0x00, 0x7f, 0x41, 0x41, 0x00 // 0x5b [
109 ,0x02, 0x04, 0x08, 0x10, 0x20 // 0x5c backslash
110 ,0x00, 0x41, 0x41, 0x7f, 0x00 // 0x5d ]
111 ,0x04, 0x02, 0x01, 0x02, 0x04 // 0x5e ^
112 ,0x40, 0x40, 0x40, 0x40, 0x40 // 0x5f _
113 ,0x00, 0x01, 0x02, 0x04, 0x00 // 0x60 `
114 ,0x20, 0x54, 0x54, 0x54, 0x78 // 0x61 a
115 ,0x7f, 0x48, 0x44, 0x44, 0x38 // 0x62 b
116 ,0x38, 0x44, 0x44, 0x44, 0x20 // 0x63 c
117 ,0x38, 0x44, 0x44, 0x48, 0x7f // 0x64 d
118 ,0x38, 0x54, 0x54, 0x54, 0x18 // 0x65 e
119 ,0x08, 0x7e, 0x09, 0x01, 0x02 // 0x66 f
120 ,0x0c, 0x52, 0x52, 0x52, 0x3e // 0x67 g
121 ,0x7f, 0x08, 0x04, 0x04, 0x78 // 0x68 h
122 ,0x00, 0x44, 0x7d, 0x40, 0x00 // 0x69 i
123 ,0x20, 0x40, 0x44, 0x3d, 0x00 // 0x6a j
124 ,0x7f, 0x10, 0x28, 0x44, 0x00 // 0x6b k
125 ,0x00, 0x41, 0x7f, 0x40, 0x00 // 0x6c l
126 ,0x7c, 0x04, 0x18, 0x04, 0x78 // 0x6d m
127 ,0x7c, 0x08, 0x04, 0x04, 0x78 // 0x6e n
128 ,0x38, 0x44, 0x44, 0x44, 0x38 // 0x6f o
129 ,0x7c, 0x14, 0x14, 0x14, 0x08 // 0x70 p
130 ,0x08, 0x14, 0x14, 0x18, 0x7c // 0x71 q
131 ,0x7c, 0x08, 0x04, 0x04, 0x08 // 0x72 r
132 ,0x48, 0x54, 0x54, 0x54, 0x20 // 0x73 s
133 ,0x04, 0x3f, 0x44, 0x40, 0x20 // 0x74 t
134 ,0x3c, 0x40, 0x40, 0x20, 0x7c // 0x75 u
135 ,0x1c, 0x20, 0x40, 0x20, 0x1c // 0x76 v
136 ,0x3c, 0x40, 0x30, 0x40, 0x3c // 0x77 w
137 ,0x44, 0x28, 0x10, 0x28, 0x44 // 0x78 x
138 ,0x0c, 0x50, 0x50, 0x50, 0x3c // 0x79 y
139 ,0x44, 0x64, 0x54, 0x4c, 0x44 // 0x7a z
140 ,0x00, 0x08, 0x36, 0x41, 0x00 // 0x7b {
141 ,0x00, 0x00, 0x7f, 0x00, 0x00 // 0x7c |
142 ,0x00, 0x41, 0x36, 0x08, 0x00 // 0x7d }
143 ,0x10, 0x08, 0x08, 0x10, 0x08 // 0x7e ~
144 ,0x78, 0x46, 0x41, 0x46, 0x78 // 0x7f DEL
145 ,0x00, 0x3c, 0x7e, 0xe7, 0xc3 // 0x80 Half circle left
146 ,0xc3, 0xe7, 0x7e, 0x3c, 0x00 // 0x81 Half circle right
147 ,0x00, 0x3c, 0x7e, 0xFF, 0xFF // 0x82 Half full circle left
148 ,0xFF, 0xFF, 0x7e, 0x3c, 0x00 // 0x83 Half full circle right
149};
150
157
158public:
159
162 ssd1306( uint8_t address_p );
163
166 bool begin();
167
169 void displayOn();
170
172 void displayOff();
173
178 void update();
179
183 void setPixel( uint8_t x, uint8_t y );
184
188 void clearPixel( uint8_t x, uint8_t y );
189
195 void fillRect( uint8_t x, uint8_t y, uint8_t w, uint8_t h );
196
202 void clearRect( uint8_t x, uint8_t y, uint8_t w, uint8_t h );
203
207 void writeCharacter( uint8_t c );
208
210 void clear();
211
215 void print( char* str );
216
220 void print( int d );
221
227 void line( uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2 );
228
231 bool inverted = false;
232
234 uint8_t cursorX = 0;
235
237 uint8_t cursorY = 0;
238
239
240private:
241
243 uint8_t buffer[ SSD1306_WIDTH * SSD1306_HEIGHT / 8 ] = { 0 };
244
248 void writeData( uint8_t* data, uint16_t dataSize );
249
252 void writeCommand( uint8_t c );
253
255 uint8_t address = 0;
256
257};
258
259
260#endif
Display driver object.
Definition: oled.hpp:156
void writeCharacter(uint8_t c)
Write a character to the display.
Definition: oled.cpp:292
uint8_t cursorX
X-coordinate of the cursor.
Definition: oled.hpp:234
void writeData(uint8_t *data, uint16_t dataSize)
Write data to the display.
Definition: oled.cpp:157
bool inverted
If this flag is set, the draw logic will be inverted.
Definition: oled.hpp:231
void displayOff()
Turn off the oled panel.
Definition: oled.cpp:210
void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
Print line to the display.
Definition: oled.cpp:385
bool begin()
Init function for the display.
Definition: oled.cpp:38
uint8_t buffer[SSD1306_WIDTH *SSD1306_HEIGHT/8]
Pixel buffer.
Definition: oled.hpp:243
void clearRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h)
Create a cleared rectangle.
Definition: oled.cpp:274
void clearPixel(uint8_t x, uint8_t y)
Clear a pixel by location.
Definition: oled.cpp:236
void displayOn()
Turn on the oled panel.
Definition: oled.cpp:204
uint8_t address
Address of the display.
Definition: oled.hpp:255
void update()
Update the content of the panel.
Definition: oled.cpp:141
void setPixel(uint8_t x, uint8_t y)
Set a pixel by location.
Definition: oled.cpp:216
uint8_t cursorY
Y-coordinate of the cursor.
Definition: oled.hpp:237
void clear()
Clear the display.
Definition: oled.cpp:134
void print(char *str)
Print a c-string tho the display.
Definition: oled.cpp:360
void writeCommand(uint8_t c)
Write command to the display.
Definition: oled.cpp:194
void fillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h)
Create a filled rectangle.
Definition: oled.cpp:256
#define SSD1306_HEIGHT
Height of the display module in pixels.
Definition: oled.hpp:41
const uint8_t ASCII[] PROGMEM
Font for the display.
Definition: oled.hpp:48
#define SSD1306_WIDTH
Width of the display module in pixels.
Definition: oled.hpp:38