Skip to content

Commit a96e507

Browse files
szczyssquix78
authored andcommitted
Added clearPixel(x,y) function (#247)
1 parent a563a25 commit a96e507

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/OLEDDisplay.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ void OLEDDisplay::setPixel(int16_t x, int16_t y) {
101101
}
102102
}
103103

104+
void OLEDDisplay::clearPixel(int16_t x, int16_t y) {
105+
if (x >= 0 && x < this->width() && y >= 0 && y < this->height()) {
106+
switch (color) {
107+
case BLACK: buffer[x + (y / 8) * this->width()] |= (1 << (y & 7)); break;
108+
case WHITE: buffer[x + (y / 8) * this->width()] &= ~(1 << (y & 7)); break;
109+
case INVERSE: buffer[x + (y / 8) * this->width()] ^= (1 << (y & 7)); break;
110+
}
111+
}
112+
}
113+
114+
104115
// Bresenham's algorithm - thx wikipedia and Adafruit_GFX
105116
void OLEDDisplay::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1) {
106117
int16_t steep = abs(y1 - y0) > abs(x1 - x0);

src/OLEDDisplay.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ class OLEDDisplay : public Print {
140140
// Draw a pixel at given position
141141
void setPixel(int16_t x, int16_t y);
142142

143+
// Clear a pixel at given position FIXME: INVERSE is untested with this function
144+
void clearPixel(int16_t x, int16_t y);
145+
143146
// Draw a line from position 0 to position 1
144147
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
145148

0 commit comments

Comments
 (0)