Last active
January 26, 2017 05:49
-
-
Save takashiski/be0b03f0bdc9daff2d683592c41ef66c to your computer and use it in GitHub Desktop.
OLED(128x32)にシリアルと同じような感じで文字列吐き出す(ArduinoUNO,I2Cで試した)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef OLEDDEBUGGER_H | |
#define OLEDDEBUGGER_H | |
#include<Adafruit_GFX.h> | |
#include<Adafruit_SSD1306.h> | |
class OLEDDebugger{ | |
public: | |
OLEDDebugger() | |
{ | |
display = new Adafruit_SSD1306(OLED_RESET); | |
}; | |
~OLEDDebugger() | |
{ | |
delete display; | |
}; | |
void begin(){display->begin(SSD1306_SWITCHCAPVCC,0x3c);}; | |
void print(String str) | |
{ | |
display->setTextSize(1); | |
display->setTextColor(WHITE); | |
display->setCursor(x,y); | |
display->println(str); | |
display->display(); | |
incrementPosition(str.length()); | |
}; | |
void println(String str) | |
{ | |
print(str); | |
CRLF(); | |
} | |
void incrementPosition(uint16_t len) | |
{ | |
x+=len*x_offset; | |
if(x>x_max)CRLF(); | |
} | |
void CRLF() | |
{ | |
y+=y_offset; | |
if(y>y_max){y=0;clear();} | |
x=0; | |
}; | |
void clear(){display->clearDisplay();}; | |
void setPosition(uint8_t x, uint8_t y) | |
{ | |
this->x=x; | |
this->y=y; | |
}; | |
private: | |
uint8_t x=0; | |
uint8_t y=0; | |
const uint8_t x_max = 114; | |
const uint8_t y_max = 31; | |
const uint8_t x_offset = 6; | |
const uint8_t y_offset = 8; | |
const int8_t OLED_RESET = 4; | |
Adafruit_SSD1306 *display = NULL; | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment