-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOLEDDisplay.h
106 lines (93 loc) · 2.46 KB
/
OLEDDisplay.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
/* IoTKit OLED Display Library
* Copyright (c) 2016 Marcel mc-b Bernet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include <stdarg.h>
#include "Adafruit_SSD1306.h"
#ifndef OLED_DISPLAY
#define OLED_DISPLAY
/** OLED Display
*
* Vereinfachte Version zur Ansteuerung eines Displays
* auf Basis von I2C und SSD1306 Interface
*
* Example:
* @code
* #include "mbed.h"
* #include "OLEDDisplay.h"
*
* DigitalOut led( D10 );
* OLEDDisplay oled;
*
* int main()
* {
* int i = 0;
* oled.clear();
* oled.printf( "Test\r\n" );
*
* while (true)
* {
* oled.cursor( 1, 0 );
* oled.printf( "ON %d, %d\n", led.read(), i );
* led = 1;
* wait( 1.0f );
*
* oled.cursor( 2, 0 );
* oled.printf( "OFF %d, %d\n", led.read(), i );
* led = 0;
* i++;
* wait( 1.0f );
* }
* }
* @endcode
*/
class OLEDDisplay
{
public:
OLEDDisplay( PinName rst = D9, PinName sca = D14, PinName scl = D15, uint8_t addr = 0x78 ) : i2c( sca, scl ), oled( i2c, rst, addr )
{
}
/** clear Display */
void clear()
{
oled.clearDisplay();
oled.setTextCursor( 0, 0 );
}
/** Set the display rotation, 1 = down, 2 = up, 3 = left, or 4 = right*/
void setRotation(uint8_t r)
{
oled.setRotation( r );
}
/** printf formatted with display */
void printf( const char *format, ... )
{
static char buffer[128];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
oled.printf( buffer );
oled.display();
}
/// Set the text cursor location, based on the size of the text
void cursor( int16_t y, int16_t x )
{
oled.setTextCursor( x * 6 , y * 8 );
}
private:
I2C i2c;
Adafruit_SSD1306_I2c oled;
};
#endif // OLED_DISPLAY