Dezibot 4
Loading...
Searching...
No Matches
Display.cpp
Go to the documentation of this file.
1
11#include "Display.h"
12#include "CharTable.h"
13#include "Wire.h"
14
15
16void Display::begin(void){
17 //set Mux Ratio
19 sendDisplayCMD(0x3f);
21 sendDisplayCMD(0x00);
24 /*which pixels are bright: normal = 1s are bright, inverese= 0s are bright*/
26
28 sendDisplayCMD(0x80);
29
31 sendDisplayCMD(0x14);
33 this->clear();
34 return;
35};
36
37void Display::sendDisplayCMD(uint8_t cmd){
38 Wire.beginTransmission(DisplayAdress);
39 Wire.write(cmd_byte);
40 Wire.write(cmd);
41 Wire.endTransmission();
42};
43
44void Display::clear(void){
46 sendDisplayCMD(0x00); //horizontal
48 sendDisplayCMD(0x00);
49 sendDisplayCMD(0x7f);
51 sendDisplayCMD(0x00);
52 sendDisplayCMD(0x07);
53 for (int j=0;j<64;j++){
54 Wire.beginTransmission(DisplayAdress);
55 Wire.write(data_byte);
56 for(int i = 0;i<16;i++){
57 Wire.write(0x00);
58 }
59 Wire.endTransmission();
60 }
61 this -> charsOnCurrLine = 0;
62 this -> currLine = 0;
63 return;
64};
65
66void Display::updateLine(uint charAmount)
67{
68 if(charAmount+this->charsOnCurrLine>16)
69 {
70 this->currLine = (this->currLine+((charAmount+this->charsOnCurrLine)/16))%8;
71 this->charsOnCurrLine = (charAmount+this->charsOnCurrLine)%17; //there can be 0-16 chars on one line, so the 17th char is on next line
72 }
73 else
74 {
75 this->charsOnCurrLine = charAmount+this->charsOnCurrLine;
76 }
77};
78
79void Display::print(char *value){
80 char *nextchar;
81 /* write data to the buffer */
82 while(value && *value != '\0') //check if pointer is still valid and string is not terminated
83 {
84 //check if next character is a linebreak
85 if(*value=='\n')
86 {
87 //fill the current line with blanks
88 while(this->charsOnCurrLine<16)
89 {
90 updateLine(1);
91 Wire.beginTransmission(DisplayAdress);
92 for(int i = 0;i<9;i++){
93 Wire.write(font8x8_colwise[0][i]);
94 }
95 Wire.endTransmission();
96 }
97 //make the linebreak
98 this->currLine=currLine+1;
99 this->charsOnCurrLine=0;
100 }
101 else
102 {
103 updateLine(1);
104 Wire.beginTransmission(DisplayAdress);
105 //print the character
106 for(int i = 0;i<9;i++){
107 Wire.write(font8x8_colwise[*value][i]);
108 }
109 Wire.endTransmission();
110 }
111 value++;
112 }
113};
114
115char Display::stringToCharArray(String value) {
116 const int len = value.length() + 1; // +1 for the null terminator
117 char msgBuffer[len]; // Create a buffer of the appropriate length
118
119 value.toCharArray(msgBuffer, len); // Copy the string into the buffer, including the null terminator
120
121 return *msgBuffer;
122}
123
124void Display::print(String value){
125 const int len = value.length() + 1; // +1 for the null terminator
126 char msgBuffer[len]; // Create a buffer of the appropriate length
127 value.toCharArray(msgBuffer, len);
128
129 this->print(msgBuffer);
130};
131
132void Display::println(String value){
133 const int len = value.length() + 1; // +1 for the null terminator
134 char msgBuffer[len]; // Create a buffer of the appropriate length
135 value.toCharArray(msgBuffer, len);
136
137 this->println(msgBuffer);
138};
139
140void Display::print(int value){
141 char cstr[16];
142
143 this->print(itoa(value, cstr, 10));
144};
145
146void Display::println(int value){
147 char cstr[16];
148
149 this->println(itoa(value, cstr, 10));
150};
151
152void Display::println(char *value){
153 this ->print(value);
154 this->print("\n");
155};
156
167
169 if(this->colorInverted){
171 } else {
173 }
174 this->colorInverted = !this->colorInverted;
175};
LookUpTable for 8x8 Pixel Characters for an SSD1306 Display.
const char font8x8_colwise[128][9]
First index specifies the index, where index equals the ascii encoding unprintable characters are enc...
Definition CharTable.h:20
#define setChargePump
Definition DisplayCMDs.h:17
#define setInverseMode
Definition DisplayCMDs.h:15
#define DisplayAdress
Definition DisplayCMDs.h:24
#define setStartLine
Definition DisplayCMDs.h:5
#define colRange
Definition DisplayCMDs.h:21
#define data_byte
Definition DisplayCMDs.h:2
#define setComDirectionFlipped
Definition DisplayCMDs.h:9
#define pageRange
Definition DisplayCMDs.h:22
#define stopCompleteOn
Definition DisplayCMDs.h:13
#define setSegmentReMap
Definition DisplayCMDs.h:7
#define setNormalMode
Definition DisplayCMDs.h:14
#define setSegmentMap
Definition DisplayCMDs.h:6
#define muxRatio
Definition DisplayCMDs.h:3
#define setOffset
Definition DisplayCMDs.h:4
#define activateDisplay
Definition DisplayCMDs.h:18
#define addressingMode
Definition DisplayCMDs.h:20
#define setComDirectionNormal
Definition DisplayCMDs.h:8
#define setOscFreq
Definition DisplayCMDs.h:16
#define cmd_byte
Definition DisplayCMDs.h:1
void sendDisplayCMD(uint8_t cmd)
sends the passed cmd to the display, cmd_byte is added as prefix by the function
Definition Display.cpp:37
bool colorInverted
Definition Display.h:30
void println(char *value)
same as the print method, but after the string a line break is inserted
Definition Display.cpp:152
bool orientationFlipped
Definition Display.h:27
uint8_t currLine
Definition Display.h:24
void flipOrientation(void)
flips the horizontal orientation of all content on the display
Definition Display.cpp:157
uint8_t charsOnCurrLine
Definition Display.h:21
void clear(void)
delets all content from the display, resets the linecounter, new print will start at the top left....
Definition Display.cpp:44
char stringToCharArray(String value)
string to char
Definition Display.cpp:115
void print(char *value)
prints the passed string right behind the current displaycontent the sequence "\n" can be used to mak...
Definition Display.cpp:79
void updateLine(uint charAmount)
should be called whenever characters where printed to the display. Updates the data of the class to h...
Definition Display.cpp:66
void invertColor(void)
inverts the pixelcolors, so pixels on will be set to off and currently off pixels will be turned off....
Definition Display.cpp:168
void begin(void)
initializes the display datastructures and sents the required cmds to start the display....
Definition Display.cpp:16