Skip to content
Snippets Groups Projects
Commit fc484730 authored by Daniel Eichhorn's avatar Daniel Eichhorn
Browse files

Initial import

parent a04a9d0d
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
#include <ArduinoJson.h>
/**The MIT License (MIT)
Copyright (c) 2015 by Daniel Eichhorn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
See more at http://blog.squix.ch
*/
#include <Wire.h>
#include "ssd1306_i2c.h"
#include "images.h"
// if you are using a ESP8266 module with NodeMCU
// pin labels, you can use this list to keep
// your code and the lables in-sync
#define NODEMCU_D0 16
#define NODEMCU_D1 5
#define NODEMCU_D2 4
#define NODEMCU_D3 0
#define NODEMCU_D4 2
#define NODEMCU_D5 14
#define NODEMCU_D6 12
#define NODEMCU_D7 13
#define NODEMCU_D8 15
#define NODEMCU_D9 3
#define NODEMCU_D10 1
#define NODEMCU_D12 10
// Initialize the oled display for address 0x3c
// sda-pin=14 and sdc-pin=12
SSD1306 display(0x3c, NODEMCU_D6, NODEMCU_D5);
// this array keeps function pointers to all frames
// frames are the single views that slide from right to left
void (*frameCallbacks[])(int x, int y) = {drawFrame1, drawFrame2, drawFrame3, drawFrame4};
// how many frames are there?
int frameCount = 4;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
// initialize dispaly
display.init();
display.flipScreenVertically();
// set the drawing functions
display.setFrameCallbacks(frameCount, frameCallbacks);
// how many ticks does a slide of a frame take?
display.setFrameTransitionTicks(10);
// defines how many ticks the driver waits between frame transitions
display.setFrameWaitTicks(150);
display.clear();
display.display();
}
void loop() {
if (display.getFrameState() == display.FRAME_STATE_FIX) {
// do something which consumes a lot of time in a moment
// when there is no transition between frames going on.
// This will keep transitions smooth;
}
// clear the frame
display.clear();
// Tell the driver to render the next frame.
// This enables the frame mode including the transition
// and the drawing of the frame indicators
display.nextFrameTick();
// Even in frame mode you can draw static elements.
// But they won't be transitioned
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 54, "20:54");
// copy the buffer to the display
display.display();
}
void drawFrame1(int x, int y) {
// draw an xbm image.
// Please note that everything that should be transitioned
// needs to be drawn relative to x and y
display.drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
}
void drawFrame2(int x, int y) {
// Demonstrates the 3 included default sizes. The fonts come from SSD1306Fonts.h file
// Besides the default fonts there will be a program to convert TrueType fonts into this format
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0 + x, 0 + y, "Arial 10");
display.setFont(ArialMT_Plain_16);
display.drawString(0 + x, 10 + y, "Arial 16");
display.setFont(ArialMT_Plain_24);
display.drawString(0 + x, 24 + y, "Arial 24");
}
void drawFrame3(int x, int y) {
// Text alignment demo
display.setFont(ArialMT_Plain_10);
// The coordinates define the left starting point of the text
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0 + x, 0 + y, "Left aligned (0,0)");
// The coordinates define the center of the text
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64 + x, 20, "Center aligned (64,20)");
// The coordinates define the right end of the text
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128 + x, 40, "Right aligned (128,40)");
}
void drawFrame4(int x, int y) {
// Demo for drawStringMaxWidth:
// with the third parameter you can define the width after which words will be wrapped.
// Currently only spaces and "-" are allowed for wrapping
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawStringMaxWidth(0 + x, 0 + y, 128, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore.");
}
#define WiFi_Logo_width 60
#define WiFi_Logo_height 36
const char WiFi_Logo_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
name=ESP8266 Oled Driver for SSD1306 display
version=1.0.0
author=Daniel Eichhorn
maintainer=Daniel Eichhorn <squix78@gmail.com>
sentence=A display driver for SSD1306 oled displays connected to an ESP8266
paragraph=A display driver for SSD1306 oled displays connected to an ESP8266
category=Display
url=https://github.com/squix78/esp8266-oled-ssd1306
architectures=esp8266
/**The MIT License (MIT)
Copyright (c) 2015 by Daniel Eichhorn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
See more at http://blog.squix.ch
Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
*/
#include "ssd1306_i2c.h"
#include <Wire.h>
SSD1306::SSD1306(int i2cAddress, int sda, int sdc)
{
myI2cAddress = i2cAddress;
mySda = sda;
mySdc = sdc;
}
void SSD1306::init() {
Wire.begin(mySda, mySdc);
Wire.setClock(400000);
sendInitCommands();
resetDisplay();
}
void SSD1306::resetDisplay(void)
{
displayOff();
clear();
display();
displayOn();
}
void SSD1306::reconnect() {
Wire.begin(mySda, mySdc);
}
void SSD1306::displayOn(void)
{
sendCommand(0xaf); //display on
}
void SSD1306::displayOff(void)
{
sendCommand(0xae); //display off
}
void SSD1306::setContrast(char contrast) {
sendCommand(0x81);
sendCommand(contrast);
}
void SSD1306::flipScreenVertically() {
sendCommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg
sendCommand(0xC8); //COMSCANDEC Rotate screen 180 Deg
}
void SSD1306::clear(void) {
memset(buffer, 0, (128*64 / 8));
}
void SSD1306::display(void) {
for (uint16_t i=0; i<(128*64/8); i++) {
// send a bunch of data in one xmission
//Wire.begin(mySda, mySdc);
Wire.beginTransmission(myI2cAddress);
Wire.write(0x40);
for (uint8_t x=0; x<16; x++) {
Wire.write(buffer[i]);
i++;
}
i--;
yield();
Wire.endTransmission();
}
}
void SSD1306::setPixel(int x, int y) {
if (x >= 0 && x < 128 && y >= 0 && y < 64) {
switch (myColor) {
case WHITE: buffer[x+ (y/8)*128] |= (1 << (y&7)); break;
case BLACK: buffer[x+ (y/8)*128] &= ~(1 << (y&7)); break;
case INVERSE: buffer[x+ (y/8)*128] ^= (1 << (y&7)); break;
}
}
}
void SSD1306::setChar(int x, int y, unsigned char data) {
for (int i = 0; i < 8; i++) {
if (bitRead(data, i)) {
setPixel(x,y + i);
}
}
}
void SSD1306::drawString(int x, int y, String text) {
unsigned char currentByte;
int charX, charY;
int currentBitCount;
int charCode;
int currentCharWidth;
int currentCharStartPos;
int cursorX = 0;
int numberOfChars = pgm_read_byte(myFontData + CHAR_NUM_POS);
// iterate over string
int firstChar = pgm_read_byte(myFontData + FIRST_CHAR_POS);
int charHeight = pgm_read_byte(myFontData + HEIGHT_POS);
int currentCharByteNum = 0;
int startX = 0;
int startY = y;
if (myTextAlignment == TEXT_ALIGN_LEFT) {
startX = x;
} else if (myTextAlignment == TEXT_ALIGN_CENTER) {
int width = getStringWidth(text);
startX = x - width / 2;
} else if (myTextAlignment == TEXT_ALIGN_RIGHT) {
int width = getStringWidth(text);
startX = x - width;
}
for (int j=0; j < text.length(); j++) {
charCode = text.charAt(j)-0x20;
currentCharWidth = pgm_read_byte(myFontData + CHAR_WIDTH_START_POS + charCode);
// Jump to font data beginning
currentCharStartPos = CHAR_WIDTH_START_POS + numberOfChars;
for (int m = 0; m < charCode; m++) {
currentCharStartPos += pgm_read_byte(myFontData + CHAR_WIDTH_START_POS + m) * charHeight / 8 + 1;
}
currentCharByteNum = ((charHeight * currentCharWidth) / 8) + 1;
// iterate over all bytes of character
for (int i = 0; i < currentCharByteNum; i++) {
currentByte = pgm_read_byte(myFontData + currentCharStartPos + i);
//Serial.println(String(charCode) + ", " + String(currentCharWidth) + ", " + String(currentByte));
// iterate over all bytes of character
for(int bit = 0; bit < 8; bit++) {
//int currentBit = bitRead(currentByte, bit);
currentBitCount = i * 8 + bit;
charX = currentBitCount % currentCharWidth;
charY = currentBitCount / currentCharWidth;
if (bitRead(currentByte, bit)) {
//Serial.println(String(charX) + ", " + String(charY));
setPixel(startX + cursorX + charX, startY + charY);
//setPixel(charX, charY);
}
}
yield();
}
cursorX += currentCharWidth;
}
}
void SSD1306::drawStringMaxWidth(int x, int y, int maxLineWidth, String text) {
int currentLineWidth = 0;
int startsAt = 0;
int endsAt = 0;
int lineNumber = 0;
char currentChar = ' ';
int lineHeight = pgm_read_byte(myFontData + HEIGHT_POS);
String currentLine = "";
for (int i = 0; i < text.length(); i++) {
currentChar = text.charAt(i);
if (currentChar == ' ' || currentChar == '-') {
String lineCandidate = text.substring(startsAt, i);
if (getStringWidth(lineCandidate) <= maxLineWidth) {
endsAt = i;
} else {
drawString(x, y + lineNumber * lineHeight, text.substring(startsAt, endsAt));
lineNumber++;
startsAt = endsAt + 1;
}
}
}
drawString(x, y + lineNumber * lineHeight, text.substring(startsAt));
}
int SSD1306::getStringWidth(String text) {
int stringWidth = 0;
char charCode;
for (int j=0; j < text.length(); j++) {
charCode = text.charAt(j)-0x20;
stringWidth += pgm_read_byte(myFontData + CHAR_WIDTH_START_POS + charCode);
}
return stringWidth;
}
void SSD1306::setTextAlignment(int textAlignment) {
myTextAlignment = textAlignment;
}
void SSD1306::setFont(const char *fontData) {
myFontData = fontData;
}
void SSD1306::drawBitmap(int x, int y, int width, int height, const char *bitmap) {
for (int i = 0; i < width * height / 8; i++ ){
unsigned char charColumn = 255 - pgm_read_byte(bitmap + i);
for (int j = 0; j < 8; j++) {
int targetX = i % width + x;
int targetY = (i / (width)) * 8 + j + y;
if (bitRead(charColumn, j)) {
setPixel(targetX, targetY);
}
}
}
}
void SSD1306::setColor(int color) {
myColor = color;
}
void SSD1306::drawRect(int x, int y, int width, int height) {
for (int i = x; i < x + width; i++) {
setPixel(i, y);
setPixel(i, y + height);
}
for (int i = y; i < y + height; i++) {
setPixel(x, i);
setPixel(x + width, i);
}
}
void SSD1306::fillRect(int x, int y, int width, int height) {
for (int i = x; i < x + width; i++) {
for (int j = 0; j < y + height; j++) {
setPixel(i, j);
}
}
}
void SSD1306::drawXbm(int x, int y, int width, int height, const char *xbm) {
if (width % 8 != 0) {
width = ((width / 8) + 1) * 8;
}
for (int i = 0; i < width * height / 8; i++ ){
unsigned char charColumn = pgm_read_byte(xbm + i);
for (int j = 0; j < 8; j++) {
int targetX = (i * 8 + j) % width + x;
int targetY = (8 * i / (width)) + y;
if (bitRead(charColumn, j)) {
setPixel(targetX, targetY);
}
}
}
}
void SSD1306::sendCommand(unsigned char com)
{
//Wire.begin(mySda, mySdc);
Wire.beginTransmission(myI2cAddress); //begin transmitting
Wire.write(0x80); //command mode
Wire.write(com);
Wire.endTransmission(); // stop transmitting
}
void SSD1306::sendInitCommands(void)
{
// Init sequence from https://github.com/adafruit/Adafruit_SSD1306/blob/master/Adafruit_SSD1306.cpp
sendCommand(0xae); //display off
sendCommand(0xa6); //Set Normal Display (default)
// Init sequence for 128x64 OLED module
sendCommand(0xAE); //DISPLAYOFF
sendCommand(0xD5); //SETDISPLAYCLOCKDIV
sendCommand(0x80); // the suggested ratio 0x80
sendCommand(0xA8); //SSD1306_SETMULTIPLEX
sendCommand(0x3F);
sendCommand(0xD3); //SETDISPLAYOFFSET
sendCommand(0x0); //no offset
sendCommand(0x40 | 0x0); //SETSTARTLINE
sendCommand(0x8D); //CHARGEPUMP
sendCommand(0x14);
sendCommand(0x20); //MEMORYMODE
sendCommand(0x00); //0x0 act like ks0108
//sendCommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg
sendCommand(0xA0);
//sendCommand(0xC8); //COMSCANDEC Rotate screen 180 Deg
sendCommand(0xC0);
sendCommand(0xDA); //0xDA
sendCommand(0x12); //COMSCANDEC
sendCommand(0x81); //SETCONTRAS
sendCommand(0xCF); //
sendCommand(0xd9); //SETPRECHARGE
sendCommand(0xF1);
sendCommand(0xDB); //SETVCOMDETECT
sendCommand(0x40);
sendCommand(0xA4); //DISPLAYALLON_RESUME
sendCommand(0xA6); //NORMALDISPLAY
sendCommand(0x2e); // stop scroll
//----------------------------REVERSE comments----------------------------//
// sendCommand(0xa0); //seg re-map 0->127(default)
// sendCommand(0xa1); //seg re-map 127->0
// sendCommand(0xc8);
// delay(1000);
//----------------------------REVERSE comments----------------------------//
// sendCommand(0xa7); //Set Inverse Display
// sendCommand(0xae); //display off
sendCommand(0x20); //Set Memory Addressing Mode
sendCommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode
//sendCommand(0x02); // Set Memory Addressing Mode ab Page addressing mode(RESET)
}
void SSD1306::nextFrameTick() {
myFrameTick++;
if (myFrameTick==myFrameWaitTicks && myFrameState == 0 || myFrameTick==myFrameTransitionTicks && myFrameState == 1) {
myFrameState = (myFrameState + 1) % 2;
if (myFrameState==FRAME_STATE_FIX) {
myCurrentFrame = (myCurrentFrame + 1) % myFrameCount;
}
myFrameTick = 0;
}
drawIndicators(myFrameCount, myCurrentFrame);
switch(myFrameState) {
case 0:
(*myFrameCallbacks[myCurrentFrame])(0, 0);
break;
case 1:
(*myFrameCallbacks[myCurrentFrame])(-128 * myFrameTick / myFrameTransitionTicks, 0);
(*myFrameCallbacks[(myCurrentFrame + 1) % myFrameCount])(-128 * myFrameTick / myFrameTransitionTicks + 128, 0);
break;
}
}
void SSD1306::drawIndicators(int frameCount, int activeFrame) {
for (int i = 0; i < frameCount; i++) {
const char *xbm;
if (activeFrame == i) {
xbm = active_bits;
} else {
xbm = inactive_bits;
}
drawXbm(64 - (12 * frameCount / 2) + 12 * i,56, 8, 8, xbm);
}
}
void SSD1306::setFrameCallbacks(int frameCount, void (*frameCallbacks[])(int x, int y)) {
myFrameCount = frameCount;
myFrameCallbacks = frameCallbacks;
}
void SSD1306::setFrameWaitTicks(int frameWaitTicks) {
myFrameWaitTicks = frameWaitTicks;
}
void SSD1306::setFrameTransitionTicks(int frameTransitionTicks) {
myFrameTransitionTicks = frameTransitionTicks;
}
int SSD1306::getFrameState() {
return myFrameState;
}
/**The MIT License (MIT)
Copyright (c) 2015 by Daniel Eichhorn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
See more at http://blog.squix.ch
Credits for parts of this code go to Mike Rankin. Thank you so much for sharing!
*/
#pragma once
#include <Arduino.h>
#include "SSD1306Fonts.h"
#define active_width 8
#define active_height 8
const char active_bits[] PROGMEM = {
0x00, 0x18, 0x3c, 0x7e, 0x7e, 0x3c, 0x18, 0x00 };
#define inactive_width 8
#define inactive_height 8
const char inactive_bits[] PROGMEM = {
0x00, 0x0, 0x0, 0x18, 0x18, 0x0, 0x0, 0x00 };
#define BLACK 0
#define WHITE 1
#define INVERSE 2
#define WIDTH_POS 0
#define HEIGHT_POS 1
#define FIRST_CHAR_POS 2
#define CHAR_NUM_POS 3
#define CHAR_WIDTH_START_POS 4
#define TEXT_ALIGN_LEFT 0
#define TEXT_ALIGN_CENTER 1
#define TEXT_ALIGN_RIGHT 2
class SSD1306 {
private:
int myI2cAddress;
int mySda;
int mySdc;
uint8_t buffer[128 * 64 / 8];
int myFrameState = 0;
int myFrameTick = 0;
int myCurrentFrame = 0;
int myFrameCount = 0;
int myFrameWaitTicks = 100;
int myFrameTransitionTicks = 25;
int myTextAlignment = TEXT_ALIGN_LEFT;
int myColor = WHITE;
const char *myFontData = ArialMT_Plain_10;
void (**myFrameCallbacks)(int x, int y);
public:
// Empty constructor
SSD1306(int i2cAddress, int sda, int sdc);
void init();
void resetDisplay(void);
void reconnect(void);
void displayOn(void);
void displayOff(void);
void clear(void);
void display(void);
void setPixel(int x, int y);
void setChar(int x, int y, unsigned char data);
void drawString(int x, int y, String text);
void drawStringMaxWidth(int x, int y, int maxLineWidth, String text);
int getStringWidth(String text);
void setTextAlignment(int textAlignment);
void setFont(const char *fontData);
void drawBitmap(int x, int y, int width, int height, const char *bitmap);
void drawXbm(int x, int y, int width, int height, const char *xbm);
void sendCommand(unsigned char com);
void sendInitCommands(void);
void setColor(int color);
void drawRect(int x, int y, int width, int height);
void fillRect(int x, int y, int width, int height);
void setContrast(char contrast);
void flipScreenVertically();
void setFrameCallbacks(int frameCount, void (*frameCallbacks[])(int x, int y));
void nextFrameTick(void);
void drawIndicators(int frameCount, int activeFrame);
void setFrameWaitTicks(int frameWaitTicks);
void setFrameTransitionTicks(int frameTransitionTicks);
int getFrameState();
const int FRAME_STATE_FIX = 0;
const int FRAME_STATE_TRANSITION = 1;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment