Added Adafruit_SSD1306 and OLED_I2C libs ported by @Madias
This commit is contained in:
parent
e069959d3e
commit
da54c87173
|
@ -0,0 +1,777 @@
|
|||
/*********************************************************************
|
||||
This is a library for our Monochrome OLEDs based on SSD1306 drivers
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/category/63_98
|
||||
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen below must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
//#ifndef __SAM3X8E__ || __STM32F1__
|
||||
//#include <util/delay.h>
|
||||
//#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
//#include <HWIRE.h>
|
||||
#include <HardWire.h>
|
||||
//HardWire HWIRE(1,I2C_FAST_MODE); // I2c1
|
||||
HardWire HWIRE(2,I2C_FAST_MODE); // I2c2
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_SSD1306_STM32.h"
|
||||
|
||||
// the memory buffer for the LCD
|
||||
|
||||
static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
|
||||
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF,
|
||||
#if (SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH > 96*16)
|
||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
|
||||
0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8,
|
||||
0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80,
|
||||
0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01,
|
||||
0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF,
|
||||
0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00,
|
||||
0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF,
|
||||
0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF,
|
||||
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F,
|
||||
0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC,
|
||||
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03,
|
||||
0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01,
|
||||
0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00,
|
||||
0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03,
|
||||
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
#if (SSD1306_LCDHEIGHT == 64)
|
||||
0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F,
|
||||
0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F,
|
||||
0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00,
|
||||
0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E,
|
||||
0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC,
|
||||
0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06,
|
||||
0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8,
|
||||
0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
|
||||
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C,
|
||||
0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F,
|
||||
0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00,
|
||||
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07,
|
||||
0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
// the most basic function, set a single pixel
|
||||
void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
|
||||
return;
|
||||
|
||||
// check rotation, move pixel around if necessary
|
||||
switch (getRotation()) {
|
||||
case 1:
|
||||
swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// x is which column
|
||||
switch (color)
|
||||
{
|
||||
case WHITE: buffer[x+ (y/8)*SSD1306_LCDWIDTH] |= (1 << (y&7)); break;
|
||||
case BLACK: buffer[x+ (y/8)*SSD1306_LCDWIDTH] &= ~(1 << (y&7)); break;
|
||||
case INVERSE: buffer[x+ (y/8)*SSD1306_LCDWIDTH] ^= (1 << (y&7)); break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) {
|
||||
cs = CS;
|
||||
rst = RST;
|
||||
dc = DC;
|
||||
sclk = SCLK;
|
||||
sid = SID;
|
||||
hwSPI = false;
|
||||
}
|
||||
|
||||
// constructor for hardware SPI - we indicate DataCommand, ChipSelect, Reset
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS) : Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) {
|
||||
dc = DC;
|
||||
rst = RST;
|
||||
cs = CS;
|
||||
hwSPI = true;
|
||||
}
|
||||
|
||||
// initializer for I2C - we only indicate the reset pin!
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(int8_t reset) :
|
||||
Adafruit_GFX(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT) {
|
||||
sclk = dc = cs = sid = -1;
|
||||
rst = reset;
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_SSD1306::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
|
||||
_vccstate = vccstate;
|
||||
_i2caddr = i2caddr;
|
||||
|
||||
// set pin directions
|
||||
if (sid != -1){
|
||||
pinMode(dc, OUTPUT);
|
||||
pinMode(cs, OUTPUT);
|
||||
csport = portOutputRegister(digitalPinToPort(cs));
|
||||
cspinmask = digitalPinToBitMask(cs);
|
||||
dcport = portOutputRegister(digitalPinToPort(dc));
|
||||
dcpinmask = digitalPinToBitMask(dc);
|
||||
if (!hwSPI){
|
||||
// set pins for software-SPI
|
||||
pinMode(sid, OUTPUT);
|
||||
pinMode(sclk, OUTPUT);
|
||||
clkport = portOutputRegister(digitalPinToPort(sclk));
|
||||
clkpinmask = digitalPinToBitMask(sclk);
|
||||
mosiport = portOutputRegister(digitalPinToPort(sid));
|
||||
mosipinmask = digitalPinToBitMask(sid);
|
||||
}
|
||||
if (hwSPI){
|
||||
SPI.begin ();
|
||||
//#ifdef __SAM3X8E__
|
||||
SPI.setClockDivider (9); // 9.3 MHz
|
||||
//#else
|
||||
// SPI.setClockDivider (SPI_CLOCK_DIV2); // 8 MHz
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C Init
|
||||
HWIRE.begin();
|
||||
|
||||
#ifdef __SAM3X8E__
|
||||
// Force 400 KHz I2C, rawr! (Uses pins 20, 21 for SDA, SCL)
|
||||
TWI1->TWI_CWGR = 0;
|
||||
TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (reset) {
|
||||
// Setup reset pin direction (used by both SPI and I2C)
|
||||
pinMode(rst, OUTPUT);
|
||||
digitalWrite(rst, HIGH);
|
||||
// VDD (3.3V) goes high at start, lets just chill for a ms
|
||||
delay(1);
|
||||
// bring reset low
|
||||
digitalWrite(rst, LOW);
|
||||
// wait 10ms
|
||||
delay(10);
|
||||
// bring out of reset
|
||||
digitalWrite(rst, HIGH);
|
||||
// turn on VCC (9V?)
|
||||
}
|
||||
|
||||
#if defined SSD1306_128_32
|
||||
// Init sequence for 128x32 OLED module
|
||||
ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
|
||||
ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
|
||||
ssd1306_command(0x80); // the suggested ratio 0x80
|
||||
ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
|
||||
ssd1306_command(0x1F);
|
||||
ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
|
||||
ssd1306_command(0x0); // no offset
|
||||
ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0
|
||||
ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x10); }
|
||||
else
|
||||
{ ssd1306_command(0x14); }
|
||||
ssd1306_command(SSD1306_MEMORYMODE); // 0x20
|
||||
ssd1306_command(0x00); // 0x0 act like ks0108
|
||||
ssd1306_command(SSD1306_SEGREMAP | 0x1);
|
||||
ssd1306_command(SSD1306_COMSCANDEC);
|
||||
ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
|
||||
ssd1306_command(0x02);
|
||||
ssd1306_command(SSD1306_SETCONTRAST); // 0x81
|
||||
ssd1306_command(0x8F);
|
||||
ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x22); }
|
||||
else
|
||||
{ ssd1306_command(0xF1); }
|
||||
ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
|
||||
ssd1306_command(0x40);
|
||||
ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
|
||||
ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
|
||||
#endif
|
||||
|
||||
#if defined SSD1306_128_64
|
||||
// Init sequence for 128x64 OLED module
|
||||
ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
|
||||
ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
|
||||
ssd1306_command(0x80); // the suggested ratio 0x80
|
||||
ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
|
||||
ssd1306_command(0x3F);
|
||||
ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
|
||||
ssd1306_command(0x0); // no offset
|
||||
ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0
|
||||
ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x10); }
|
||||
else
|
||||
{ ssd1306_command(0x14); }
|
||||
ssd1306_command(SSD1306_MEMORYMODE); // 0x20
|
||||
ssd1306_command(0x00); // 0x0 act like ks0108
|
||||
ssd1306_command(SSD1306_SEGREMAP | 0x1);
|
||||
ssd1306_command(SSD1306_COMSCANDEC);
|
||||
ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
|
||||
ssd1306_command(0x12);
|
||||
ssd1306_command(SSD1306_SETCONTRAST); // 0x81
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x9F); }
|
||||
else
|
||||
{ ssd1306_command(0xCF); }
|
||||
ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x22); }
|
||||
else
|
||||
{ ssd1306_command(0xF1); }
|
||||
ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
|
||||
ssd1306_command(0x40);
|
||||
ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
|
||||
ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
|
||||
#endif
|
||||
|
||||
#if defined SSD1306_96_16
|
||||
// Init sequence for 96x16 OLED module
|
||||
ssd1306_command(SSD1306_DISPLAYOFF); // 0xAE
|
||||
ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
|
||||
ssd1306_command(0x80); // the suggested ratio 0x80
|
||||
ssd1306_command(SSD1306_SETMULTIPLEX); // 0xA8
|
||||
ssd1306_command(0x0F);
|
||||
ssd1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3
|
||||
ssd1306_command(0x00); // no offset
|
||||
ssd1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0
|
||||
ssd1306_command(SSD1306_CHARGEPUMP); // 0x8D
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x10); }
|
||||
else
|
||||
{ ssd1306_command(0x14); }
|
||||
ssd1306_command(SSD1306_MEMORYMODE); // 0x20
|
||||
ssd1306_command(0x00); // 0x0 act like ks0108
|
||||
ssd1306_command(SSD1306_SEGREMAP | 0x1);
|
||||
ssd1306_command(SSD1306_COMSCANDEC);
|
||||
ssd1306_command(SSD1306_SETCOMPINS); // 0xDA
|
||||
ssd1306_command(0x2); //ada x12
|
||||
ssd1306_command(SSD1306_SETCONTRAST); // 0x81
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x10); }
|
||||
else
|
||||
{ ssd1306_command(0xAF); }
|
||||
ssd1306_command(SSD1306_SETPRECHARGE); // 0xd9
|
||||
if (vccstate == SSD1306_EXTERNALVCC)
|
||||
{ ssd1306_command(0x22); }
|
||||
else
|
||||
{ ssd1306_command(0xF1); }
|
||||
ssd1306_command(SSD1306_SETVCOMDETECT); // 0xDB
|
||||
ssd1306_command(0x40);
|
||||
ssd1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4
|
||||
ssd1306_command(SSD1306_NORMALDISPLAY); // 0xA6
|
||||
#endif
|
||||
|
||||
ssd1306_command(SSD1306_DISPLAYON);//--turn on oled panel
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_SSD1306::invertDisplay(uint8_t i) {
|
||||
if (i) {
|
||||
ssd1306_command(SSD1306_INVERTDISPLAY);
|
||||
} else {
|
||||
ssd1306_command(SSD1306_NORMALDISPLAY);
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
|
||||
if (sid != -1)
|
||||
{
|
||||
// SPI
|
||||
//digitalWrite(cs, HIGH);
|
||||
*csport |= cspinmask;
|
||||
//digitalWrite(dc, LOW);
|
||||
*dcport &= ~dcpinmask;
|
||||
//digitalWrite(cs, LOW);
|
||||
*csport &= ~cspinmask;
|
||||
fastSPIwrite(c);
|
||||
//digitalWrite(cs, HIGH);
|
||||
*csport |= cspinmask;
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C
|
||||
uint8_t control = 0x00; // Co = 0, D/C = 0
|
||||
HWIRE.beginTransmission(_i2caddr);
|
||||
WIRE_WRITE(control);
|
||||
WIRE_WRITE(c);
|
||||
HWIRE.endTransmission();
|
||||
}
|
||||
}
|
||||
|
||||
// startscrollright
|
||||
// Activate a right handed scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrollright(uint8_t start, uint8_t stop){
|
||||
ssd1306_command(SSD1306_RIGHT_HORIZONTAL_SCROLL);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(start);
|
||||
ssd1306_command(0X0F);
|
||||
ssd1306_command(stop);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(0XFF);
|
||||
ssd1306_command(SSD1306_ACTIVATE_SCROLL);
|
||||
}
|
||||
|
||||
// startscrollleft
|
||||
// Activate a right handed scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrollleft(uint8_t start, uint8_t stop){
|
||||
ssd1306_command(SSD1306_LEFT_HORIZONTAL_SCROLL);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(start);
|
||||
ssd1306_command(7);
|
||||
ssd1306_command(stop);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(0XFF);
|
||||
ssd1306_command(SSD1306_ACTIVATE_SCROLL);
|
||||
}
|
||||
|
||||
// startscrolldiagright
|
||||
// Activate a diagonal scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrolldiagright(uint8_t start, uint8_t stop){
|
||||
ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(SSD1306_LCDHEIGHT);
|
||||
ssd1306_command(SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(start);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(stop);
|
||||
ssd1306_command(0X01);
|
||||
ssd1306_command(SSD1306_ACTIVATE_SCROLL);
|
||||
}
|
||||
|
||||
// startscrolldiagleft
|
||||
// Activate a diagonal scroll for rows start through stop
|
||||
// Hint, the display is 16 rows tall. To scroll the whole display, run:
|
||||
// display.scrollright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrolldiagleft(uint8_t start, uint8_t stop){
|
||||
ssd1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(SSD1306_LCDHEIGHT);
|
||||
ssd1306_command(SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(start);
|
||||
ssd1306_command(0X00);
|
||||
ssd1306_command(stop);
|
||||
ssd1306_command(0X01);
|
||||
ssd1306_command(SSD1306_ACTIVATE_SCROLL);
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::stopscroll(void){
|
||||
ssd1306_command(SSD1306_DEACTIVATE_SCROLL);
|
||||
}
|
||||
|
||||
// Dim the display
|
||||
// dim = true: display is dimmed
|
||||
// dim = false: display is normal
|
||||
void Adafruit_SSD1306::dim(boolean dim) {
|
||||
uint8_t contrast;
|
||||
|
||||
if (dim) {
|
||||
contrast = 0; // Dimmed display
|
||||
} else {
|
||||
if (_vccstate == SSD1306_EXTERNALVCC) {
|
||||
contrast = 0x9F;
|
||||
} else {
|
||||
contrast = 0xCF;
|
||||
}
|
||||
}
|
||||
// the range of contrast to too small to be really useful
|
||||
// it is useful to dim the display
|
||||
ssd1306_command(SSD1306_SETCONTRAST);
|
||||
ssd1306_command(contrast);
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::ssd1306_data(uint8_t c) {
|
||||
if (sid != -1)
|
||||
{
|
||||
// SPI
|
||||
//digitalWrite(cs, HIGH);
|
||||
*csport |= cspinmask;
|
||||
//digitalWrite(dc, HIGH);
|
||||
*dcport |= dcpinmask;
|
||||
//digitalWrite(cs, LOW);
|
||||
*csport &= ~cspinmask;
|
||||
fastSPIwrite(c);
|
||||
//digitalWrite(cs, HIGH);
|
||||
*csport |= cspinmask;
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C
|
||||
uint8_t control = 0x40; // Co = 0, D/C = 1
|
||||
HWIRE.beginTransmission(_i2caddr);
|
||||
WIRE_WRITE(control);
|
||||
WIRE_WRITE(c);
|
||||
HWIRE.endTransmission();
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::display(void) {
|
||||
ssd1306_command(SSD1306_COLUMNADDR);
|
||||
ssd1306_command(0); // Column start address (0 = reset)
|
||||
ssd1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)
|
||||
|
||||
ssd1306_command(SSD1306_PAGEADDR);
|
||||
ssd1306_command(0); // Page start address (0 = reset)
|
||||
#if SSD1306_LCDHEIGHT == 64
|
||||
ssd1306_command(7); // Page end address
|
||||
#endif
|
||||
#if SSD1306_LCDHEIGHT == 32
|
||||
ssd1306_command(3); // Page end address
|
||||
#endif
|
||||
#if SSD1306_LCDHEIGHT == 16
|
||||
ssd1306_command(1); // Page end address
|
||||
#endif
|
||||
|
||||
if (sid != -1)
|
||||
{
|
||||
// SPI
|
||||
*csport |= cspinmask;
|
||||
*dcport |= dcpinmask;
|
||||
*csport &= ~cspinmask;
|
||||
|
||||
for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
|
||||
fastSPIwrite(buffer[i]);
|
||||
//ssd1306_data(buffer[i]);
|
||||
}
|
||||
*csport |= cspinmask;
|
||||
}
|
||||
else
|
||||
{
|
||||
// save I2C bitrate
|
||||
/*
|
||||
#ifndef __SAM3X8E__
|
||||
uint8_t twbrbackup = TWBR;
|
||||
TWBR = 12; // upgrade to 400KHz!
|
||||
#endif
|
||||
*/
|
||||
//Serial.println(TWBR, DEC);
|
||||
//Serial.println(TWSR & 0x3, DEC);
|
||||
|
||||
// I2C
|
||||
for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
|
||||
// send a bunch of data in one xmission
|
||||
HWIRE.beginTransmission(_i2caddr);
|
||||
WIRE_WRITE(0x40);
|
||||
for (uint8_t x=0; x<16; x++) {
|
||||
WIRE_WRITE(buffer[i]);
|
||||
i++;
|
||||
}
|
||||
i--;
|
||||
HWIRE.endTransmission();
|
||||
}
|
||||
/*
|
||||
#ifndef __SAM3X8E__
|
||||
TWBR = twbrbackup;
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// clear everything
|
||||
void Adafruit_SSD1306::clearDisplay(void) {
|
||||
memset(buffer, 0, (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8));
|
||||
}
|
||||
|
||||
|
||||
inline void Adafruit_SSD1306::fastSPIwrite(uint8_t d) {
|
||||
|
||||
if(hwSPI) {
|
||||
(void)SPI.transfer(d);
|
||||
} else {
|
||||
for(uint8_t bit = 0x80; bit; bit >>= 1) {
|
||||
*clkport &= ~clkpinmask;
|
||||
if(d & bit) *mosiport |= mosipinmask;
|
||||
else *mosiport &= ~mosipinmask;
|
||||
*clkport |= clkpinmask;
|
||||
}
|
||||
}
|
||||
//*csport |= cspinmask;
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
|
||||
boolean bSwap = false;
|
||||
switch(rotation) {
|
||||
case 0:
|
||||
// 0 degree rotation, do nothing
|
||||
break;
|
||||
case 1:
|
||||
// 90 degree rotation, swap x & y for rotation, then invert x
|
||||
bSwap = true;
|
||||
swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
// 180 degree rotation, invert x and y - then shift y around for height.
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
x -= (w-1);
|
||||
break;
|
||||
case 3:
|
||||
// 270 degree rotation, swap x & y for rotation, then invert y and adjust y for w (not to become h)
|
||||
bSwap = true;
|
||||
swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
y -= (w-1);
|
||||
break;
|
||||
}
|
||||
|
||||
if(bSwap) {
|
||||
drawFastVLineInternal(x, y, w, color);
|
||||
} else {
|
||||
drawFastHLineInternal(x, y, w, color);
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) {
|
||||
// Do bounds/limit checks
|
||||
if(y < 0 || y >= HEIGHT) { return; }
|
||||
|
||||
// make sure we don't try to draw below 0
|
||||
if(x < 0) {
|
||||
w += x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
// make sure we don't go off the edge of the display
|
||||
if( (x + w) > WIDTH) {
|
||||
w = (WIDTH - x);
|
||||
}
|
||||
|
||||
// if our width is now negative, punt
|
||||
if(w <= 0) { return; }
|
||||
|
||||
// set up the pointer for movement through the buffer
|
||||
register uint8_t *pBuf = buffer;
|
||||
// adjust the buffer pointer for the current row
|
||||
pBuf += ((y/8) * SSD1306_LCDWIDTH);
|
||||
// and offset x columns in
|
||||
pBuf += x;
|
||||
|
||||
register uint8_t mask = 1 << (y&7);
|
||||
|
||||
switch (color)
|
||||
{
|
||||
case WHITE: while(w--) { *pBuf++ |= mask; }; break;
|
||||
case BLACK: mask = ~mask; while(w--) { *pBuf++ &= mask; }; break;
|
||||
case INVERSE: while(w--) { *pBuf++ ^= mask; }; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
|
||||
bool bSwap = false;
|
||||
switch(rotation) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
// 90 degree rotation, swap x & y for rotation, then invert x and adjust x for h (now to become w)
|
||||
bSwap = true;
|
||||
swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
x -= (h-1);
|
||||
break;
|
||||
case 2:
|
||||
// 180 degree rotation, invert x and y - then shift y around for height.
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
y -= (h-1);
|
||||
break;
|
||||
case 3:
|
||||
// 270 degree rotation, swap x & y for rotation, then invert y
|
||||
bSwap = true;
|
||||
swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if(bSwap) {
|
||||
drawFastHLineInternal(x, y, h, color);
|
||||
} else {
|
||||
drawFastVLineInternal(x, y, h, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_SSD1306::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16_t color) {
|
||||
|
||||
// do nothing if we're off the left or right side of the screen
|
||||
if(x < 0 || x >= WIDTH) { return; }
|
||||
|
||||
// make sure we don't try to draw below 0
|
||||
if(__y < 0) {
|
||||
// __y is negative, this will subtract enough from __h to account for __y being 0
|
||||
__h += __y;
|
||||
__y = 0;
|
||||
|
||||
}
|
||||
|
||||
// make sure we don't go past the height of the display
|
||||
if( (__y + __h) > HEIGHT) {
|
||||
__h = (HEIGHT - __y);
|
||||
}
|
||||
|
||||
// if our height is now negative, punt
|
||||
if(__h <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this display doesn't need ints for coordinates, use local byte registers for faster juggling
|
||||
register uint8_t y = __y;
|
||||
register uint8_t h = __h;
|
||||
|
||||
|
||||
// set up the pointer for fast movement through the buffer
|
||||
register uint8_t *pBuf = buffer;
|
||||
// adjust the buffer pointer for the current row
|
||||
pBuf += ((y/8) * SSD1306_LCDWIDTH);
|
||||
// and offset x columns in
|
||||
pBuf += x;
|
||||
|
||||
// do the first partial byte, if necessary - this requires some masking
|
||||
register uint8_t mod = (y&7);
|
||||
if(mod) {
|
||||
// mask off the high n bits we want to set
|
||||
mod = 8-mod;
|
||||
|
||||
// note - lookup table results in a nearly 10% performance improvement in fill* functions
|
||||
// register uint8_t mask = ~(0xFF >> (mod));
|
||||
static uint8_t premask[8] = {0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
|
||||
register uint8_t mask = premask[mod];
|
||||
|
||||
// adjust the mask if we're not going to reach the end of this byte
|
||||
if( h < mod) {
|
||||
mask &= (0XFF >> (mod-h));
|
||||
}
|
||||
|
||||
switch (color)
|
||||
{
|
||||
case WHITE: *pBuf |= mask; break;
|
||||
case BLACK: *pBuf &= ~mask; break;
|
||||
case INVERSE: *pBuf ^= mask; break;
|
||||
}
|
||||
|
||||
// fast exit if we're done here!
|
||||
if(h<mod) { return; }
|
||||
|
||||
h -= mod;
|
||||
|
||||
pBuf += SSD1306_LCDWIDTH;
|
||||
}
|
||||
|
||||
|
||||
// write solid bytes while we can - effectively doing 8 rows at a time
|
||||
if(h >= 8) {
|
||||
if (color == INVERSE) { // separate copy of the code so we don't impact performance of the black/white write version with an extra comparison per loop
|
||||
do {
|
||||
*pBuf=~(*pBuf);
|
||||
|
||||
// adjust the buffer forward 8 rows worth of data
|
||||
pBuf += SSD1306_LCDWIDTH;
|
||||
|
||||
// adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now)
|
||||
h -= 8;
|
||||
} while(h >= 8);
|
||||
}
|
||||
else {
|
||||
// store a local value to work with
|
||||
register uint8_t val = (color == WHITE) ? 255 : 0;
|
||||
|
||||
do {
|
||||
// write our value in
|
||||
*pBuf = val;
|
||||
|
||||
// adjust the buffer forward 8 rows worth of data
|
||||
pBuf += SSD1306_LCDWIDTH;
|
||||
|
||||
// adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now)
|
||||
h -= 8;
|
||||
} while(h >= 8);
|
||||
}
|
||||
}
|
||||
|
||||
// now do the final partial byte, if necessary
|
||||
if(h) {
|
||||
mod = h & 7;
|
||||
// this time we want to mask the low bits of the byte, vs the high bits we did above
|
||||
// register uint8_t mask = (1 << mod) - 1;
|
||||
// note - lookup table results in a nearly 10% performance improvement in fill* functions
|
||||
static uint8_t postmask[8] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F };
|
||||
register uint8_t mask = postmask[mod];
|
||||
switch (color)
|
||||
{
|
||||
case WHITE: *pBuf |= mask; break;
|
||||
case BLACK: *pBuf &= ~mask; break;
|
||||
case INVERSE: *pBuf ^= mask; break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
/*********************************************************************
|
||||
This is a library for our Monochrome OLEDs based on SSD1306 drivers
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/category/63_98
|
||||
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#define WIRE_WRITE HWIRE.write
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#define WIRE_WRITE HWIRE.send
|
||||
#endif
|
||||
/*
|
||||
#ifdef __SAM3X8E__
|
||||
typedef volatile RwReg PortReg;
|
||||
typedef uint32_t PortMask;
|
||||
#else
|
||||
typedef volatile uint8_t PortReg;
|
||||
typedef uint8_t PortMask;
|
||||
#endif
|
||||
*/
|
||||
//typedef volatile RwReg PortReg;
|
||||
// typedef uint32_t PortMask;
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
|
||||
#define BLACK 0
|
||||
#define WHITE 1
|
||||
#define INVERSE 2
|
||||
|
||||
#define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D
|
||||
// Address for 128x32 is 0x3C
|
||||
// Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded)
|
||||
|
||||
/*=========================================================================
|
||||
SSD1306 Displays
|
||||
-----------------------------------------------------------------------
|
||||
The driver is used in multiple displays (128x64, 128x32, etc.).
|
||||
Select the appropriate display below to create an appropriately
|
||||
sized framebuffer, etc.
|
||||
|
||||
SSD1306_128_64 128x64 pixel display
|
||||
|
||||
SSD1306_128_32 128x32 pixel display
|
||||
|
||||
SSD1306_96_16
|
||||
|
||||
-----------------------------------------------------------------------*/
|
||||
#define SSD1306_128_64
|
||||
// #define SSD1306_128_32
|
||||
// #define SSD1306_96_16
|
||||
/*=========================================================================*/
|
||||
|
||||
#if defined SSD1306_128_64 && defined SSD1306_128_32
|
||||
#error "Only one SSD1306 display can be specified at once in SSD1306.h"
|
||||
#endif
|
||||
#if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16
|
||||
#error "At least one SSD1306 display must be specified in SSD1306.h"
|
||||
#endif
|
||||
|
||||
#if defined SSD1306_128_64
|
||||
#define SSD1306_LCDWIDTH 128
|
||||
#define SSD1306_LCDHEIGHT 64
|
||||
#endif
|
||||
#if defined SSD1306_128_32
|
||||
#define SSD1306_LCDWIDTH 128
|
||||
#define SSD1306_LCDHEIGHT 32
|
||||
#endif
|
||||
#if defined SSD1306_96_16
|
||||
#define SSD1306_LCDWIDTH 96
|
||||
#define SSD1306_LCDHEIGHT 16
|
||||
#endif
|
||||
|
||||
#define SSD1306_SETCONTRAST 0x81
|
||||
#define SSD1306_DISPLAYALLON_RESUME 0xA4
|
||||
#define SSD1306_DISPLAYALLON 0xA5
|
||||
#define SSD1306_NORMALDISPLAY 0xA6
|
||||
#define SSD1306_INVERTDISPLAY 0xA7
|
||||
#define SSD1306_DISPLAYOFF 0xAE
|
||||
#define SSD1306_DISPLAYON 0xAF
|
||||
|
||||
#define SSD1306_SETDISPLAYOFFSET 0xD3
|
||||
#define SSD1306_SETCOMPINS 0xDA
|
||||
|
||||
#define SSD1306_SETVCOMDETECT 0xDB
|
||||
|
||||
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
|
||||
#define SSD1306_SETPRECHARGE 0xD9
|
||||
|
||||
#define SSD1306_SETMULTIPLEX 0xA8
|
||||
|
||||
#define SSD1306_SETLOWCOLUMN 0x00
|
||||
#define SSD1306_SETHIGHCOLUMN 0x10
|
||||
|
||||
#define SSD1306_SETSTARTLINE 0x40
|
||||
|
||||
#define SSD1306_MEMORYMODE 0x20
|
||||
#define SSD1306_COLUMNADDR 0x21
|
||||
#define SSD1306_PAGEADDR 0x22
|
||||
|
||||
#define SSD1306_COMSCANINC 0xC0
|
||||
#define SSD1306_COMSCANDEC 0xC8
|
||||
|
||||
#define SSD1306_SEGREMAP 0xA0
|
||||
|
||||
#define SSD1306_CHARGEPUMP 0x8D
|
||||
|
||||
#define SSD1306_EXTERNALVCC 0x1
|
||||
#define SSD1306_SWITCHCAPVCC 0x2
|
||||
|
||||
// Scrolling #defines
|
||||
#define SSD1306_ACTIVATE_SCROLL 0x2F
|
||||
#define SSD1306_DEACTIVATE_SCROLL 0x2E
|
||||
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
|
||||
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
|
||||
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
|
||||
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
|
||||
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
|
||||
|
||||
class Adafruit_SSD1306 : public Adafruit_GFX {
|
||||
public:
|
||||
Adafruit_SSD1306(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS);
|
||||
Adafruit_SSD1306(int8_t DC, int8_t RST, int8_t CS);
|
||||
Adafruit_SSD1306(int8_t RST);
|
||||
|
||||
void begin(uint8_t switchvcc = SSD1306_SWITCHCAPVCC, uint8_t i2caddr = SSD1306_I2C_ADDRESS, bool reset=true);
|
||||
void ssd1306_command(uint8_t c);
|
||||
void ssd1306_data(uint8_t c);
|
||||
|
||||
void clearDisplay(void);
|
||||
void invertDisplay(uint8_t i);
|
||||
void display();
|
||||
|
||||
void startscrollright(uint8_t start, uint8_t stop);
|
||||
void startscrollleft(uint8_t start, uint8_t stop);
|
||||
|
||||
void startscrolldiagright(uint8_t start, uint8_t stop);
|
||||
void startscrolldiagleft(uint8_t start, uint8_t stop);
|
||||
void stopscroll(void);
|
||||
|
||||
void dim(boolean dim);
|
||||
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
|
||||
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
|
||||
private:
|
||||
int8_t _i2caddr, _vccstate, sid, sclk, dc, rst, cs;
|
||||
void fastSPIwrite(uint8_t c);
|
||||
|
||||
boolean hwSPI;
|
||||
volatile uint32 *mosiport, *clkport, *csport, *dcport;
|
||||
uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
|
||||
|
||||
inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline));
|
||||
inline void drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) __attribute__((always_inline));
|
||||
|
||||
};
|
|
@ -0,0 +1,24 @@
|
|||
This is a library for our Monochrome OLEDs based on SSD1306 drivers
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/category/63_98
|
||||
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
Scrolling code contributed by Michael Gregg
|
||||
BSD license, check license.txt for more information
|
||||
All text above must be included in any redistribution
|
||||
|
||||
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1306. Check that the Adafruit_SSD1306 folder contains Adafruit_SSD1306.cpp and Adafruit_SSD1306.h
|
||||
|
||||
Place the Adafruit_SSD1306 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
|
||||
|
||||
You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from
|
||||
https://github.com/adafruit/Adafruit-GFX-Library
|
||||
and download/install that library as well
|
|
@ -0,0 +1,6 @@
|
|||
STM32 adaption by Matthias Diro, 25.03.2015
|
||||
Things to know:
|
||||
This adaption uses hardware I2C (hardwire.h), Port: I2c2. SDA=0, SCL=1 on maple mini
|
||||
To change it to Port I2C1:
|
||||
//HardWire HWIRE(1,I2C_FAST_MODE); // I2c1
|
||||
HardWire HWIRE(2,I2C_FAST_MODE); // I2c2
|
|
@ -0,0 +1,357 @@
|
|||
/*********************************************************************
|
||||
This is an example for our Monochrome OLEDs based on SSD1306 drivers
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/category/63_98
|
||||
|
||||
This example is for a 128x32 size display using I2C to communicate
|
||||
3 pins are required to interface (2 I2C and one reset)
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#define OLED_RESET 4
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
|
||||
#define LOGO16_GLCD_HEIGHT 16
|
||||
#define LOGO16_GLCD_WIDTH 16
|
||||
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
||||
{ B00000000, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000011, B11100000,
|
||||
B11110011, B11100000,
|
||||
B11111110, B11111000,
|
||||
B01111110, B11111111,
|
||||
B00110011, B10011111,
|
||||
B00011111, B11111100,
|
||||
B00001101, B01110000,
|
||||
B00011011, B10100000,
|
||||
B00111111, B11100000,
|
||||
B00111111, B11110000,
|
||||
B01111100, B11110000,
|
||||
B01110000, B01110000,
|
||||
B00000000, B00110000 };
|
||||
|
||||
#if (SSD1306_LCDHEIGHT != 32)
|
||||
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
|
||||
// init done
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, WHITE);
|
||||
// Show the display buffer on the hardware.
|
||||
// NOTE: You _must_ call display after making any drawing commands
|
||||
// to make them visible on the display hardware!
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw many lines
|
||||
testdrawline();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw rectangles
|
||||
testdrawrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw multiple rectangles
|
||||
testfillrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw mulitple circles
|
||||
testdrawcircle();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a white circle, 10 pixel radius
|
||||
display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfillroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawtriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfilltriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw the first ~12 characters in the font
|
||||
testdrawchar();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw scrolling text
|
||||
testscrolltext();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.println("Hello, world!");
|
||||
display.setTextColor(BLACK, WHITE); // 'inverted' text
|
||||
display.println(3.141592);
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.print("0x"); display.println(0xDEADBEEF, HEX);
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// miniature bitmap display
|
||||
display.clearDisplay();
|
||||
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
|
||||
display.display();
|
||||
|
||||
// invert the display
|
||||
display.invertDisplay(true);
|
||||
delay(1000);
|
||||
display.invertDisplay(false);
|
||||
delay(1000);
|
||||
|
||||
// draw a bitmap icon and 'animate' movement
|
||||
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
|
||||
uint8_t icons[NUMFLAKES][3];
|
||||
|
||||
// initialize
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
|
||||
Serial.print("x: ");
|
||||
Serial.print(icons[f][XPOS], DEC);
|
||||
Serial.print(" y: ");
|
||||
Serial.print(icons[f][YPOS], DEC);
|
||||
Serial.print(" dy: ");
|
||||
Serial.println(icons[f][DELTAY], DEC);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
// draw each icon
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
|
||||
}
|
||||
display.display();
|
||||
delay(200);
|
||||
|
||||
// then erase it + move it
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
|
||||
// move it
|
||||
icons[f][YPOS] += icons[f][DELTAY];
|
||||
// if its gone, reinit
|
||||
if (icons[f][YPOS] > display.height()) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testdrawchar(void) {
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
|
||||
for (uint8_t i=0; i < 168; i++) {
|
||||
if (i == '\n') continue;
|
||||
display.write(i);
|
||||
if ((i > 0) && (i % 21 == 0))
|
||||
display.println();
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
|
||||
void testdrawcircle(void) {
|
||||
for (int16_t i=0; i<display.height(); i+=2) {
|
||||
display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrect(void) {
|
||||
uint8_t color = 1;
|
||||
for (int16_t i=0; i<display.height()/2; i+=3) {
|
||||
// alternate colors
|
||||
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
|
||||
display.display();
|
||||
color++;
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawtriangle(void) {
|
||||
for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
|
||||
display.drawTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
|
||||
display.fillTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawroundrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2; i+=2) {
|
||||
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(0, 0, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=display.width()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
|
||||
void testscrolltext(void) {
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(10,0);
|
||||
display.clearDisplay();
|
||||
display.println("scroll");
|
||||
display.display();
|
||||
|
||||
display.startscrollright(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrollleft(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrolldiagright(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.startscrolldiagleft(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
}
|
||||
|
|
@ -0,0 +1,368 @@
|
|||
/*********************************************************************
|
||||
This is an example for our Monochrome OLEDs based on SSD1306 drivers
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/category/63_98
|
||||
|
||||
This example is for a 128x32 size display using SPI to communicate
|
||||
4 or 5 pins are required to interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
// If using software SPI (the default case):
|
||||
#define OLED_MOSI 9
|
||||
#define OLED_CLK 10
|
||||
#define OLED_DC 11
|
||||
#define OLED_CS 12
|
||||
#define OLED_RESET 13
|
||||
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
|
||||
|
||||
/* Uncomment this block to use hardware SPI
|
||||
#define OLED_DC 6
|
||||
#define OLED_CS 7
|
||||
#define OLED_RESET 8
|
||||
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
|
||||
*/
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
#define LOGO16_GLCD_HEIGHT 16
|
||||
#define LOGO16_GLCD_WIDTH 16
|
||||
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
||||
{ B00000000, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000011, B11100000,
|
||||
B11110011, B11100000,
|
||||
B11111110, B11111000,
|
||||
B01111110, B11111111,
|
||||
B00110011, B10011111,
|
||||
B00011111, B11111100,
|
||||
B00001101, B01110000,
|
||||
B00011011, B10100000,
|
||||
B00111111, B11100000,
|
||||
B00111111, B11110000,
|
||||
B01111100, B11110000,
|
||||
B01110000, B01110000,
|
||||
B00000000, B00110000 };
|
||||
|
||||
#if (SSD1306_LCDHEIGHT != 32)
|
||||
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
|
||||
display.begin(SSD1306_SWITCHCAPVCC);
|
||||
// init done
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, WHITE);
|
||||
// Show the display buffer on the hardware.
|
||||
// NOTE: You _must_ call display after making any drawing commands
|
||||
// to make them visible on the display hardware!
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw many lines
|
||||
testdrawline();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw rectangles
|
||||
testdrawrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw multiple rectangles
|
||||
testfillrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw mulitple circles
|
||||
testdrawcircle();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a white circle, 10 pixel radius
|
||||
display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfillroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawtriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfilltriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw the first ~12 characters in the font
|
||||
testdrawchar();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw scrolling text
|
||||
testscrolltext();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.println("Hello, world!");
|
||||
display.setTextColor(BLACK, WHITE); // 'inverted' text
|
||||
display.println(3.141592);
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.print("0x"); display.println(0xDEADBEEF, HEX);
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// miniature bitmap display
|
||||
display.clearDisplay();
|
||||
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
|
||||
display.display();
|
||||
|
||||
// invert the display
|
||||
display.invertDisplay(true);
|
||||
delay(1000);
|
||||
display.invertDisplay(false);
|
||||
delay(1000);
|
||||
|
||||
// draw a bitmap icon and 'animate' movement
|
||||
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
|
||||
uint8_t icons[NUMFLAKES][3];
|
||||
|
||||
// initialize
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
|
||||
Serial.print("x: ");
|
||||
Serial.print(icons[f][XPOS], DEC);
|
||||
Serial.print(" y: ");
|
||||
Serial.print(icons[f][YPOS], DEC);
|
||||
Serial.print(" dy: ");
|
||||
Serial.println(icons[f][DELTAY], DEC);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
// draw each icon
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
|
||||
}
|
||||
display.display();
|
||||
delay(200);
|
||||
|
||||
// then erase it + move it
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
|
||||
// move it
|
||||
icons[f][YPOS] += icons[f][DELTAY];
|
||||
// if its gone, reinit
|
||||
if (icons[f][YPOS] > display.height()) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testdrawchar(void) {
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
|
||||
for (uint8_t i=0; i < 168; i++) {
|
||||
if (i == '\n') continue;
|
||||
display.write(i);
|
||||
if ((i > 0) && (i % 21 == 0))
|
||||
display.println();
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
|
||||
void testdrawcircle(void) {
|
||||
for (int16_t i=0; i<display.height(); i+=2) {
|
||||
display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrect(void) {
|
||||
uint8_t color = 1;
|
||||
for (int16_t i=0; i<display.height()/2; i+=3) {
|
||||
// alternate colors
|
||||
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
|
||||
display.display();
|
||||
color++;
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawtriangle(void) {
|
||||
for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
|
||||
display.drawTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
|
||||
display.fillTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawroundrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2; i+=2) {
|
||||
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(0, 0, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=display.width()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
|
||||
void testscrolltext(void) {
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(10,0);
|
||||
display.clearDisplay();
|
||||
display.println("scroll");
|
||||
display.display();
|
||||
|
||||
display.startscrollright(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrollleft(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrolldiagright(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.startscrolldiagleft(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
}
|
||||
|
|
@ -0,0 +1,362 @@
|
|||
/*
|
||||
STM32 adaption by Matthias Diro, tested with maple mini and heltec OLED 12864 I2c; adress: 0x3C (SPI should work, but I didn't own one)
|
||||
Things to know:
|
||||
This adaption uses hardware I2C (hardwire.h), Port: I2c2. SDA=0, SCL=1 on maple mini
|
||||
further details: STM32_README.txt
|
||||
*/
|
||||
/*********************************************************************
|
||||
This is an example for our Monochrome OLEDs based on SSD1306 drivers
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/category/63_98
|
||||
|
||||
This example is for a 128x64 size display using I2C to communicate
|
||||
3 pins are required to interface (2 I2C and one reset)
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306_STM32.h>
|
||||
|
||||
#define OLED_RESET 4
|
||||
Adafruit_SSD1306 display(OLED_RESET);
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
|
||||
#define LOGO16_GLCD_HEIGHT 16
|
||||
#define LOGO16_GLCD_WIDTH 16
|
||||
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
||||
{ B00000000, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000011, B11100000,
|
||||
B11110011, B11100000,
|
||||
B11111110, B11111000,
|
||||
B01111110, B11111111,
|
||||
B00110011, B10011111,
|
||||
B00011111, B11111100,
|
||||
B00001101, B01110000,
|
||||
B00011011, B10100000,
|
||||
B00111111, B11100000,
|
||||
B00111111, B11110000,
|
||||
B01111100, B11110000,
|
||||
B01110000, B01110000,
|
||||
B00000000, B00110000 };
|
||||
|
||||
#if (SSD1306_LCDHEIGHT != 64)
|
||||
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
|
||||
// init done
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, WHITE);
|
||||
// Show the display buffer on the hardware.
|
||||
// NOTE: You _must_ call display after making any drawing commands
|
||||
// to make them visible on the display hardware!
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw many lines
|
||||
testdrawline();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw rectangles
|
||||
testdrawrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw multiple rectangles
|
||||
testfillrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw mulitple circles
|
||||
testdrawcircle();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a white circle, 10 pixel radius
|
||||
display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfillroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawtriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfilltriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw the first ~12 characters in the font
|
||||
testdrawchar();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw scrolling text
|
||||
testscrolltext();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.println("Hello, world!");
|
||||
display.setTextColor(BLACK, WHITE); // 'inverted' text
|
||||
display.println(3.141592);
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.print("0x"); display.println(0xDEADBEEF, HEX);
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// miniature bitmap display
|
||||
display.clearDisplay();
|
||||
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
|
||||
display.display();
|
||||
|
||||
// invert the display
|
||||
display.invertDisplay(true);
|
||||
delay(1000);
|
||||
display.invertDisplay(false);
|
||||
delay(1000);
|
||||
|
||||
// draw a bitmap icon and 'animate' movement
|
||||
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
|
||||
uint8_t icons[NUMFLAKES][3];
|
||||
|
||||
// initialize
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
|
||||
Serial.print("x: ");
|
||||
Serial.print(icons[f][XPOS], DEC);
|
||||
Serial.print(" y: ");
|
||||
Serial.print(icons[f][YPOS], DEC);
|
||||
Serial.print(" dy: ");
|
||||
Serial.println(icons[f][DELTAY], DEC);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
// draw each icon
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
|
||||
}
|
||||
display.display();
|
||||
delay(200);
|
||||
|
||||
// then erase it + move it
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
|
||||
// move it
|
||||
icons[f][YPOS] += icons[f][DELTAY];
|
||||
// if its gone, reinit
|
||||
if (icons[f][YPOS] > display.height()) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testdrawchar(void) {
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
|
||||
for (uint8_t i=0; i < 168; i++) {
|
||||
if (i == '\n') continue;
|
||||
display.write(i);
|
||||
if ((i > 0) && (i % 21 == 0))
|
||||
display.println();
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
|
||||
void testdrawcircle(void) {
|
||||
for (int16_t i=0; i<display.height(); i+=2) {
|
||||
display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrect(void) {
|
||||
uint8_t color = 1;
|
||||
for (int16_t i=0; i<display.height()/2; i+=3) {
|
||||
// alternate colors
|
||||
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
|
||||
display.display();
|
||||
color++;
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawtriangle(void) {
|
||||
for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
|
||||
display.drawTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
|
||||
display.fillTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawroundrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2; i+=2) {
|
||||
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(0, 0, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=display.width()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
|
||||
void testscrolltext(void) {
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(10,0);
|
||||
display.clearDisplay();
|
||||
display.println("scroll");
|
||||
display.display();
|
||||
|
||||
display.startscrollright(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrollleft(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrolldiagright(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.startscrolldiagleft(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
}
|
|
@ -0,0 +1,368 @@
|
|||
/*********************************************************************
|
||||
This is an example for our Monochrome OLEDs based on SSD1306 drivers
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/category/63_98
|
||||
|
||||
This example is for a 128x64 size display using SPI to communicate
|
||||
4 or 5 pins are required to interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
// If using software SPI (the default case):
|
||||
#define OLED_MOSI 9
|
||||
#define OLED_CLK 10
|
||||
#define OLED_DC 11
|
||||
#define OLED_CS 12
|
||||
#define OLED_RESET 13
|
||||
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
|
||||
|
||||
/* Uncomment this block to use hardware SPI
|
||||
#define OLED_DC 6
|
||||
#define OLED_CS 7
|
||||
#define OLED_RESET 8
|
||||
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
|
||||
*/
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
#define LOGO16_GLCD_HEIGHT 16
|
||||
#define LOGO16_GLCD_WIDTH 16
|
||||
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
||||
{ B00000000, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000011, B11100000,
|
||||
B11110011, B11100000,
|
||||
B11111110, B11111000,
|
||||
B01111110, B11111111,
|
||||
B00110011, B10011111,
|
||||
B00011111, B11111100,
|
||||
B00001101, B01110000,
|
||||
B00011011, B10100000,
|
||||
B00111111, B11100000,
|
||||
B00111111, B11110000,
|
||||
B01111100, B11110000,
|
||||
B01110000, B01110000,
|
||||
B00000000, B00110000 };
|
||||
|
||||
#if (SSD1306_LCDHEIGHT != 64)
|
||||
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
|
||||
display.begin(SSD1306_SWITCHCAPVCC);
|
||||
// init done
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, WHITE);
|
||||
// Show the display buffer on the hardware.
|
||||
// NOTE: You _must_ call display after making any drawing commands
|
||||
// to make them visible on the display hardware!
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw many lines
|
||||
testdrawline();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw rectangles
|
||||
testdrawrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw multiple rectangles
|
||||
testfillrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw mulitple circles
|
||||
testdrawcircle();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a white circle, 10 pixel radius
|
||||
display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfillroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawtriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfilltriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw the first ~12 characters in the font
|
||||
testdrawchar();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw scrolling text
|
||||
testscrolltext();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.println("Hello, world!");
|
||||
display.setTextColor(BLACK, WHITE); // 'inverted' text
|
||||
display.println(3.141592);
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.print("0x"); display.println(0xDEADBEEF, HEX);
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// miniature bitmap display
|
||||
display.clearDisplay();
|
||||
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
|
||||
display.display();
|
||||
|
||||
// invert the display
|
||||
display.invertDisplay(true);
|
||||
delay(1000);
|
||||
display.invertDisplay(false);
|
||||
delay(1000);
|
||||
|
||||
// draw a bitmap icon and 'animate' movement
|
||||
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
|
||||
uint8_t icons[NUMFLAKES][3];
|
||||
|
||||
// initialize
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
|
||||
Serial.print("x: ");
|
||||
Serial.print(icons[f][XPOS], DEC);
|
||||
Serial.print(" y: ");
|
||||
Serial.print(icons[f][YPOS], DEC);
|
||||
Serial.print(" dy: ");
|
||||
Serial.println(icons[f][DELTAY], DEC);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
// draw each icon
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
|
||||
}
|
||||
display.display();
|
||||
delay(200);
|
||||
|
||||
// then erase it + move it
|
||||
for (uint8_t f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
|
||||
// move it
|
||||
icons[f][YPOS] += icons[f][DELTAY];
|
||||
// if its gone, reinit
|
||||
if (icons[f][YPOS] > display.height()) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testdrawchar(void) {
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0,0);
|
||||
|
||||
for (uint8_t i=0; i < 168; i++) {
|
||||
if (i == '\n') continue;
|
||||
display.write(i);
|
||||
if ((i > 0) && (i % 21 == 0))
|
||||
display.println();
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
|
||||
void testdrawcircle(void) {
|
||||
for (int16_t i=0; i<display.height(); i+=2) {
|
||||
display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrect(void) {
|
||||
uint8_t color = 1;
|
||||
for (int16_t i=0; i<display.height()/2; i+=3) {
|
||||
// alternate colors
|
||||
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
|
||||
display.display();
|
||||
color++;
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawtriangle(void) {
|
||||
for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
|
||||
display.drawTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
|
||||
display.fillTriangle(display.width()/2, display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, WHITE);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawroundrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
uint8_t color = WHITE;
|
||||
for (int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
|
||||
if (color == WHITE) color = BLACK;
|
||||
else color = WHITE;
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrect(void) {
|
||||
for (int16_t i=0; i<display.height()/2; i+=2) {
|
||||
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(0, 0, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=display.width()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, 0, i, WHITE);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
|
||||
void testscrolltext(void) {
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(10,0);
|
||||
display.clearDisplay();
|
||||
display.println("scroll");
|
||||
display.display();
|
||||
|
||||
display.startscrollright(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrollleft(0x00, 0x0F);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
delay(1000);
|
||||
display.startscrolldiagright(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.startscrolldiagleft(0x00, 0x07);
|
||||
delay(2000);
|
||||
display.stopscroll();
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2012, Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,168 @@
|
|||
#if defined(__AVR__)
|
||||
#include <avr/pgmspace.h>
|
||||
#define fontdatatype const uint8_t
|
||||
#elif defined(__PIC32MX__)
|
||||
#define PROGMEM
|
||||
#define fontdatatype const unsigned char
|
||||
#elif defined(__arm__)
|
||||
#define PROGMEM
|
||||
#define fontdatatype const unsigned char
|
||||
#endif
|
||||
|
||||
fontdatatype SmallFont[] PROGMEM =
|
||||
{
|
||||
0x06, 0x08, 0x20, 0x5f,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sp
|
||||
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, // !
|
||||
0x00, 0x00, 0x07, 0x00, 0x07, 0x00, // "
|
||||
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14, // #
|
||||
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12, // $
|
||||
0x00, 0x23, 0x13, 0x08, 0x64, 0x62, // %
|
||||
0x00, 0x36, 0x49, 0x55, 0x22, 0x50, // &
|
||||
0x00, 0x00, 0x05, 0x03, 0x00, 0x00, // '
|
||||
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00, // (
|
||||
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00, // )
|
||||
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14, // *
|
||||
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, // +
|
||||
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00, // ,
|
||||
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, // -
|
||||
0x00, 0x00, 0x60, 0x60, 0x00, 0x00, // .
|
||||
0x00, 0x20, 0x10, 0x08, 0x04, 0x02, // /
|
||||
|
||||
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
|
||||
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, // 1
|
||||
0x00, 0x42, 0x61, 0x51, 0x49, 0x46, // 2
|
||||
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31, // 3
|
||||
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, // 4
|
||||
0x00, 0x27, 0x45, 0x45, 0x45, 0x39, // 5
|
||||
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30, // 6
|
||||
0x00, 0x01, 0x71, 0x09, 0x05, 0x03, // 7
|
||||
0x00, 0x36, 0x49, 0x49, 0x49, 0x36, // 8
|
||||
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, // 9
|
||||
0x00, 0x00, 0x36, 0x36, 0x00, 0x00, // :
|
||||
0x00, 0x00, 0x56, 0x36, 0x00, 0x00, // ;
|
||||
0x00, 0x08, 0x14, 0x22, 0x41, 0x00, // <
|
||||
0x00, 0x14, 0x14, 0x14, 0x14, 0x14, // =
|
||||
0x00, 0x00, 0x41, 0x22, 0x14, 0x08, // >
|
||||
0x00, 0x02, 0x01, 0x51, 0x09, 0x06, // ?
|
||||
|
||||
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E, // @
|
||||
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, // A
|
||||
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, // B
|
||||
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, // C
|
||||
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C, // D
|
||||
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, // E
|
||||
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, // F
|
||||
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A, // G
|
||||
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, // H
|
||||
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, // I
|
||||
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, // J
|
||||
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, // K
|
||||
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, // L
|
||||
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
|
||||
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, // N
|
||||
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, // O
|
||||
|
||||
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, // P
|
||||
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, // Q
|
||||
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, // R
|
||||
0x00, 0x46, 0x49, 0x49, 0x49, 0x31, // S
|
||||
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, // T
|
||||
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, // U
|
||||
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, // V
|
||||
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, // W
|
||||
0x00, 0x63, 0x14, 0x08, 0x14, 0x63, // X
|
||||
0x00, 0x07, 0x08, 0x70, 0x08, 0x07, // Y
|
||||
0x00, 0x61, 0x51, 0x49, 0x45, 0x43, // Z
|
||||
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00, // [
|
||||
0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, // Backslash (Checker pattern)
|
||||
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, // ]
|
||||
0x00, 0x04, 0x02, 0x01, 0x02, 0x04, // ^
|
||||
0x00, 0x40, 0x40, 0x40, 0x40, 0x40, // _
|
||||
|
||||
0x00, 0x00, 0x03, 0x05, 0x00, 0x00, // `
|
||||
0x00, 0x20, 0x54, 0x54, 0x54, 0x78, // a
|
||||
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38, // b
|
||||
0x00, 0x38, 0x44, 0x44, 0x44, 0x20, // c
|
||||
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F, // d
|
||||
0x00, 0x38, 0x54, 0x54, 0x54, 0x18, // e
|
||||
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02, // f
|
||||
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C, // g
|
||||
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, // h
|
||||
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, // i
|
||||
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00, // j
|
||||
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, // k
|
||||
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, // l
|
||||
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78, // m
|
||||
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, // n
|
||||
0x00, 0x38, 0x44, 0x44, 0x44, 0x38, // o
|
||||
|
||||
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18, // p
|
||||
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, // q
|
||||
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, // r
|
||||
0x00, 0x48, 0x54, 0x54, 0x54, 0x20, // s
|
||||
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20, // t
|
||||
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, // u
|
||||
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, // v
|
||||
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, // w
|
||||
0x00, 0x44, 0x28, 0x10, 0x28, 0x44, // x
|
||||
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C, // y
|
||||
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, // z
|
||||
0x00, 0x00, 0x10, 0x7C, 0x82, 0x00, // {
|
||||
0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, // |
|
||||
0x00, 0x00, 0x82, 0x7C, 0x10, 0x00, // }
|
||||
0x00, 0x00, 0x06, 0x09, 0x09, 0x06 // ~ (Degrees)
|
||||
};
|
||||
|
||||
fontdatatype MediumNumbers[] PROGMEM =
|
||||
{
|
||||
0x0c, 0x10, 0x2d, 0x0d,
|
||||
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, // -
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, // .
|
||||
0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 0x00, 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x81, 0x00, 0x00, // /
|
||||
0x00, 0xfc, 0x7a, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7a, 0xfc, 0x00, 0x00, 0x7e, 0xbc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xbc, 0x7e, 0x00, // 0
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x7e, 0x00, // 1
|
||||
0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 0x00, 0x00, 0x7e, 0xbd, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x81, 0x00, 0x00, // 2
|
||||
0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 0x00, 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, 0x00, // 3
|
||||
0x00, 0xfc, 0x78, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x78, 0xfc, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3d, 0x7e, 0x00, // 4
|
||||
0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 0x00, 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, 0x00, // 5
|
||||
0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 0x00, 0x00, 0x7e, 0xbd, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, 0x00, // 6
|
||||
0x00, 0x00, 0x02, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7a, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x7e, 0x00, // 7
|
||||
0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 0x00, 0x00, 0x7e, 0xbd, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, 0x00, // 8
|
||||
0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 0x00, 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, 0x00, // 9
|
||||
};
|
||||
|
||||
fontdatatype BigNumbers[] PROGMEM =
|
||||
{
|
||||
0x0e, 0x18, 0x2d, 0x0d,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // -
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xe0, 0xe0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, // .
|
||||
0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x00, 0x00, // /
|
||||
0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 0x00, 0x00, 0xef, 0xc7, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc7, 0xef, 0x00, 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, 0x00, // 0
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf8, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc7, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x3f, 0x7f, 0x00, // 1
|
||||
0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 0x00, 0x00, 0xe0, 0xd0, 0xb8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x3b, 0x17, 0x0f, 0x00, 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x00, 0x00, // 2
|
||||
0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, 0x00, // 3
|
||||
0x00, 0xfc, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf8, 0xfc, 0x00, 0x00, 0x0f, 0x17, 0x3b, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x3f, 0x7f, 0x00, // 4
|
||||
0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x17, 0x3b, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xb8, 0xd0, 0xe0, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, 0x00, // 5
|
||||
0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0xef, 0xd7, 0xbb, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xb8, 0xd0, 0xe0, 0x00, 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, 0x00, // 6
|
||||
0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc7, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x3f, 0x7f, 0x00, // 7
|
||||
0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 0x00, 0x00, 0xef, 0xd7, 0xbb, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 0x00, 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, 0x00, // 8
|
||||
0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 0x00, 0x00, 0x0f, 0x17, 0x3b, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, 0x00, // 9
|
||||
};
|
||||
|
||||
fontdatatype TinyFont[] PROGMEM =
|
||||
{
|
||||
0x04, 0x06, 0x20, 0x5f,
|
||||
0x00, 0x00, 0x00, 0x03, 0xa0, 0x00, 0xc0, 0x0c, 0x00, 0xf9, 0x4f, 0x80, 0x6b, 0xeb, 0x00, 0x98, 0x8c, 0x80, 0x52, 0xa5, 0x80, 0x03, 0x00, 0x00, // Space, !"#$%&'
|
||||
0x01, 0xc8, 0x80, 0x89, 0xc0, 0x00, 0x50, 0x85, 0x00, 0x21, 0xc2, 0x00, 0x08, 0x40, 0x00, 0x20, 0x82, 0x00, 0x00, 0x20, 0x00, 0x18, 0x8c, 0x00, // ()*+,-./
|
||||
0xfa, 0x2f, 0x80, 0x4b, 0xe0, 0x80, 0x5a, 0x66, 0x80, 0x8a, 0xa5, 0x00, 0xe0, 0x8f, 0x80, 0xea, 0xab, 0x00, 0x72, 0xa9, 0x00, 0x9a, 0x8c, 0x00, // 01234567
|
||||
0xfa, 0xaf, 0x80, 0x4a, 0xa7, 0x00, 0x01, 0x40, 0x00, 0x09, 0x40, 0x00, 0x21, 0x48, 0x80, 0x51, 0x45, 0x00, 0x89, 0x42, 0x00, 0x42, 0x66, 0x00, // 89:;<=>?
|
||||
0x72, 0xa6, 0x80, 0x7a, 0x87, 0x80, 0xfa, 0xa5, 0x00, 0x72, 0x25, 0x00, 0xfa, 0x27, 0x00, 0xfa, 0xa8, 0x80, 0xfa, 0x88, 0x00, 0x72, 0x2b, 0x00, // @ABCDEFG
|
||||
0xf8, 0x8f, 0x80, 0x8b, 0xe8, 0x80, 0x8b, 0xe8, 0x00, 0xf8, 0x8d, 0x80, 0xf8, 0x20, 0x80, 0xf9, 0x0f, 0x80, 0xf9, 0xcf, 0x80, 0x72, 0x27, 0x00, // HIJKLMNO
|
||||
0xfa, 0x84, 0x00, 0x72, 0x27, 0x40, 0xfa, 0x85, 0x80, 0x4a, 0xa9, 0x00, 0x83, 0xe8, 0x00, 0xf0, 0x2f, 0x00, 0xe0, 0x6e, 0x00, 0xf0, 0xef, 0x00, // PQRSTUVW
|
||||
0xd8, 0x8d, 0x80, 0xc0, 0xec, 0x00, 0x9a, 0xac, 0x80, 0x03, 0xe8, 0x80, 0xc0, 0x81, 0x80, 0x8b, 0xe0, 0x00, 0x42, 0x04, 0x00, 0x08, 0x20, 0x80, // XYZ[\]^_
|
||||
0x02, 0x04, 0x00, 0x31, 0x23, 0x80, 0xf9, 0x23, 0x00, 0x31, 0x24, 0x80, 0x31, 0x2f, 0x80, 0x31, 0x62, 0x80, 0x23, 0xea, 0x00, 0x25, 0x53, 0x80, // `abcdefg
|
||||
0xf9, 0x03, 0x80, 0x02, 0xe0, 0x00, 0x06, 0xe0, 0x00, 0xf8, 0x42, 0x80, 0x03, 0xe0, 0x00, 0x79, 0x87, 0x80, 0x39, 0x03, 0x80, 0x31, 0x23, 0x00, // hijklmno
|
||||
0x7d, 0x23, 0x00, 0x31, 0x27, 0xc0, 0x78, 0x84, 0x00, 0x29, 0x40, 0x00, 0x43, 0xe4, 0x00, 0x70, 0x27, 0x00, 0x60, 0x66, 0x00, 0x70, 0x67, 0x00, // pqrstuvw
|
||||
0x48, 0xc4, 0x80, 0x74, 0x57, 0x80, 0x59, 0xe6, 0x80, 0x23, 0xe8, 0x80, 0x03, 0x60, 0x00, 0x8b, 0xe2, 0x00, 0x61, 0x0c, 0x00 // zyx{|}~
|
||||
};
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
|||
Version:
|
||||
1.0 01 Mar 2015 - initial release
|
||||
1.01 07 Mar 2015 - fixed a bug in the OLED_I2C_3D_Cube example
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,862 @@
|
|||
/*
|
||||
OLED_I2C.cpp - Arduino/chipKit library support for 128x64 pixel SSD1306 OLEDs
|
||||
Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
|
||||
This library has been made to make it easy to use 128x64 pixel OLED displays
|
||||
based on the SSD1306 controller chip with an Arduino or a chipKit.
|
||||
|
||||
You can always find the latest version of the library at
|
||||
http://www.RinkyDinkElectronics.com/
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the CC BY-NC-SA 3.0 license.
|
||||
Please see the included documents for further information.
|
||||
|
||||
Commercial use of this library requires you to buy a license that
|
||||
will allow commercial use. This includes using the library,
|
||||
modified or not, as a tool to sell products.
|
||||
|
||||
The license applies to all part of the library including the
|
||||
examples and tools supplied with the library.
|
||||
*/
|
||||
|
||||
#include "OLED_I2C.h"
|
||||
#if defined(__AVR__)
|
||||
#include <avr/pgmspace.h>
|
||||
#include "hardware/avr/HW_AVR.h"
|
||||
#elif defined(__PIC32MX__)
|
||||
#pragma message("Compiling for PIC32 Architecture...")
|
||||
#include "hardware/pic32/HW_PIC32.h"
|
||||
/*
|
||||
#elif defined(__arm__)
|
||||
#pragma message("Compiling for ARM Architecture...")
|
||||
#include "hardware/arm/HW_ARM.h"
|
||||
*/
|
||||
#elif defined (__STM32F1__)
|
||||
#pragma message("Compiling for STM32F1 Architecture...")
|
||||
#include "hardware/arm/HW_STM32.h"
|
||||
#endif
|
||||
|
||||
OLED::OLED(uint8_t data_pin, uint8_t sclk_pin, uint8_t rst_pin)
|
||||
{
|
||||
_sda_pin = data_pin;
|
||||
_scl_pin = sclk_pin;
|
||||
_rst_pin = rst_pin;
|
||||
}
|
||||
|
||||
OLED::OLED(uint8_t data_pin, uint8_t sclk_pin)
|
||||
{
|
||||
_sda_pin = data_pin;
|
||||
_scl_pin = sclk_pin;
|
||||
_rst_pin = RST_NOT_IN_USE;
|
||||
}
|
||||
|
||||
void OLED::begin()
|
||||
{
|
||||
if (_rst_pin != RST_NOT_IN_USE)
|
||||
{
|
||||
pinMode(_rst_pin, OUTPUT);
|
||||
digitalWrite(_rst_pin, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(_rst_pin, LOW);
|
||||
delay(10);
|
||||
digitalWrite(_rst_pin, HIGH);
|
||||
}
|
||||
|
||||
#if defined(SDA1) & defined(SCL1)
|
||||
if (((_sda_pin == SDA) and (_scl_pin == SCL)) or ((_sda_pin == SDA1) and (_scl_pin == SCL1)))
|
||||
#else
|
||||
if ((_sda_pin == SDA) and (_scl_pin == SCL))
|
||||
#endif
|
||||
{
|
||||
_use_hw = true;
|
||||
#pragma message("I2C HW mode enabled")
|
||||
_initTWI();
|
||||
}
|
||||
else
|
||||
{
|
||||
_use_hw = false;
|
||||
pinMode(_scl_pin, OUTPUT);
|
||||
#pragma message("SCL pinmode OUTPUT")
|
||||
}
|
||||
|
||||
_sendTWIcommand(SSD1306_DISPLAY_OFF);
|
||||
_sendTWIcommand(SSD1306_SET_DISPLAY_CLOCK_DIV_RATIO);
|
||||
_sendTWIcommand(0x80);
|
||||
_sendTWIcommand(SSD1306_SET_MULTIPLEX_RATIO);
|
||||
_sendTWIcommand(0x3F);
|
||||
_sendTWIcommand(SSD1306_SET_DISPLAY_OFFSET);
|
||||
_sendTWIcommand(0x0);
|
||||
_sendTWIcommand(SSD1306_SET_START_LINE | 0x0);
|
||||
_sendTWIcommand(SSD1306_CHARGE_PUMP);
|
||||
_sendTWIcommand(0x14);
|
||||
_sendTWIcommand(SSD1306_MEMORY_ADDR_MODE);
|
||||
_sendTWIcommand(0x00);
|
||||
_sendTWIcommand(SSD1306_SET_SEGMENT_REMAP | 0x1);
|
||||
_sendTWIcommand(SSD1306_COM_SCAN_DIR_DEC);
|
||||
_sendTWIcommand(SSD1306_SET_COM_PINS);
|
||||
_sendTWIcommand(0x12);
|
||||
_sendTWIcommand(SSD1306_SET_CONTRAST_CONTROL);
|
||||
_sendTWIcommand(0xCF);
|
||||
_sendTWIcommand(SSD1306_SET_PRECHARGE_PERIOD);
|
||||
_sendTWIcommand(0xF1);
|
||||
_sendTWIcommand(SSD1306_SET_VCOM_DESELECT);
|
||||
_sendTWIcommand(0x40);
|
||||
_sendTWIcommand(SSD1306_DISPLAY_ALL_ON_RESUME);
|
||||
_sendTWIcommand(SSD1306_NORMAL_DISPLAY);
|
||||
_sendTWIcommand(SSD1306_DISPLAY_ON);
|
||||
|
||||
clrScr();
|
||||
update();
|
||||
cfont.font=0;
|
||||
}
|
||||
|
||||
void OLED::clrScr()
|
||||
{
|
||||
memset(scrbuf, 0, 1024);
|
||||
}
|
||||
|
||||
void OLED::fillScr()
|
||||
{
|
||||
memset(scrbuf, 255, 1024);
|
||||
}
|
||||
|
||||
void OLED::setBrightness(uint8_t value)
|
||||
{
|
||||
_sendTWIcommand(SSD1306_SET_CONTRAST_CONTROL);
|
||||
_sendTWIcommand(value);
|
||||
}
|
||||
|
||||
void OLED::invert(bool mode)
|
||||
{
|
||||
if (mode==true)
|
||||
_sendTWIcommand(SSD1306_INVERT_DISPLAY);
|
||||
else
|
||||
_sendTWIcommand(SSD1306_NORMAL_DISPLAY);
|
||||
}
|
||||
|
||||
void OLED::setPixel(uint16_t x, uint16_t y)
|
||||
{
|
||||
int by, bi;
|
||||
|
||||
if ((x>=0) and (x<128) and (y>=0) and (y<64))
|
||||
{
|
||||
by=((y/8)*128)+x;
|
||||
bi=y % 8;
|
||||
|
||||
scrbuf[by]=scrbuf[by] | (1<<bi);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::clrPixel(uint16_t x, uint16_t y)
|
||||
{
|
||||
int by, bi;
|
||||
|
||||
if ((x>=0) and (x<128) and (y>=0) and (y<64))
|
||||
{
|
||||
by=((y/8)*128)+x;
|
||||
bi=y % 8;
|
||||
|
||||
scrbuf[by]=scrbuf[by] & ~(1<<bi);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::invPixel(uint16_t x, uint16_t y)
|
||||
{
|
||||
int by, bi;
|
||||
|
||||
if ((x>=0) and (x<128) and (y>=0) and (y<64))
|
||||
{
|
||||
by=((y/8)*128)+x;
|
||||
bi=y % 8;
|
||||
|
||||
if ((scrbuf[by] & (1<<bi))==0)
|
||||
scrbuf[by]=scrbuf[by] | (1<<bi);
|
||||
else
|
||||
scrbuf[by]=scrbuf[by] & ~(1<<bi);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::invertText(bool mode)
|
||||
{
|
||||
if (mode==true)
|
||||
cfont.inverted=1;
|
||||
else
|
||||
cfont.inverted=0;
|
||||
}
|
||||
|
||||
void OLED::print(char *st, int x, int y)
|
||||
{
|
||||
unsigned char ch;
|
||||
int stl;
|
||||
|
||||
stl = strlen(st);
|
||||
if (x == RIGHT)
|
||||
x = 128-(stl*cfont.x_size);
|
||||
if (x == CENTER)
|
||||
x = (128-(stl*cfont.x_size))/2;
|
||||
|
||||
for (int cnt=0; cnt<stl; cnt++)
|
||||
_print_char(*st++, x + (cnt*(cfont.x_size)), y);
|
||||
}
|
||||
|
||||
void OLED::print(String st, int x, int y)
|
||||
{
|
||||
char buf[st.length()+1];
|
||||
|
||||
st.toCharArray(buf, st.length()+1);
|
||||
print(buf, x, y);
|
||||
}
|
||||
|
||||
void OLED::printNumI(long num, int x, int y, int length, char filler)
|
||||
{
|
||||
char buf[25];
|
||||
char st[27];
|
||||
boolean neg=false;
|
||||
int c=0, f=0;
|
||||
|
||||
if (num==0)
|
||||
{
|
||||
if (length!=0)
|
||||
{
|
||||
for (c=0; c<(length-1); c++)
|
||||
st[c]=filler;
|
||||
st[c]=48;
|
||||
st[c+1]=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
st[0]=48;
|
||||
st[1]=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num<0)
|
||||
{
|
||||
neg=true;
|
||||
num=-num;
|
||||
}
|
||||
|
||||
while (num>0)
|
||||
{
|
||||
buf[c]=48+(num % 10);
|
||||
c++;
|
||||
num=(num-(num % 10))/10;
|
||||
}
|
||||
buf[c]=0;
|
||||
|
||||
if (neg)
|
||||
{
|
||||
st[0]=45;
|
||||
}
|
||||
|
||||
if (length>(c+neg))
|
||||
{
|
||||
for (int i=0; i<(length-c-neg); i++)
|
||||
{
|
||||
st[i+neg]=filler;
|
||||
f++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<c; i++)
|
||||
{
|
||||
st[i+neg+f]=buf[c-i-1];
|
||||
}
|
||||
st[c+neg+f]=0;
|
||||
|
||||
}
|
||||
|
||||
print(st,x,y);
|
||||
}
|
||||
|
||||
void OLED::printNumF(double num, byte dec, int x, int y, char divider, int length, char filler)
|
||||
{
|
||||
char st[27];
|
||||
boolean neg=false;
|
||||
|
||||
if (num<0)
|
||||
neg = true;
|
||||
|
||||
_convert_float(st, num, length, dec);
|
||||
|
||||
if (divider != '.')
|
||||
{
|
||||
for (int i=0; i<sizeof(st); i++)
|
||||
if (st[i]=='.')
|
||||
st[i]=divider;
|
||||
}
|
||||
|
||||
if (filler != ' ')
|
||||
{
|
||||
if (neg)
|
||||
{
|
||||
st[0]='-';
|
||||
for (int i=1; i<sizeof(st); i++)
|
||||
if ((st[i]==' ') || (st[i]=='-'))
|
||||
st[i]=filler;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0; i<sizeof(st); i++)
|
||||
if (st[i]==' ')
|
||||
st[i]=filler;
|
||||
}
|
||||
}
|
||||
|
||||
print(st,x,y);
|
||||
}
|
||||
|
||||
void OLED::_print_char(unsigned char c, int x, int y)
|
||||
{
|
||||
if ((cfont.y_size % 8) == 0)
|
||||
{
|
||||
int font_idx = ((c - cfont.offset)*(cfont.x_size*(cfont.y_size/8)))+4;
|
||||
for (int rowcnt=0; rowcnt<(cfont.y_size/8); rowcnt++)
|
||||
{
|
||||
for(int cnt=0; cnt<cfont.x_size; cnt++)
|
||||
{
|
||||
for (int b=0; b<8; b++)
|
||||
if ((fontbyte(font_idx+cnt+(rowcnt*cfont.x_size)) & (1<<b))!=0)
|
||||
if (cfont.inverted==0)
|
||||
setPixel(x+cnt, y+(rowcnt*8)+b);
|
||||
else
|
||||
clrPixel(x+cnt, y+(rowcnt*8)+b);
|
||||
else
|
||||
if (cfont.inverted==0)
|
||||
clrPixel(x+cnt, y+(rowcnt*8)+b);
|
||||
else
|
||||
setPixel(x+cnt, y+(rowcnt*8)+b);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int font_idx = ((c - cfont.offset)*((cfont.x_size*cfont.y_size/8)))+4;
|
||||
int cbyte=fontbyte(font_idx);
|
||||
int cbit=7;
|
||||
for (int cx=0; cx<cfont.x_size; cx++)
|
||||
{
|
||||
for (int cy=0; cy<cfont.y_size; cy++)
|
||||
{
|
||||
if ((cbyte & (1<<cbit)) != 0)
|
||||
if (cfont.inverted==0)
|
||||
setPixel(x+cx, y+cy);
|
||||
else
|
||||
clrPixel(x+cx, y+cy);
|
||||
else
|
||||
if (cfont.inverted==0)
|
||||
clrPixel(x+cx, y+cy);
|
||||
else
|
||||
setPixel(x+cx, y+cy);
|
||||
cbit--;
|
||||
if (cbit<0)
|
||||
{
|
||||
cbit=7;
|
||||
font_idx++;
|
||||
cbyte=fontbyte(font_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::setFont(uint8_t* font)
|
||||
{
|
||||
cfont.font=font;
|
||||
cfont.x_size=fontbyte(0);
|
||||
cfont.y_size=fontbyte(1);
|
||||
cfont.offset=fontbyte(2);
|
||||
cfont.numchars=fontbyte(3);
|
||||
cfont.inverted=0;
|
||||
}
|
||||
|
||||
void OLED::drawHLine(int x, int y, int l)
|
||||
{
|
||||
int by, bi;
|
||||
|
||||
if ((x>=0) and (x<128) and (y>=0) and (y<64))
|
||||
{
|
||||
for (int cx=0; cx<l; cx++)
|
||||
{
|
||||
by=((y/8)*128)+x;
|
||||
bi=y % 8;
|
||||
|
||||
scrbuf[by+cx] |= (1<<bi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::clrHLine(int x, int y, int l)
|
||||
{
|
||||
int by, bi;
|
||||
|
||||
if ((x>=0) and (x<128) and (y>=0) and (y<64))
|
||||
{
|
||||
for (int cx=0; cx<l; cx++)
|
||||
{
|
||||
by=((y/8)*128)+x;
|
||||
bi=y % 8;
|
||||
|
||||
scrbuf[by+cx] &= ~(1<<bi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::drawVLine(int x, int y, int l)
|
||||
{
|
||||
int by, bi;
|
||||
|
||||
if ((x>=0) and (x<128) and (y>=0) and (y<64))
|
||||
{
|
||||
for (int cy=0; cy<l; cy++)
|
||||
{
|
||||
setPixel(x, y+cy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::clrVLine(int x, int y, int l)
|
||||
{
|
||||
int by, bi;
|
||||
|
||||
if ((x>=0) and (x<128) and (y>=0) and (y<64))
|
||||
{
|
||||
for (int cy=0; cy<l; cy++)
|
||||
{
|
||||
clrPixel(x, y+cy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::drawLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int tmp;
|
||||
double delta, tx, ty;
|
||||
double m, b, dx, dy;
|
||||
|
||||
if (((x2-x1)<0))
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
if (((y2-y1)<0))
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
|
||||
if (y1==y2)
|
||||
{
|
||||
if (x1>x2)
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
}
|
||||
drawHLine(x1, y1, x2-x1);
|
||||
}
|
||||
else if (x1==x2)
|
||||
{
|
||||
if (y1>y2)
|
||||
{
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
drawVLine(x1, y1, y2-y1);
|
||||
}
|
||||
else if (abs(x2-x1)>abs(y2-y1))
|
||||
{
|
||||
delta=(double(y2-y1)/double(x2-x1));
|
||||
ty=double(y1);
|
||||
if (x1>x2)
|
||||
{
|
||||
for (int i=x1; i>=x2; i--)
|
||||
{
|
||||
setPixel(i, int(ty+0.5));
|
||||
ty=ty-delta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=x1; i<=x2; i++)
|
||||
{
|
||||
setPixel(i, int(ty+0.5));
|
||||
ty=ty+delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delta=(float(x2-x1)/float(y2-y1));
|
||||
tx=float(x1);
|
||||
if (y1>y2)
|
||||
{
|
||||
for (int i=y2+1; i>y1; i--)
|
||||
{
|
||||
setPixel(int(tx+0.5), i);
|
||||
tx=tx+delta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=y1; i<y2+1; i++)
|
||||
{
|
||||
setPixel(int(tx+0.5), i);
|
||||
tx=tx+delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OLED::clrLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int tmp;
|
||||
double delta, tx, ty;
|
||||
double m, b, dx, dy;
|
||||
|
||||
if (((x2-x1)<0))
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
if (((y2-y1)<0))
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
|
||||
if (y1==y2)
|
||||
{
|
||||
if (x1>x2)
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
}
|
||||
clrHLine(x1, y1, x2-x1);
|
||||
}
|
||||
else if (x1==x2)
|
||||
{
|
||||
if (y1>y2)
|
||||
{
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
clrVLine(x1, y1, y2-y1);
|
||||
}
|
||||
else if (abs(x2-x1)>abs(y2-y1))
|
||||
{
|
||||
delta=(double(y2-y1)/double(x2-x1));
|
||||
ty=double(y1);
|
||||
if (x1>x2)
|
||||
{
|
||||
for (int i=x1; i>=x2; i--)
|
||||
{
|
||||
clrPixel(i, int(ty+0.5));
|
||||
ty=ty-delta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=x1; i<=x2; i++)
|
||||
{
|
||||
clrPixel(i, int(ty+0.5));
|
||||
ty=ty+delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delta=(float(x2-x1)/float(y2-y1));
|
||||
tx=float(x1);
|
||||
if (y1>y2)
|
||||
{
|
||||
for (int i=y2+1; i>y1; i--)
|
||||
{
|
||||
clrPixel(int(tx+0.5), i);
|
||||
tx=tx+delta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=y1; i<y2+1; i++)
|
||||
{
|
||||
clrPixel(int(tx+0.5), i);
|
||||
tx=tx+delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OLED::drawRect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (x1>x2)
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
}
|
||||
if (y1>y2)
|
||||
{
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
|
||||
drawHLine(x1, y1, x2-x1);
|
||||
drawHLine(x1, y2, x2-x1);
|
||||
drawVLine(x1, y1, y2-y1);
|
||||
drawVLine(x2, y1, y2-y1+1);
|
||||
}
|
||||
|
||||
void OLED::clrRect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (x1>x2)
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
}
|
||||
if (y1>y2)
|
||||
{
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
|
||||
clrHLine(x1, y1, x2-x1);
|
||||
clrHLine(x1, y2, x2-x1);
|
||||
clrVLine(x1, y1, y2-y1);
|
||||
clrVLine(x2, y1, y2-y1+1);
|
||||
}
|
||||
|
||||
void OLED::drawRoundRect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (x1>x2)
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
}
|
||||
if (y1>y2)
|
||||
{
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
if ((x2-x1)>4 && (y2-y1)>4)
|
||||
{
|
||||
setPixel(x1+1,y1+1);
|
||||
setPixel(x2-1,y1+1);
|
||||
setPixel(x1+1,y2-1);
|
||||
setPixel(x2-1,y2-1);
|
||||
drawHLine(x1+2, y1, x2-x1-3);
|
||||
drawHLine(x1+2, y2, x2-x1-3);
|
||||
drawVLine(x1, y1+2, y2-y1-3);
|
||||
drawVLine(x2, y1+2, y2-y1-3);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::clrRoundRect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (x1>x2)
|
||||
{
|
||||
tmp=x1;
|
||||
x1=x2;
|
||||
x2=tmp;
|
||||
}
|
||||
if (y1>y2)
|
||||
{
|
||||
tmp=y1;
|
||||
y1=y2;
|
||||
y2=tmp;
|
||||
}
|
||||
if ((x2-x1)>4 && (y2-y1)>4)
|
||||
{
|
||||
clrPixel(x1+1,y1+1);
|
||||
clrPixel(x2-1,y1+1);
|
||||
clrPixel(x1+1,y2-1);
|
||||
clrPixel(x2-1,y2-1);
|
||||
clrHLine(x1+2, y1, x2-x1-3);
|
||||
clrHLine(x1+2, y2, x2-x1-3);
|
||||
clrVLine(x1, y1+2, y2-y1-3);
|
||||
clrVLine(x2, y1+2, y2-y1-3);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::drawCircle(int x, int y, int radius)
|
||||
{
|
||||
int f = 1 - radius;
|
||||
int ddF_x = 1;
|
||||
int ddF_y = -2 * radius;
|
||||
int x1 = 0;
|
||||
int y1 = radius;
|
||||
char ch, cl;
|
||||
|
||||
setPixel(x, y + radius);
|
||||
setPixel(x, y - radius);
|
||||
setPixel(x + radius, y);
|
||||
setPixel(x - radius, y);
|
||||
|
||||
while(x1 < y1)
|
||||
{
|
||||
if(f >= 0)
|
||||
{
|
||||
y1--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x1++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
setPixel(x + x1, y + y1);
|
||||
setPixel(x - x1, y + y1);
|
||||
setPixel(x + x1, y - y1);
|
||||
setPixel(x - x1, y - y1);
|
||||
setPixel(x + y1, y + x1);
|
||||
setPixel(x - y1, y + x1);
|
||||
setPixel(x + y1, y - x1);
|
||||
setPixel(x - y1, y - x1);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::clrCircle(int x, int y, int radius)
|
||||
{
|
||||
int f = 1 - radius;
|
||||
int ddF_x = 1;
|
||||
int ddF_y = -2 * radius;
|
||||
int x1 = 0;
|
||||
int y1 = radius;
|
||||
char ch, cl;
|
||||
|
||||
clrPixel(x, y + radius);
|
||||
clrPixel(x, y - radius);
|
||||
clrPixel(x + radius, y);
|
||||
clrPixel(x - radius, y);
|
||||
|
||||
while(x1 < y1)
|
||||
{
|
||||
if(f >= 0)
|
||||
{
|
||||
y1--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x1++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
clrPixel(x + x1, y + y1);
|
||||
clrPixel(x - x1, y + y1);
|
||||
clrPixel(x + x1, y - y1);
|
||||
clrPixel(x - x1, y - y1);
|
||||
clrPixel(x + y1, y + x1);
|
||||
clrPixel(x - y1, y + x1);
|
||||
clrPixel(x + y1, y - x1);
|
||||
clrPixel(x - y1, y - x1);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::drawBitmap(int x, int y, uint8_t* bitmap, int sx, int sy)
|
||||
{
|
||||
int bit;
|
||||
byte data;
|
||||
|
||||
for (int cy=0; cy<sy; cy++)
|
||||
{
|
||||
bit= cy % 8;
|
||||
for(int cx=0; cx<sx; cx++)
|
||||
{
|
||||
data=bitmapbyte(cx+((cy/8)*sx));
|
||||
if ((data & (1<<bit))>0)
|
||||
setPixel(x+cx, y+cy);
|
||||
else
|
||||
clrPixel(x+cx, y+cy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
void OLED::_sendStart(byte addr)
|
||||
{
|
||||
pinMode(_sda_pin, OUTPUT);
|
||||
digitalWrite(_sda_pin, HIGH);
|
||||
digitalWrite(_scl_pin, HIGH);
|
||||
digitalWrite(_sda_pin, LOW);
|
||||
digitalWrite(_scl_pin, LOW);
|
||||
shiftOut(_sda_pin, _scl_pin, MSBFIRST, addr);
|
||||
}
|
||||
|
||||
void OLED::_sendStop()
|
||||
{
|
||||
pinMode(_sda_pin, OUTPUT);
|
||||
digitalWrite(_sda_pin, LOW);
|
||||
digitalWrite(_scl_pin, HIGH);
|
||||
digitalWrite(_sda_pin, HIGH);
|
||||
pinMode(_sda_pin, INPUT);
|
||||
}
|
||||
|
||||
void OLED::_sendNack()
|
||||
{
|
||||
pinMode(_sda_pin, OUTPUT);
|
||||
digitalWrite(_scl_pin, LOW);
|
||||
digitalWrite(_sda_pin, HIGH);
|
||||
digitalWrite(_scl_pin, HIGH);
|
||||
digitalWrite(_scl_pin, LOW);
|
||||
pinMode(_sda_pin, INPUT);
|
||||
}
|
||||
|
||||
void OLED::_sendAck()
|
||||
{
|
||||
pinMode(_sda_pin, OUTPUT);
|
||||
digitalWrite(_scl_pin, LOW);
|
||||
digitalWrite(_sda_pin, LOW);
|
||||
digitalWrite(_scl_pin, HIGH);
|
||||
digitalWrite(_scl_pin, LOW);
|
||||
pinMode(_sda_pin, INPUT);
|
||||
}
|
||||
|
||||
void OLED::_waitForAck()
|
||||
{
|
||||
pinMode(_sda_pin, INPUT);
|
||||
digitalWrite(_scl_pin, HIGH);
|
||||
while (digitalRead(_sda_pin)==HIGH) {}
|
||||
digitalWrite(_scl_pin, LOW);
|
||||
}
|
||||
|
||||
void OLED::_writeByte(uint8_t value)
|
||||
{
|
||||
pinMode(_sda_pin, OUTPUT);
|
||||
shiftOut(_sda_pin, _scl_pin, MSBFIRST, value);
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
/*
|
||||
OLED_I2C.h - Arduino/chipKit library support for 128x64 pixel SSD1306 OLEDs
|
||||
Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
|
||||
This library has been made to make it easy to use 128x64 pixel OLED displays
|
||||
based on the SSD1306 controller chip with an Arduino or a chipKit.
|
||||
|
||||
You can always find the latest version of the library at
|
||||
http://www.RinkyDinkElectronics.com/
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the CC BY-NC-SA 3.0 license.
|
||||
Please see the included documents for further information.
|
||||
|
||||
Commercial use of this library requires you to buy a license that
|
||||
will allow commercial use. This includes using the library,
|
||||
modified or not, as a tool to sell products.
|
||||
|
||||
The license applies to all part of the library including the
|
||||
examples and tools supplied with the library.
|
||||
*/
|
||||
|
||||
#ifndef OLED_I2C_h
|
||||
#define OLED_I2C_h
|
||||
|
||||
#define SSD1306_ADDR 0x3C
|
||||
|
||||
#define LEFT 0
|
||||
#define RIGHT 9999
|
||||
#define CENTER 9998
|
||||
|
||||
#define SSD1306_COMMAND 0x00
|
||||
#define SSD1306_DATA 0xC0
|
||||
#define SSD1306_DATA_CONTINUE 0x40
|
||||
|
||||
#define RST_NOT_IN_USE 255
|
||||
|
||||
// SSD1306 Commandset
|
||||
// ------------------
|
||||
// Fundamental Commands
|
||||
#define SSD1306_SET_CONTRAST_CONTROL 0x81
|
||||
#define SSD1306_DISPLAY_ALL_ON_RESUME 0xA4
|
||||
#define SSD1306_DISPLAY_ALL_ON 0xA5
|
||||
#define SSD1306_NORMAL_DISPLAY 0xA6
|
||||
#define SSD1306_INVERT_DISPLAY 0xA7
|
||||
#define SSD1306_DISPLAY_OFF 0xAE
|
||||
#define SSD1306_DISPLAY_ON 0xAF
|
||||
#define SSD1306_NOP 0xE3
|
||||
// Scrolling Commands
|
||||
#define SSD1306_HORIZONTAL_SCROLL_RIGHT 0x26
|
||||
#define SSD1306_HORIZONTAL_SCROLL_LEFT 0x27
|
||||
#define SSD1306_HORIZONTAL_SCROLL_VERTICAL_AND_RIGHT 0x29
|
||||
#define SSD1306_HORIZONTAL_SCROLL_VERTICAL_AND_LEFT 0x2A
|
||||
#define SSD1306_DEACTIVATE_SCROLL 0x2E
|
||||
#define SSD1306_ACTIVATE_SCROLL 0x2F
|
||||
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
|
||||
// Addressing Setting Commands
|
||||
#define SSD1306_SET_LOWER_COLUMN 0x00
|
||||
#define SSD1306_SET_HIGHER_COLUMN 0x10
|
||||
#define SSD1306_MEMORY_ADDR_MODE 0x20
|
||||
#define SSD1306_SET_COLUMN_ADDR 0x21
|
||||
#define SSD1306_SET_PAGE_ADDR 0x22
|
||||
// Hardware Configuration Commands
|
||||
#define SSD1306_SET_START_LINE 0x40
|
||||
#define SSD1306_SET_SEGMENT_REMAP 0xA0
|
||||
#define SSD1306_SET_MULTIPLEX_RATIO 0xA8
|
||||
#define SSD1306_COM_SCAN_DIR_INC 0xC0
|
||||
#define SSD1306_COM_SCAN_DIR_DEC 0xC8
|
||||
#define SSD1306_SET_DISPLAY_OFFSET 0xD3
|
||||
#define SSD1306_SET_COM_PINS 0xDA
|
||||
#define SSD1306_CHARGE_PUMP 0x8D
|
||||
// Timing & Driving Scheme Setting Commands
|
||||
#define SSD1306_SET_DISPLAY_CLOCK_DIV_RATIO 0xD5
|
||||
#define SSD1306_SET_PRECHARGE_PERIOD 0xD9
|
||||
#define SSD1306_SET_VCOM_DESELECT 0xDB
|
||||
|
||||
#if defined(__AVR__)
|
||||
#include "Arduino.h"
|
||||
#include "hardware/avr/HW_AVR_defines.h"
|
||||
#elif defined(__PIC32MX__)
|
||||
#include "WProgram.h"
|
||||
#include "hardware/pic32/HW_PIC32_defines.h"
|
||||
/*
|
||||
#elif defined(__arm__)
|
||||
#include "Arduino.h"
|
||||
#include "hardware/arm/HW_ARM_defines.h"
|
||||
*/
|
||||
#elif defined (__STM32F1__)
|
||||
#include "Arduino.h"
|
||||
//#include <HardWire.h>
|
||||
#include "hardware/arm/HW_STM32_defines.h"
|
||||
#endif
|
||||
|
||||
struct _current_font
|
||||
{
|
||||
uint8_t* font;
|
||||
uint8_t x_size;
|
||||
uint8_t y_size;
|
||||
uint8_t offset;
|
||||
uint8_t numchars;
|
||||
uint8_t inverted;
|
||||
};
|
||||
|
||||
class OLED
|
||||
{
|
||||
public:
|
||||
OLED(uint8_t data_pin, uint8_t sclk_pin, uint8_t rst_pin);
|
||||
OLED(uint8_t data_pin, uint8_t sclk_pin);
|
||||
void begin();
|
||||
void update();
|
||||
void setBrightness(uint8_t value);
|
||||
void clrScr();
|
||||
void fillScr();
|
||||
void invert(bool mode);
|
||||
void setPixel(uint16_t x, uint16_t y);
|
||||
void clrPixel(uint16_t x, uint16_t y);
|
||||
void invPixel(uint16_t x, uint16_t y);
|
||||
void invertText(bool mode);
|
||||
void print(char *st, int x, int y);
|
||||
void print(String st, int x, int y);
|
||||
void printNumI(long num, int x, int y, int length=0, char filler=' ');
|
||||
void printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ');
|
||||
void setFont(uint8_t* font);
|
||||
void drawBitmap(int x, int y, uint8_t* bitmap, int sx, int sy);
|
||||
void drawLine(int x1, int y1, int x2, int y2);
|
||||
void clrLine(int x1, int y1, int x2, int y2);
|
||||
void drawRect(int x1, int y1, int x2, int y2);
|
||||
void clrRect(int x1, int y1, int x2, int y2);
|
||||
void drawRoundRect(int x1, int y1, int x2, int y2);
|
||||
void clrRoundRect(int x1, int y1, int x2, int y2);
|
||||
void drawCircle(int x, int y, int radius);
|
||||
void clrCircle(int x, int y, int radius);
|
||||
|
||||
protected:
|
||||
uint8_t _scl_pin, _sda_pin, _rst_pin;
|
||||
boolean _use_hw;
|
||||
_current_font cfont;
|
||||
uint8_t scrbuf[1024];
|
||||
|
||||
void _print_char(unsigned char c, int x, int row);
|
||||
void _convert_float(char *buf, double num, int width, byte prec);
|
||||
void drawHLine(int x, int y, int l);
|
||||
void clrHLine(int x, int y, int l);
|
||||
void drawVLine(int x, int y, int l);
|
||||
void clrVLine(int x, int y, int l);
|
||||
|
||||
void _initTWI();
|
||||
void _sendTWIstart();
|
||||
void _sendTWIstop();
|
||||
void _sendTWIcommand(uint8_t value);
|
||||
void _sendStart(byte addr);
|
||||
void _sendStop();
|
||||
void _sendAck();
|
||||
void _sendNack();
|
||||
void _waitForAck();
|
||||
void _writeByte(uint8_t value);
|
||||
#if defined(__arm__)
|
||||
// Twi *twi;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,158 @@
|
|||
// OLED_I2C_3D_Cube
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library to rotate a 3D cube.
|
||||
// The average FPS (Frames Per Second) will be displayed on the screen.
|
||||
//
|
||||
// NOTE: The FPS counter will overflow if left for an extended amount of time.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
|
||||
double vectors[8][3] = {{20, 20, 20},{-20, 20, 20},{-20, -20, 20},{20, -20, 20},{20, 20, -20},{-20, 20, -20},{-20, -20, -20},{20, -20, -20}};
|
||||
|
||||
double perspective = 100.0f;
|
||||
int deltaX, deltaY, deltaZ, iter = 0;
|
||||
long stime, fps = 0, frames = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
randomSeed(analogRead(0));
|
||||
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
stime = micros();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
drawVectors();
|
||||
if (iter == 0)
|
||||
{
|
||||
deltaX = random(7) - 3;
|
||||
deltaY = random(7) - 3;
|
||||
deltaZ = random(7) - 3;
|
||||
iter = random(250) + 5;
|
||||
}
|
||||
rotateX(deltaX);
|
||||
rotateY(deltaY);
|
||||
rotateZ(deltaZ);
|
||||
iter--;
|
||||
fps += 1000000 / (micros() - stime);
|
||||
stime = micros();
|
||||
frames++;
|
||||
myOLED.printNumI(fps / frames, 0, 0, 3); // Print average FPS on screen
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
int translateX(double x, double z)
|
||||
{
|
||||
return (int)((x + 64) + (z * (x / perspective)));
|
||||
}
|
||||
|
||||
int translateY(double y, double z)
|
||||
{
|
||||
return (int)((y + 32) + (z * (y / perspective)));
|
||||
}
|
||||
|
||||
void rotateX(int angle)
|
||||
{
|
||||
double rad, cosa, sina, Yn, Zn;
|
||||
|
||||
rad = angle * PI / 180;
|
||||
cosa = cos(rad);
|
||||
sina = sin(rad);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Yn = (vectors[i][1] * cosa) - (vectors[i][2] * sina);
|
||||
Zn = (vectors[i][1] * sina) + (vectors[i][2] * cosa);
|
||||
vectors[i][1] = Yn;
|
||||
vectors[i][2] = Zn;
|
||||
}
|
||||
}
|
||||
|
||||
void rotateY(int angle)
|
||||
{
|
||||
double rad, cosa, sina, Xn, Zn;
|
||||
|
||||
rad = angle * PI / 180;
|
||||
cosa = cos(rad);
|
||||
sina = sin(rad);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Xn = (vectors[i][0] * cosa) - (vectors[i][2] * sina);
|
||||
Zn = (vectors[i][0] * sina) + (vectors[i][2] * cosa);
|
||||
vectors[i][0] = Xn;
|
||||
vectors[i][2] = Zn;
|
||||
}
|
||||
}
|
||||
|
||||
void rotateZ(int angle)
|
||||
{
|
||||
double rad, cosa, sina, Xn, Yn;
|
||||
|
||||
rad = angle * PI / 180;
|
||||
cosa = cos(rad);
|
||||
sina = sin(rad);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Xn = (vectors[i][0] * cosa) - (vectors[i][1] * sina);
|
||||
Yn = (vectors[i][0] * sina) + (vectors[i][1] * cosa);
|
||||
vectors[i][0] = Xn;
|
||||
vectors[i][1] = Yn;
|
||||
}
|
||||
}
|
||||
|
||||
void drawVectors()
|
||||
{
|
||||
myOLED.drawLine(translateX(vectors[0][0], vectors[0][2]), translateY(vectors[0][1], vectors[0][2]), translateX(vectors[1][0], vectors[1][2]), translateY(vectors[1][1], vectors[1][2]));
|
||||
myOLED.drawLine(translateX(vectors[1][0], vectors[1][2]), translateY(vectors[1][1], vectors[1][2]), translateX(vectors[2][0], vectors[2][2]), translateY(vectors[2][1], vectors[2][2]));
|
||||
myOLED.drawLine(translateX(vectors[2][0], vectors[2][2]), translateY(vectors[2][1], vectors[2][2]), translateX(vectors[3][0], vectors[3][2]), translateY(vectors[3][1], vectors[3][2]));
|
||||
myOLED.drawLine(translateX(vectors[3][0], vectors[3][2]), translateY(vectors[3][1], vectors[3][2]), translateX(vectors[0][0], vectors[0][2]), translateY(vectors[0][1], vectors[0][2]));
|
||||
myOLED.drawLine(translateX(vectors[4][0], vectors[4][2]), translateY(vectors[4][1], vectors[4][2]), translateX(vectors[5][0], vectors[5][2]), translateY(vectors[5][1], vectors[5][2]));
|
||||
myOLED.drawLine(translateX(vectors[5][0], vectors[5][2]), translateY(vectors[5][1], vectors[5][2]), translateX(vectors[6][0], vectors[6][2]), translateY(vectors[6][1], vectors[6][2]));
|
||||
myOLED.drawLine(translateX(vectors[6][0], vectors[6][2]), translateY(vectors[6][1], vectors[6][2]), translateX(vectors[7][0], vectors[7][2]), translateY(vectors[7][1], vectors[7][2]));
|
||||
myOLED.drawLine(translateX(vectors[7][0], vectors[7][2]), translateY(vectors[7][1], vectors[7][2]), translateX(vectors[4][0], vectors[4][2]), translateY(vectors[4][1], vectors[4][2]));
|
||||
myOLED.drawLine(translateX(vectors[0][0], vectors[0][2]), translateY(vectors[0][1], vectors[0][2]), translateX(vectors[4][0], vectors[4][2]), translateY(vectors[4][1], vectors[4][2]));
|
||||
myOLED.drawLine(translateX(vectors[1][0], vectors[1][2]), translateY(vectors[1][1], vectors[1][2]), translateX(vectors[5][0], vectors[5][2]), translateY(vectors[5][1], vectors[5][2]));
|
||||
myOLED.drawLine(translateX(vectors[2][0], vectors[2][2]), translateY(vectors[2][1], vectors[2][2]), translateX(vectors[6][0], vectors[6][2]), translateY(vectors[6][1], vectors[6][2]));
|
||||
myOLED.drawLine(translateX(vectors[3][0], vectors[3][2]), translateY(vectors[3][1], vectors[3][2]), translateX(vectors[7][0], vectors[7][2]), translateY(vectors[7][1], vectors[7][2]));
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
// OLED_I2C_Bitmap
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t logo[];
|
||||
extern uint8_t mice[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(0, 16, logo, 128, 36);
|
||||
myOLED.update();
|
||||
delay(4000);
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
myOLED.invert(true);
|
||||
delay(500);
|
||||
myOLED.invert(false);
|
||||
delay(500);
|
||||
}
|
||||
delay(4000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(0, 0, mice, 128, 64);
|
||||
myOLED.update();
|
||||
delay(4000);
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
myOLED.invert(true);
|
||||
delay(500);
|
||||
myOLED.invert(false);
|
||||
delay(500);
|
||||
}
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
#include <avr/pgmspace.h>
|
||||
|
||||
const uint8_t logo[] PROGMEM={
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x08, // 0x0010 (16) pixels
|
||||
0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x1F, 0xFF, 0xFE, 0x83, // 0x0020 (32) pixels
|
||||
0x83, 0xC2, 0xC6, 0x7E, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x00, // 0x0030 (48) pixels
|
||||
0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, // 0x0040 (64) pixels
|
||||
0x20, 0xE0, 0x60, 0x20, 0x20, 0x00, 0x00, 0x40, 0xE0, 0xE0, 0x40, 0x00, 0x40, 0xE0, 0x60, 0x00, // 0x0050 (80) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFF, 0xFF, 0xEF, 0x03, 0x02, 0x02, 0x02, 0x06, 0xFC, 0xF8, // 0x0060 (96) pixels
|
||||
0xE0, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, // 0x0070 (112) pixels
|
||||
0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, 0x20, 0xE0, 0x60, 0x20, 0x20, // 0x0080 (128) pixels
|
||||
0x00, 0x00, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, // 0x0090 (144) pixels
|
||||
0x90, 0x7F, 0x90, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x3F, 0x3F, 0x20, // 0x00A0 (160) pixels
|
||||
0x00, 0x00, 0x07, 0x3F, 0x3C, 0x30, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x00, // 0x00B0 (176) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, // 0x00C0 (192) pixels
|
||||
0x27, 0x2F, 0x38, 0x30, 0x20, 0x00, 0x00, 0x00, 0x01, 0x0F, 0xBC, 0x60, 0x1E, 0x01, 0x00, 0x01, // 0x00D0 (208) pixels
|
||||
0x01, 0x01, 0x01, 0x01, 0x20, 0x20, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x1F, 0x0F, // 0x00E0 (224) pixels
|
||||
0x03, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, // 0x00F0 (240) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, 0x27, 0x2F, 0x38, 0x30, 0x20, // 0x0100 (256) pixels
|
||||
0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x06, // 0x0110 (272) pixels
|
||||
0x01, 0x00, 0x01, 0x06, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, // 0x0120 (288) pixels
|
||||
0xE0, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x00, // 0x0130 (304) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0140 (320) pixels
|
||||
0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0150 (336) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0160 (352) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0170 (368) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0180 (384) pixels
|
||||
0x00, 0x00, 0x0F, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x0F, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, // 0x0190 (400) pixels
|
||||
0x01, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, // 0x01A0 (416) pixels
|
||||
0xFF, 0x9F, 0x18, 0x18, 0x3E, 0x00, 0x00, 0x87, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, // 0x01B0 (432) pixels
|
||||
0x60, 0xF8, 0xFC, 0x46, 0x26, 0x2E, 0x3C, 0xB8, 0x00, 0xE0, 0xF8, 0x08, 0x0C, 0x0C, 0x7C, 0x38, // 0x01C0 (448) pixels
|
||||
0x00, 0x06, 0x06, 0xFF, 0x0E, 0x06, 0x84, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x08, 0x0C, 0x0C, 0x08, // 0x01D0 (464) pixels
|
||||
0x00, 0xF0, 0xF8, 0x1C, 0x06, 0x02, 0x04, 0xFC, 0xF8, 0xF0, 0x00, 0x04, 0xEE, 0xFC, 0x18, 0x04, // 0x01E0 (480) pixels
|
||||
0x06, 0x06, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x08, // 0x01F0 (496) pixels
|
||||
0x0C, 0x0C, 0x7C, 0x38, 0x00, 0x00, 0x7C, 0x7C, 0x64, 0xC4, 0xDC, 0xCC, 0x80, 0x00, 0x00, 0x00, // 0x0200 (512) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xFF, 0xF1, 0xF1, 0xF1, 0xF1, // 0x0210 (528) pixels
|
||||
0xF1, 0xF1, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF4, 0xF4, 0xF7, // 0x0220 (544) pixels
|
||||
0xF7, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF6, 0xF7, 0xF3, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, // 0x0230 (560) pixels
|
||||
0xF0, 0xF3, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF1, 0xF0, 0xF1, 0xF7, 0xF6, 0xFC, 0xFC, 0xF4, 0xF7, // 0x0240 (576) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF7, 0xFE, 0xF4, 0xF7, 0xF0, 0xF0, 0xF6, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF0, // 0x0250 (592) pixels
|
||||
0xF0, 0xF0, 0xF3, 0xF6, 0xF4, 0xF4, 0xF4, 0xF7, 0xF3, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, // 0x0260 (608) pixels
|
||||
0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF6, 0xF0, 0xF0, 0xF1, 0xF7, 0xF6, // 0x0270 (624) pixels
|
||||
0xFC, 0xFC, 0xF4, 0xF7, 0xF0, 0xF0, 0xFF, 0xF6, 0xF4, 0xF8, 0xF8, 0xF7, 0xF1, 0xF0, 0xF0, 0xF0, // 0x0280 (640) pixels
|
||||
};
|
||||
|
||||
const uint8_t mice[] PROGMEM={
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0010 (16) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x3F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, // 0x0020 (32) pixels
|
||||
0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0030 (48) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0040 (64) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0050 (80) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0xCF, 0xCF, 0xEF, 0xCF, 0x9F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, // 0x0060 (96) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x9F, 0x9F, 0xDF, 0xCF, 0xCF, 0xCF, // 0x0070 (112) pixels
|
||||
0x1F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0080 (128) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0090 (144) pixels
|
||||
0xFF, 0xFF, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00A0 (160) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00B0 (176) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00C0 (192) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00D0 (208) pixels
|
||||
0xFF, 0xFF, 0xFF, 0x07, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xE1, 0x07, 0x3F, // 0x00E0 (224) pixels
|
||||
0xFF, 0xFF, 0x7F, 0x1F, 0x47, 0x33, 0x98, 0xCC, 0xE6, 0xF3, 0xF9, 0xFE, 0xFF, 0xFF, 0x3F, 0x07, // 0x00F0 (240) pixels
|
||||
0xC0, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0100 (256) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0110 (272) pixels
|
||||
0xFF, 0xFF, 0xFC, 0xF0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0120 (288) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0130 (304) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0140 (320) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x0F, 0x07, 0x03, 0x01, 0x01, 0x00, // 0x0150 (336) pixels
|
||||
0x00, 0x00, 0xC0, 0xF0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3, 0xF7, 0xE6, 0x00, // 0x0160 (352) pixels
|
||||
0x33, 0xF9, 0xF0, 0x04, 0x0E, 0xCF, 0xEF, 0xE7, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x00, 0x03, // 0x0170 (368) pixels
|
||||
0x03, 0x03, 0x07, 0x07, 0x0F, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0180 (384) pixels
|
||||
0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x1F, // 0x0190 (400) pixels
|
||||
0x3F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1E, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x01A0 (416) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0xF0, 0xFC, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFC, 0xF9, 0xF1, 0xC3, // 0x01B0 (432) pixels
|
||||
0x87, 0xCF, 0x9F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x01C0 (448) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x01D0 (464) pixels
|
||||
0x00, 0x00, 0x3F, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0xDF, 0xCF, 0xEF, 0xE7, 0xB7, 0x33, 0x11, 0x30, // 0x01E0 (480) pixels
|
||||
0xC6, 0xC7, 0xE3, 0x10, 0x32, 0x17, 0x67, 0xAF, 0xCF, 0x1F, 0x3F, 0x7F, 0x7F, 0x7F, 0x00, 0x00, // 0x01F0 (496) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0200 (512) pixels
|
||||
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0210 (528) pixels
|
||||
0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0220 (544) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x01, 0xC1, 0xF1, // 0x0230 (560) pixels
|
||||
0x07, 0x3F, 0x0F, 0x87, 0x0C, 0x01, 0x0F, 0x7F, 0x1F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x0F, 0xFF, // 0x0240 (576) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF8, 0xF8, 0xF0, // 0x0250 (592) pixels
|
||||
0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC1, 0x00, 0x3E, 0x3C, // 0x0260 (608) pixels
|
||||
0x03, 0x8F, 0x01, 0x3C, 0x3E, 0x00, 0x83, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x70, // 0x0270 (624) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0280 (640) pixels
|
||||
0xFF, 0xF8, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0290 (656) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0xE0, 0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0x7E, 0x7C, // 0x02A0 (672) pixels
|
||||
0x3C, 0x3C, 0x3C, 0x78, 0x78, 0xF1, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF3, 0xE7, // 0x02B0 (688) pixels
|
||||
0xF0, 0xF8, 0xF0, 0xF3, 0xF8, 0xF8, 0xFC, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xFF, // 0x02C0 (704) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x02D0 (720) pixels
|
||||
0x80, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0x63, 0x6F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFA, 0x08, 0x00, // 0x02E0 (736) pixels
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0xFF, 0x3F, 0x39, 0x78, 0xF8, 0xF8, 0x60, 0x00, // 0x02F0 (752) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0300 (768) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFC, // 0x0310 (784) pixels
|
||||
0xFC, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE7, 0xCF, 0x9F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFF, // 0x0320 (800) pixels
|
||||
0xF8, 0xE3, 0xCF, 0xBF, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0330 (816) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x9F, 0xCF, 0xE3, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, // 0x0340 (832) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0350 (848) pixels
|
||||
0xFF, 0xFC, 0xF9, 0xF3, 0xE7, 0xCE, 0xDE, 0x9C, 0xB9, 0x33, 0x67, 0x87, 0x0F, 0x4F, 0x8F, 0x8F, // 0x0360 (864) pixels
|
||||
0x8E, 0x8E, 0x8E, 0x8E, 0x07, 0x87, 0xF3, 0x79, 0x7D, 0x3E, 0x9F, 0xCF, 0xE7, 0xF3, 0xF8, 0xFE, // 0x0370 (880) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0380 (896) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0390 (912) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, // 0x03A0 (928) pixels
|
||||
0xFE, 0xFC, 0xFC, 0xFC, 0xFD, 0xF8, 0xFA, 0xF8, 0xF8, 0xF9, 0xF9, 0xFD, 0xF9, 0xF9, 0xF9, 0xF9, // 0x03B0 (944) pixels
|
||||
0xF9, 0xFD, 0xFD, 0xFC, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x03C0 (960) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x03D0 (976) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF9, 0xF8, 0xF0, 0xF1, // 0x03E0 (992) pixels
|
||||
0xF1, 0xF1, 0xF1, 0xF8, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x03F0 (1008) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0400 (1024) pixels
|
||||
};
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// OLED_I2C_Brightness
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.invert(true);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i=0; i<256; i++)
|
||||
{
|
||||
myOLED.setBrightness(i);
|
||||
delay(5);
|
||||
}
|
||||
for (int i=255; i>=0; i--)
|
||||
{
|
||||
myOLED.setBrightness(i);
|
||||
delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
// OLED_I2C_Graph_Demo
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
extern uint8_t logo[];
|
||||
extern uint8_t The_End[];
|
||||
extern uint8_t pacman1[];
|
||||
extern uint8_t pacman2[];
|
||||
extern uint8_t pacman3[];
|
||||
extern uint8_t pill[];
|
||||
|
||||
float y;
|
||||
uint8_t* bm;
|
||||
int pacy;
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
randomSeed(analogRead(7));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(0, 16, logo, 128, 36);
|
||||
myOLED.update();
|
||||
|
||||
delay(3000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("OLED_I2C", CENTER, 0);
|
||||
myOLED.print("DEMO", CENTER, 28);
|
||||
myOLED.drawRect(50, 26, 78, 36);
|
||||
for (int i=0; i<6; i++)
|
||||
{
|
||||
myOLED.drawLine(79, 26+(i*2), 105-(i*3), 26+(i*2));
|
||||
myOLED.drawLine(22+(i*3), 36-(i*2), 50, 36-(i*2));
|
||||
}
|
||||
myOLED.print("(C)2015 by", CENTER, 48);
|
||||
myOLED.print("Henning Karlsen", CENTER, 56);
|
||||
myOLED.update();
|
||||
|
||||
delay(5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
for (int i=0; i<64; i+=2)
|
||||
{
|
||||
myOLED.drawLine(0, i, 127, 63-i);
|
||||
myOLED.update();
|
||||
}
|
||||
for (int i=127; i>=0; i-=2)
|
||||
{
|
||||
myOLED.drawLine(i, 0, 127-i, 63);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.drawRect(0, 0, 127, 63);
|
||||
for (int i=0; i<64; i+=4)
|
||||
{
|
||||
myOLED.drawLine(0, i, i*2, 63);
|
||||
myOLED.update();
|
||||
}
|
||||
for (int i=0; i<64; i+=4)
|
||||
{
|
||||
myOLED.drawLine(127, 63-i, 127-(i*2), 0);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
for (int i=0; i<10; i++)
|
||||
{
|
||||
myOLED.drawRoundRect(i*3, i*3, 127-(i*3), 63-(i*3));
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
for (int i=0; i<25; i++)
|
||||
{
|
||||
myOLED.drawCircle(64, 32, i*3);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.drawRect(0, 0, 127, 63);
|
||||
myOLED.drawLine(0, 31, 127, 31);
|
||||
myOLED.drawLine(63, 0, 63, 63);
|
||||
for (int c=0; c<4; c++)
|
||||
{
|
||||
for (int i=0; i<128; i++)
|
||||
{
|
||||
y=i*0.04974188368183839294232518690191;
|
||||
myOLED.invPixel(i, (sin(y)*28)+31);
|
||||
myOLED.update();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
for (int pc=0; pc<3; pc++)
|
||||
{
|
||||
pacy=random(0, 44);
|
||||
|
||||
for (int i=-20; i<132; i++)
|
||||
{
|
||||
myOLED.clrScr();
|
||||
for (int p=6; p>((i+20)/20); p--)
|
||||
myOLED.drawBitmap(p*20-8, pacy+7, pill, 5, 5);
|
||||
switch(((i+20)/3) % 4)
|
||||
{
|
||||
case 0: bm=pacman1;
|
||||
break;
|
||||
case 1: bm=pacman2;
|
||||
break;
|
||||
case 2: bm=pacman3;
|
||||
break;
|
||||
case 3: bm=pacman2;
|
||||
break;
|
||||
}
|
||||
myOLED.drawBitmap(i, pacy, bm, 20, 20);
|
||||
myOLED.update();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<41; i++)
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(22, i-24, The_End, 84, 24);
|
||||
myOLED.update();
|
||||
delay(50);
|
||||
}
|
||||
myOLED.print("Runtime (ms):", CENTER, 48);
|
||||
myOLED.printNumI(millis(), CENTER, 56);
|
||||
myOLED.update();
|
||||
for (int i=0; i<5; i++)
|
||||
{
|
||||
myOLED.invert(true);
|
||||
delay(1000);
|
||||
myOLED.invert(false);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
#include <avr/pgmspace.h>
|
||||
|
||||
const uint8_t logo[] PROGMEM={
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x08, // 0x0010 (16) pixels
|
||||
0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x1F, 0xFF, 0xFE, 0x83, // 0x0020 (32) pixels
|
||||
0x83, 0xC2, 0xC6, 0x7E, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x00, // 0x0030 (48) pixels
|
||||
0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, // 0x0040 (64) pixels
|
||||
0x20, 0xE0, 0x60, 0x20, 0x20, 0x00, 0x00, 0x40, 0xE0, 0xE0, 0x40, 0x00, 0x40, 0xE0, 0x60, 0x00, // 0x0050 (80) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFF, 0xFF, 0xEF, 0x03, 0x02, 0x02, 0x02, 0x06, 0xFC, 0xF8, // 0x0060 (96) pixels
|
||||
0xE0, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, // 0x0070 (112) pixels
|
||||
0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, 0x20, 0xE0, 0x60, 0x20, 0x20, // 0x0080 (128) pixels
|
||||
0x00, 0x00, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, // 0x0090 (144) pixels
|
||||
0x90, 0x7F, 0x90, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x3F, 0x3F, 0x20, // 0x00A0 (160) pixels
|
||||
0x00, 0x00, 0x07, 0x3F, 0x3C, 0x30, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x00, // 0x00B0 (176) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, // 0x00C0 (192) pixels
|
||||
0x27, 0x2F, 0x38, 0x30, 0x20, 0x00, 0x00, 0x00, 0x01, 0x0F, 0xBC, 0x60, 0x1E, 0x01, 0x00, 0x01, // 0x00D0 (208) pixels
|
||||
0x01, 0x01, 0x01, 0x01, 0x20, 0x20, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x1F, 0x0F, // 0x00E0 (224) pixels
|
||||
0x03, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, // 0x00F0 (240) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, 0x27, 0x2F, 0x38, 0x30, 0x20, // 0x0100 (256) pixels
|
||||
0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x06, // 0x0110 (272) pixels
|
||||
0x01, 0x00, 0x01, 0x06, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, // 0x0120 (288) pixels
|
||||
0xE0, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x00, // 0x0130 (304) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0140 (320) pixels
|
||||
0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0150 (336) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0160 (352) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0170 (368) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0180 (384) pixels
|
||||
0x00, 0x00, 0x0F, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x0F, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, // 0x0190 (400) pixels
|
||||
0x01, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, // 0x01A0 (416) pixels
|
||||
0xFF, 0x9F, 0x18, 0x18, 0x3E, 0x00, 0x00, 0x87, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, // 0x01B0 (432) pixels
|
||||
0x60, 0xF8, 0xFC, 0x46, 0x26, 0x2E, 0x3C, 0xB8, 0x00, 0xE0, 0xF8, 0x08, 0x0C, 0x0C, 0x7C, 0x38, // 0x01C0 (448) pixels
|
||||
0x00, 0x06, 0x06, 0xFF, 0x0E, 0x06, 0x84, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x08, 0x0C, 0x0C, 0x08, // 0x01D0 (464) pixels
|
||||
0x00, 0xF0, 0xF8, 0x1C, 0x06, 0x02, 0x04, 0xFC, 0xF8, 0xF0, 0x00, 0x04, 0xEE, 0xFC, 0x18, 0x04, // 0x01E0 (480) pixels
|
||||
0x06, 0x06, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x08, // 0x01F0 (496) pixels
|
||||
0x0C, 0x0C, 0x7C, 0x38, 0x00, 0x00, 0x7C, 0x7C, 0x64, 0xC4, 0xDC, 0xCC, 0x80, 0x00, 0x00, 0x00, // 0x0200 (512) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xFF, 0xF1, 0xF1, 0xF1, 0xF1, // 0x0210 (528) pixels
|
||||
0xF1, 0xF1, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF4, 0xF4, 0xF7, // 0x0220 (544) pixels
|
||||
0xF7, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF6, 0xF7, 0xF3, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, // 0x0230 (560) pixels
|
||||
0xF0, 0xF3, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF1, 0xF0, 0xF1, 0xF7, 0xF6, 0xFC, 0xFC, 0xF4, 0xF7, // 0x0240 (576) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF7, 0xFE, 0xF4, 0xF7, 0xF0, 0xF0, 0xF6, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF0, // 0x0250 (592) pixels
|
||||
0xF0, 0xF0, 0xF3, 0xF6, 0xF4, 0xF4, 0xF4, 0xF7, 0xF3, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, // 0x0260 (608) pixels
|
||||
0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF6, 0xF0, 0xF0, 0xF1, 0xF7, 0xF6, // 0x0270 (624) pixels
|
||||
0xFC, 0xFC, 0xF4, 0xF7, 0xF0, 0xF0, 0xFF, 0xF6, 0xF4, 0xF8, 0xF8, 0xF7, 0xF1, 0xF0, 0xF0, 0xF0, // 0x0280 (640) pixels
|
||||
};
|
||||
|
||||
const uint8_t The_End[] PROGMEM={
|
||||
0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0x60, 0x00, 0x00, // 0x0010 (16) pixels
|
||||
0x80, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, // 0x0020 (32) pixels
|
||||
0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, // 0x0030 (48) pixels
|
||||
0xE0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, // 0x0040 (64) pixels
|
||||
0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF0, 0x60, 0x40, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, // 0x0050 (80) pixels
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x81, 0xFC, 0xFF, 0x0F, 0x03, 0x00, 0x00, 0x00, // 0x0060 (96) pixels
|
||||
0xEE, 0x6F, 0x67, 0xFF, 0xFF, 0x7F, 0x71, 0x30, 0xF0, 0xFF, 0x3F, 0x39, 0x38, 0x18, 0x00, 0x01, // 0x0070 (112) pixels
|
||||
0x00, 0xF8, 0xFF, 0x1F, 0x0F, 0x0C, 0x0D, 0x8D, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // 0x0080 (128) pixels
|
||||
0x00, 0xC0, 0xFF, 0x7F, 0x0F, 0x0C, 0x0D, 0x0D, 0x84, 0x80, 0x80, 0x07, 0x07, 0x83, 0xFF, 0xFF, // 0x0090 (144) pixels
|
||||
0x1F, 0x3F, 0xFE, 0xF8, 0xF8, 0xFE, 0xDF, 0x03, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0x1F, 0x00, // 0x00A0 (160) pixels
|
||||
0x00, 0x80, 0x81, 0xC3, 0xE7, 0x7F, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x06, 0x07, 0x07, 0x03, 0x00, // 0x00B0 (176) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x0F, 0x0F, 0x07, 0x00, // 0x00C0 (192) pixels
|
||||
0x00, 0x06, 0x06, 0x3F, 0x1F, 0x0F, 0x0F, 0x0E, 0x06, 0x06, 0x06, 0x07, 0x07, 0x03, 0x00, 0x00, // 0x00D0 (208) pixels
|
||||
0x00, 0x00, 0x06, 0x1F, 0x3F, 0x1F, 0x0F, 0x0E, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x03, 0x00, // 0x00E0 (224) pixels
|
||||
0x06, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x18, 0x1C, 0x1F, // 0x00F0 (240) pixels
|
||||
0x0F, 0x07, 0x06, 0x07, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const uint8_t pacman1[] PROGMEM={
|
||||
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3E, 0x1C, // 0x0010 (16) pixels
|
||||
0x0C, 0x00, 0x00, 0x00, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF9, // 0x0020 (32) pixels
|
||||
0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const uint8_t pacman2[] PROGMEM={
|
||||
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0x7C, // 0x0010 (16) pixels
|
||||
0x7C, 0x38, 0x20, 0x00, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF9, // 0x0020 (32) pixels
|
||||
0xF9, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const uint8_t pacman3[] PROGMEM={
|
||||
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, // 0x0010 (16) pixels
|
||||
0xF8, 0xF0, 0xE0, 0x80, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0020 (32) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xF9, 0x79, 0x19, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const uint8_t pill[] PROGMEM={
|
||||
0x0E, 0x1F, 0x1F, 0x1F, 0x0E,
|
||||
};
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
// OLED_I2C_NumberFonts
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
extern uint8_t MediumNumbers[];
|
||||
extern uint8_t BigNumbers[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i=0; i<=10000; i++)
|
||||
{
|
||||
myOLED.setFont(MediumNumbers);
|
||||
myOLED.printNumF(float(i)/3, 2, RIGHT, 0);
|
||||
myOLED.setFont(BigNumbers);
|
||||
myOLED.printNumI(i, RIGHT, 40);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
myOLED.setFont(SmallFont);
|
||||
myOLED.print("|", LEFT, 24);
|
||||
myOLED.print("|", RIGHT, 24);
|
||||
myOLED.update();
|
||||
delay(500);
|
||||
for (int i=0; i<19; i++)
|
||||
{
|
||||
myOLED.print("\\", 7+(i*6), 24);
|
||||
myOLED.update();
|
||||
delay(250);
|
||||
}
|
||||
myOLED.clrScr();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// OLED_I2C_Scrolling_Text
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
randomSeed(analogRead(0));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int y = random(0, 56);
|
||||
for (int i=128; i>=-(34*6); i--)
|
||||
{
|
||||
myOLED.print("OLED_I2C Scrolling Text Demo ", i, y);
|
||||
myOLED.update();
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// OLED_I2C_TinyFont_View
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t TinyFont[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(TinyFont);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.print(" !\"#$%&'()*+,-./", CENTER, 16);
|
||||
myOLED.print("0123456789:;<=>?", CENTER, 22);
|
||||
myOLED.print("@ABCDEFGHIJKLMNO", CENTER, 28);
|
||||
myOLED.print("PQRSTUVWXYZ[\\]^_", CENTER, 34);
|
||||
myOLED.print("`abcdefghijklmno", CENTER, 40);
|
||||
myOLED.print("pqrstuvwxyz{|}~ ", CENTER, 46);
|
||||
myOLED.update();
|
||||
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
// OLED_I2C_ViewFont
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the Arduino you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// Arduino Uno/2009:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Leonardo:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 2 or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 3 or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Mega:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin
|
||||
//
|
||||
// Arduino Due:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin
|
||||
// SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin
|
||||
//
|
||||
// The internal pull-up resistors will be activated when using the
|
||||
// hardware I2C interfaces.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use
|
||||
// any other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used, and you will also have to use appropriate, external
|
||||
// pull-up resistors on the data and clock signals.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Upper case:", LEFT, 0);
|
||||
myOLED.print("ABCDEFGHIJKLM", CENTER, 16);
|
||||
myOLED.print("NOPQRSTUVWXYZ", CENTER, 24);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Lower case:", LEFT, 0);
|
||||
myOLED.print("abcdefghijklm", CENTER, 16);
|
||||
myOLED.print("nopqrstuvwxyz", CENTER, 24);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Numbers:", LEFT, 0);
|
||||
myOLED.print("0123456789", CENTER, 16);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Special:", LEFT, 0);
|
||||
myOLED.print("!\"#$%&'()*+,-.", CENTER, 16);
|
||||
myOLED.print("/:;<=>?@[\\]^_`", CENTER, 24);
|
||||
myOLED.print("{|}~", CENTER, 32);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
// OLED_I2C_3D_Cube
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library to rotate a 3D cube.
|
||||
// The average FPS (Frames Per Second) will be displayed on the screen.
|
||||
//
|
||||
// NOTE: The FPS counter will overflow if left for an extended amount of time.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
|
||||
double vectors[8][3] = {{20, 20, 20},{-20, 20, 20},{-20, -20, 20},{20, -20, 20},{20, 20, -20},{-20, 20, -20},{-20, -20, -20},{20, -20, -20}};
|
||||
|
||||
double perspective = 100.0f;
|
||||
int deltaX, deltaY, deltaZ, iter = 0;
|
||||
long stime, fps = 0, frames = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
randomSeed(analogRead(0));
|
||||
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
stime = micros();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
drawVectors();
|
||||
if (iter == 0)
|
||||
{
|
||||
deltaX = random(7) - 3;
|
||||
deltaY = random(7) - 3;
|
||||
deltaZ = random(7) - 3;
|
||||
iter = random(250) + 5;
|
||||
}
|
||||
rotateX(deltaX);
|
||||
rotateY(deltaY);
|
||||
rotateZ(deltaZ);
|
||||
iter--;
|
||||
fps += 1000000 / (micros() - stime);
|
||||
stime = micros();
|
||||
frames++;
|
||||
myOLED.printNumI(fps / frames, 0, 0, 3); // Print average FPS on screen
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
int translateX(double x, double z)
|
||||
{
|
||||
return (int)((x + 64) + (z * (x / perspective)));
|
||||
}
|
||||
|
||||
int translateY(double y, double z)
|
||||
{
|
||||
return (int)((y + 32) + (z * (y / perspective)));
|
||||
}
|
||||
|
||||
void rotateX(int angle)
|
||||
{
|
||||
double rad, cosa, sina, Yn, Zn;
|
||||
|
||||
rad = angle * PI / 180;
|
||||
cosa = cos(rad);
|
||||
sina = sin(rad);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Yn = (vectors[i][1] * cosa) - (vectors[i][2] * sina);
|
||||
Zn = (vectors[i][1] * sina) + (vectors[i][2] * cosa);
|
||||
vectors[i][1] = Yn;
|
||||
vectors[i][2] = Zn;
|
||||
}
|
||||
}
|
||||
|
||||
void rotateY(int angle)
|
||||
{
|
||||
double rad, cosa, sina, Xn, Zn;
|
||||
|
||||
rad = angle * PI / 180;
|
||||
cosa = cos(rad);
|
||||
sina = sin(rad);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Xn = (vectors[i][0] * cosa) - (vectors[i][2] * sina);
|
||||
Zn = (vectors[i][0] * sina) + (vectors[i][2] * cosa);
|
||||
vectors[i][0] = Xn;
|
||||
vectors[i][2] = Zn;
|
||||
}
|
||||
}
|
||||
|
||||
void rotateZ(int angle)
|
||||
{
|
||||
double rad, cosa, sina, Xn, Yn;
|
||||
|
||||
rad = angle * PI / 180;
|
||||
cosa = cos(rad);
|
||||
sina = sin(rad);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Xn = (vectors[i][0] * cosa) - (vectors[i][1] * sina);
|
||||
Yn = (vectors[i][0] * sina) + (vectors[i][1] * cosa);
|
||||
vectors[i][0] = Xn;
|
||||
vectors[i][1] = Yn;
|
||||
}
|
||||
}
|
||||
|
||||
void drawVectors()
|
||||
{
|
||||
myOLED.drawLine(translateX(vectors[0][0], vectors[0][2]), translateY(vectors[0][1], vectors[0][2]), translateX(vectors[1][0], vectors[1][2]), translateY(vectors[1][1], vectors[1][2]));
|
||||
myOLED.drawLine(translateX(vectors[1][0], vectors[1][2]), translateY(vectors[1][1], vectors[1][2]), translateX(vectors[2][0], vectors[2][2]), translateY(vectors[2][1], vectors[2][2]));
|
||||
myOLED.drawLine(translateX(vectors[2][0], vectors[2][2]), translateY(vectors[2][1], vectors[2][2]), translateX(vectors[3][0], vectors[3][2]), translateY(vectors[3][1], vectors[3][2]));
|
||||
myOLED.drawLine(translateX(vectors[3][0], vectors[3][2]), translateY(vectors[3][1], vectors[3][2]), translateX(vectors[0][0], vectors[0][2]), translateY(vectors[0][1], vectors[0][2]));
|
||||
myOLED.drawLine(translateX(vectors[4][0], vectors[4][2]), translateY(vectors[4][1], vectors[4][2]), translateX(vectors[5][0], vectors[5][2]), translateY(vectors[5][1], vectors[5][2]));
|
||||
myOLED.drawLine(translateX(vectors[5][0], vectors[5][2]), translateY(vectors[5][1], vectors[5][2]), translateX(vectors[6][0], vectors[6][2]), translateY(vectors[6][1], vectors[6][2]));
|
||||
myOLED.drawLine(translateX(vectors[6][0], vectors[6][2]), translateY(vectors[6][1], vectors[6][2]), translateX(vectors[7][0], vectors[7][2]), translateY(vectors[7][1], vectors[7][2]));
|
||||
myOLED.drawLine(translateX(vectors[7][0], vectors[7][2]), translateY(vectors[7][1], vectors[7][2]), translateX(vectors[4][0], vectors[4][2]), translateY(vectors[4][1], vectors[4][2]));
|
||||
myOLED.drawLine(translateX(vectors[0][0], vectors[0][2]), translateY(vectors[0][1], vectors[0][2]), translateX(vectors[4][0], vectors[4][2]), translateY(vectors[4][1], vectors[4][2]));
|
||||
myOLED.drawLine(translateX(vectors[1][0], vectors[1][2]), translateY(vectors[1][1], vectors[1][2]), translateX(vectors[5][0], vectors[5][2]), translateY(vectors[5][1], vectors[5][2]));
|
||||
myOLED.drawLine(translateX(vectors[2][0], vectors[2][2]), translateY(vectors[2][1], vectors[2][2]), translateX(vectors[6][0], vectors[6][2]), translateY(vectors[6][1], vectors[6][2]));
|
||||
myOLED.drawLine(translateX(vectors[3][0], vectors[3][2]), translateY(vectors[3][1], vectors[3][2]), translateX(vectors[7][0], vectors[7][2]), translateY(vectors[7][1], vectors[7][2]));
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
// OLED_I2C_Bitmap
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t logo[];
|
||||
extern uint8_t mice[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(0, 16, logo, 128, 36);
|
||||
myOLED.update();
|
||||
delay(4000);
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
myOLED.invert(true);
|
||||
delay(500);
|
||||
myOLED.invert(false);
|
||||
delay(500);
|
||||
}
|
||||
delay(4000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(0, 0, mice, 128, 64);
|
||||
myOLED.update();
|
||||
delay(4000);
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
myOLED.invert(true);
|
||||
delay(500);
|
||||
myOLED.invert(false);
|
||||
delay(500);
|
||||
}
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
const unsigned char logo[] ={
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x08, // 0x0010 (16) pixels
|
||||
0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x1F, 0xFF, 0xFE, 0x83, // 0x0020 (32) pixels
|
||||
0x83, 0xC2, 0xC6, 0x7E, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x00, // 0x0030 (48) pixels
|
||||
0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, // 0x0040 (64) pixels
|
||||
0x20, 0xE0, 0x60, 0x20, 0x20, 0x00, 0x00, 0x40, 0xE0, 0xE0, 0x40, 0x00, 0x40, 0xE0, 0x60, 0x00, // 0x0050 (80) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFF, 0xFF, 0xEF, 0x03, 0x02, 0x02, 0x02, 0x06, 0xFC, 0xF8, // 0x0060 (96) pixels
|
||||
0xE0, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, // 0x0070 (112) pixels
|
||||
0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, 0x20, 0xE0, 0x60, 0x20, 0x20, // 0x0080 (128) pixels
|
||||
0x00, 0x00, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, // 0x0090 (144) pixels
|
||||
0x90, 0x7F, 0x90, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x3F, 0x3F, 0x20, // 0x00A0 (160) pixels
|
||||
0x00, 0x00, 0x07, 0x3F, 0x3C, 0x30, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x00, // 0x00B0 (176) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, // 0x00C0 (192) pixels
|
||||
0x27, 0x2F, 0x38, 0x30, 0x20, 0x00, 0x00, 0x00, 0x01, 0x0F, 0xBC, 0x60, 0x1E, 0x01, 0x00, 0x01, // 0x00D0 (208) pixels
|
||||
0x01, 0x01, 0x01, 0x01, 0x20, 0x20, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x1F, 0x0F, // 0x00E0 (224) pixels
|
||||
0x03, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, // 0x00F0 (240) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, 0x27, 0x2F, 0x38, 0x30, 0x20, // 0x0100 (256) pixels
|
||||
0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x06, // 0x0110 (272) pixels
|
||||
0x01, 0x00, 0x01, 0x06, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, // 0x0120 (288) pixels
|
||||
0xE0, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x00, // 0x0130 (304) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0140 (320) pixels
|
||||
0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0150 (336) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0160 (352) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0170 (368) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0180 (384) pixels
|
||||
0x00, 0x00, 0x0F, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x0F, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, // 0x0190 (400) pixels
|
||||
0x01, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, // 0x01A0 (416) pixels
|
||||
0xFF, 0x9F, 0x18, 0x18, 0x3E, 0x00, 0x00, 0x87, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, // 0x01B0 (432) pixels
|
||||
0x60, 0xF8, 0xFC, 0x46, 0x26, 0x2E, 0x3C, 0xB8, 0x00, 0xE0, 0xF8, 0x08, 0x0C, 0x0C, 0x7C, 0x38, // 0x01C0 (448) pixels
|
||||
0x00, 0x06, 0x06, 0xFF, 0x0E, 0x06, 0x84, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x08, 0x0C, 0x0C, 0x08, // 0x01D0 (464) pixels
|
||||
0x00, 0xF0, 0xF8, 0x1C, 0x06, 0x02, 0x04, 0xFC, 0xF8, 0xF0, 0x00, 0x04, 0xEE, 0xFC, 0x18, 0x04, // 0x01E0 (480) pixels
|
||||
0x06, 0x06, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x08, // 0x01F0 (496) pixels
|
||||
0x0C, 0x0C, 0x7C, 0x38, 0x00, 0x00, 0x7C, 0x7C, 0x64, 0xC4, 0xDC, 0xCC, 0x80, 0x00, 0x00, 0x00, // 0x0200 (512) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xFF, 0xF1, 0xF1, 0xF1, 0xF1, // 0x0210 (528) pixels
|
||||
0xF1, 0xF1, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF4, 0xF4, 0xF7, // 0x0220 (544) pixels
|
||||
0xF7, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF6, 0xF7, 0xF3, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, // 0x0230 (560) pixels
|
||||
0xF0, 0xF3, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF1, 0xF0, 0xF1, 0xF7, 0xF6, 0xFC, 0xFC, 0xF4, 0xF7, // 0x0240 (576) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF7, 0xFE, 0xF4, 0xF7, 0xF0, 0xF0, 0xF6, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF0, // 0x0250 (592) pixels
|
||||
0xF0, 0xF0, 0xF3, 0xF6, 0xF4, 0xF4, 0xF4, 0xF7, 0xF3, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, // 0x0260 (608) pixels
|
||||
0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF6, 0xF0, 0xF0, 0xF1, 0xF7, 0xF6, // 0x0270 (624) pixels
|
||||
0xFC, 0xFC, 0xF4, 0xF7, 0xF0, 0xF0, 0xFF, 0xF6, 0xF4, 0xF8, 0xF8, 0xF7, 0xF1, 0xF0, 0xF0, 0xF0, // 0x0280 (640) pixels
|
||||
};
|
||||
|
||||
const unsigned char mice[] ={
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0010 (16) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x3F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, // 0x0020 (32) pixels
|
||||
0x3F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0030 (48) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0040 (64) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0050 (80) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0xCF, 0xCF, 0xEF, 0xCF, 0x9F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, // 0x0060 (96) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x9F, 0x9F, 0xDF, 0xCF, 0xCF, 0xCF, // 0x0070 (112) pixels
|
||||
0x1F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0080 (128) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0090 (144) pixels
|
||||
0xFF, 0xFF, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00A0 (160) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00B0 (176) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00C0 (192) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00D0 (208) pixels
|
||||
0xFF, 0xFF, 0xFF, 0x07, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xE1, 0x07, 0x3F, // 0x00E0 (224) pixels
|
||||
0xFF, 0xFF, 0x7F, 0x1F, 0x47, 0x33, 0x98, 0xCC, 0xE6, 0xF3, 0xF9, 0xFE, 0xFF, 0xFF, 0x3F, 0x07, // 0x00F0 (240) pixels
|
||||
0xC0, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0100 (256) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0110 (272) pixels
|
||||
0xFF, 0xFF, 0xFC, 0xF0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0120 (288) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0130 (304) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0140 (320) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x0F, 0x07, 0x03, 0x01, 0x01, 0x00, // 0x0150 (336) pixels
|
||||
0x00, 0x00, 0xC0, 0xF0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3, 0xF7, 0xE6, 0x00, // 0x0160 (352) pixels
|
||||
0x33, 0xF9, 0xF0, 0x04, 0x0E, 0xCF, 0xEF, 0xE7, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x00, 0x03, // 0x0170 (368) pixels
|
||||
0x03, 0x03, 0x07, 0x07, 0x0F, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0180 (384) pixels
|
||||
0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x1F, // 0x0190 (400) pixels
|
||||
0x3F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1E, 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x01A0 (416) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0xF0, 0xFC, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFC, 0xF9, 0xF1, 0xC3, // 0x01B0 (432) pixels
|
||||
0x87, 0xCF, 0x9F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x01C0 (448) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x01D0 (464) pixels
|
||||
0x00, 0x00, 0x3F, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0xDF, 0xCF, 0xEF, 0xE7, 0xB7, 0x33, 0x11, 0x30, // 0x01E0 (480) pixels
|
||||
0xC6, 0xC7, 0xE3, 0x10, 0x32, 0x17, 0x67, 0xAF, 0xCF, 0x1F, 0x3F, 0x7F, 0x7F, 0x7F, 0x00, 0x00, // 0x01F0 (496) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0200 (512) pixels
|
||||
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0210 (528) pixels
|
||||
0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0220 (544) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x01, 0xC1, 0xF1, // 0x0230 (560) pixels
|
||||
0x07, 0x3F, 0x0F, 0x87, 0x0C, 0x01, 0x0F, 0x7F, 0x1F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x0F, 0xFF, // 0x0240 (576) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF8, 0xF8, 0xF0, // 0x0250 (592) pixels
|
||||
0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC1, 0x00, 0x3E, 0x3C, // 0x0260 (608) pixels
|
||||
0x03, 0x8F, 0x01, 0x3C, 0x3E, 0x00, 0x83, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x70, // 0x0270 (624) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0280 (640) pixels
|
||||
0xFF, 0xF8, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0290 (656) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0xE0, 0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0x7E, 0x7C, // 0x02A0 (672) pixels
|
||||
0x3C, 0x3C, 0x3C, 0x78, 0x78, 0xF1, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0xF3, 0xE7, // 0x02B0 (688) pixels
|
||||
0xF0, 0xF8, 0xF0, 0xF3, 0xF8, 0xF8, 0xFC, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xFF, // 0x02C0 (704) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x02D0 (720) pixels
|
||||
0x80, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0x63, 0x6F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFA, 0x08, 0x00, // 0x02E0 (736) pixels
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x8B, 0xFF, 0xFF, 0x3F, 0x39, 0x78, 0xF8, 0xF8, 0x60, 0x00, // 0x02F0 (752) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0300 (768) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFC, // 0x0310 (784) pixels
|
||||
0xFC, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE7, 0xCF, 0x9F, 0x3F, 0x3F, 0x7F, 0x7F, 0xFF, // 0x0320 (800) pixels
|
||||
0xF8, 0xE3, 0xCF, 0xBF, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0330 (816) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x9F, 0xCF, 0xE3, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, // 0x0340 (832) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0350 (848) pixels
|
||||
0xFF, 0xFC, 0xF9, 0xF3, 0xE7, 0xCE, 0xDE, 0x9C, 0xB9, 0x33, 0x67, 0x87, 0x0F, 0x4F, 0x8F, 0x8F, // 0x0360 (864) pixels
|
||||
0x8E, 0x8E, 0x8E, 0x8E, 0x07, 0x87, 0xF3, 0x79, 0x7D, 0x3E, 0x9F, 0xCF, 0xE7, 0xF3, 0xF8, 0xFE, // 0x0370 (880) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0380 (896) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0390 (912) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, // 0x03A0 (928) pixels
|
||||
0xFE, 0xFC, 0xFC, 0xFC, 0xFD, 0xF8, 0xFA, 0xF8, 0xF8, 0xF9, 0xF9, 0xFD, 0xF9, 0xF9, 0xF9, 0xF9, // 0x03B0 (944) pixels
|
||||
0xF9, 0xFD, 0xFD, 0xFC, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x03C0 (960) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x03D0 (976) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF9, 0xF8, 0xF0, 0xF1, // 0x03E0 (992) pixels
|
||||
0xF1, 0xF1, 0xF1, 0xF8, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x03F0 (1008) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0400 (1024) pixels
|
||||
};
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// OLED_I2C_Brightness
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.invert(true);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i=0; i<256; i++)
|
||||
{
|
||||
myOLED.setBrightness(i);
|
||||
delay(5);
|
||||
}
|
||||
for (int i=255; i>=0; i--)
|
||||
{
|
||||
myOLED.setBrightness(i);
|
||||
delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
// OLED_I2C_Graph_Demo
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
extern uint8_t logo[];
|
||||
extern uint8_t The_End[];
|
||||
extern uint8_t pacman1[];
|
||||
extern uint8_t pacman2[];
|
||||
extern uint8_t pacman3[];
|
||||
extern uint8_t pill[];
|
||||
|
||||
float y;
|
||||
uint8_t* bm;
|
||||
int pacy;
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
randomSeed(analogRead(7));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(0, 16, logo, 128, 36);
|
||||
myOLED.update();
|
||||
|
||||
delay(3000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("OLED_I2C", CENTER, 0);
|
||||
myOLED.print("DEMO", CENTER, 28);
|
||||
myOLED.drawRect(50, 26, 78, 36);
|
||||
for (int i=0; i<6; i++)
|
||||
{
|
||||
myOLED.drawLine(79, 26+(i*2), 105-(i*3), 26+(i*2));
|
||||
myOLED.drawLine(22+(i*3), 36-(i*2), 50, 36-(i*2));
|
||||
}
|
||||
myOLED.print("(C)2015 by", CENTER, 48);
|
||||
myOLED.print("Henning Karlsen", CENTER, 56);
|
||||
myOLED.update();
|
||||
|
||||
delay(5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
for (int i=0; i<64; i+=2)
|
||||
{
|
||||
myOLED.drawLine(0, i, 127, 63-i);
|
||||
myOLED.update();
|
||||
}
|
||||
for (int i=127; i>=0; i-=2)
|
||||
{
|
||||
myOLED.drawLine(i, 0, 127-i, 63);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.drawRect(0, 0, 127, 63);
|
||||
for (int i=0; i<64; i+=4)
|
||||
{
|
||||
myOLED.drawLine(0, i, i*2, 63);
|
||||
myOLED.update();
|
||||
}
|
||||
for (int i=0; i<64; i+=4)
|
||||
{
|
||||
myOLED.drawLine(127, 63-i, 127-(i*2), 0);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
for (int i=0; i<10; i++)
|
||||
{
|
||||
myOLED.drawRoundRect(i*3, i*3, 127-(i*3), 63-(i*3));
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
for (int i=0; i<25; i++)
|
||||
{
|
||||
myOLED.drawCircle(64, 32, i*3);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.drawRect(0, 0, 127, 63);
|
||||
myOLED.drawLine(0, 31, 127, 31);
|
||||
myOLED.drawLine(63, 0, 63, 63);
|
||||
for (int c=0; c<4; c++)
|
||||
{
|
||||
for (int i=0; i<128; i++)
|
||||
{
|
||||
y=i*0.04974188368183839294232518690191;
|
||||
myOLED.invPixel(i, (sin(y)*28)+31);
|
||||
myOLED.update();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
|
||||
for (int pc=0; pc<3; pc++)
|
||||
{
|
||||
pacy=random(0, 44);
|
||||
|
||||
for (int i=-20; i<132; i++)
|
||||
{
|
||||
myOLED.clrScr();
|
||||
for (int p=6; p>((i+20)/20); p--)
|
||||
myOLED.drawBitmap(p*20-8, pacy+7, pill, 5, 5);
|
||||
switch(((i+20)/3) % 4)
|
||||
{
|
||||
case 0: bm=pacman1;
|
||||
break;
|
||||
case 1: bm=pacman2;
|
||||
break;
|
||||
case 2: bm=pacman3;
|
||||
break;
|
||||
case 3: bm=pacman2;
|
||||
break;
|
||||
}
|
||||
myOLED.drawBitmap(i, pacy, bm, 20, 20);
|
||||
myOLED.update();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<41; i++)
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.drawBitmap(22, i-24, The_End, 84, 24);
|
||||
myOLED.update();
|
||||
delay(50);
|
||||
}
|
||||
myOLED.print("Runtime (ms):", CENTER, 48);
|
||||
myOLED.printNumI(millis(), CENTER, 56);
|
||||
myOLED.update();
|
||||
for (int i=0; i<5; i++)
|
||||
{
|
||||
myOLED.invert(true);
|
||||
delay(1000);
|
||||
myOLED.invert(false);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
const unsigned char logo[] ={
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x08, // 0x0010 (16) pixels
|
||||
0x08, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x1F, 0xFF, 0xFE, 0x83, // 0x0020 (32) pixels
|
||||
0x83, 0xC2, 0xC6, 0x7E, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x00, // 0x0030 (48) pixels
|
||||
0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, // 0x0040 (64) pixels
|
||||
0x20, 0xE0, 0x60, 0x20, 0x20, 0x00, 0x00, 0x40, 0xE0, 0xE0, 0x40, 0x00, 0x40, 0xE0, 0x60, 0x00, // 0x0050 (80) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0xFF, 0xFF, 0xEF, 0x03, 0x02, 0x02, 0x02, 0x06, 0xFC, 0xF8, // 0x0060 (96) pixels
|
||||
0xE0, 0x00, 0x00, 0x00, 0x20, 0xE7, 0xE7, 0x00, 0x00, 0x00, 0x20, 0x70, 0xE0, 0xC0, 0x20, 0x30, // 0x0070 (112) pixels
|
||||
0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0xFE, 0xFE, 0x00, 0x20, 0xE0, 0x60, 0x20, 0x20, // 0x0080 (128) pixels
|
||||
0x00, 0x00, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, // 0x0090 (144) pixels
|
||||
0x90, 0x7F, 0x90, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3C, 0x3F, 0x3F, 0x20, // 0x00A0 (160) pixels
|
||||
0x00, 0x00, 0x07, 0x3F, 0x3C, 0x30, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x00, // 0x00B0 (176) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, // 0x00C0 (192) pixels
|
||||
0x27, 0x2F, 0x38, 0x30, 0x20, 0x00, 0x00, 0x00, 0x01, 0x0F, 0xBC, 0x60, 0x1E, 0x01, 0x00, 0x01, // 0x00D0 (208) pixels
|
||||
0x01, 0x01, 0x01, 0x01, 0x20, 0x20, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x30, 0x1F, 0x0F, // 0x00E0 (224) pixels
|
||||
0x03, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x30, 0x00, 0x00, 0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, // 0x00F0 (240) pixels
|
||||
0x20, 0x3F, 0x3F, 0x20, 0x00, 0x00, 0x20, 0x20, 0x3F, 0x3F, 0x22, 0x27, 0x2F, 0x38, 0x30, 0x20, // 0x0100 (256) pixels
|
||||
0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x60, 0x18, 0x06, // 0x0110 (272) pixels
|
||||
0x01, 0x00, 0x01, 0x06, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xE0, // 0x0120 (288) pixels
|
||||
0xE0, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x40, 0xC0, 0xC0, 0x00, 0x00, 0x00, // 0x0130 (304) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0140 (320) pixels
|
||||
0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x03, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0150 (336) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0160 (352) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0170 (368) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0180 (384) pixels
|
||||
0x00, 0x00, 0x0F, 0x08, 0x08, 0xF8, 0x08, 0x08, 0x0F, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, // 0x0190 (400) pixels
|
||||
0x01, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, // 0x01A0 (416) pixels
|
||||
0xFF, 0x9F, 0x18, 0x18, 0x3E, 0x00, 0x00, 0x87, 0xC0, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, // 0x01B0 (432) pixels
|
||||
0x60, 0xF8, 0xFC, 0x46, 0x26, 0x2E, 0x3C, 0xB8, 0x00, 0xE0, 0xF8, 0x08, 0x0C, 0x0C, 0x7C, 0x38, // 0x01C0 (448) pixels
|
||||
0x00, 0x06, 0x06, 0xFF, 0x0E, 0x06, 0x84, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x08, 0x0C, 0x0C, 0x08, // 0x01D0 (464) pixels
|
||||
0x00, 0xF0, 0xF8, 0x1C, 0x06, 0x02, 0x04, 0xFC, 0xF8, 0xF0, 0x00, 0x04, 0xEE, 0xFC, 0x18, 0x04, // 0x01E0 (480) pixels
|
||||
0x06, 0x06, 0xFC, 0xF8, 0x00, 0x00, 0x00, 0x04, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x08, // 0x01F0 (496) pixels
|
||||
0x0C, 0x0C, 0x7C, 0x38, 0x00, 0x00, 0x7C, 0x7C, 0x64, 0xC4, 0xDC, 0xCC, 0x80, 0x00, 0x00, 0x00, // 0x0200 (512) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xFF, 0xF1, 0xF1, 0xF1, 0xF1, // 0x0210 (528) pixels
|
||||
0xF1, 0xF1, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF4, 0xF4, 0xF7, // 0x0220 (544) pixels
|
||||
0xF7, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF6, 0xF7, 0xF3, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, // 0x0230 (560) pixels
|
||||
0xF0, 0xF3, 0xF7, 0xF4, 0xF4, 0xF4, 0xF6, 0xF1, 0xF0, 0xF1, 0xF7, 0xF6, 0xFC, 0xFC, 0xF4, 0xF7, // 0x0240 (576) pixels
|
||||
0xF0, 0xF0, 0xF0, 0xF7, 0xFE, 0xF4, 0xF7, 0xF0, 0xF0, 0xF6, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF0, // 0x0250 (592) pixels
|
||||
0xF0, 0xF0, 0xF3, 0xF6, 0xF4, 0xF4, 0xF4, 0xF7, 0xF3, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, // 0x0260 (608) pixels
|
||||
0xF0, 0xF4, 0xF7, 0xF7, 0xF4, 0xF0, 0xF0, 0xF4, 0xF7, 0xF7, 0xF6, 0xF0, 0xF0, 0xF1, 0xF7, 0xF6, // 0x0270 (624) pixels
|
||||
0xFC, 0xFC, 0xF4, 0xF7, 0xF0, 0xF0, 0xFF, 0xF6, 0xF4, 0xF8, 0xF8, 0xF7, 0xF1, 0xF0, 0xF0, 0xF0, // 0x0280 (640) pixels
|
||||
};
|
||||
|
||||
const unsigned char The_End[] ={
|
||||
0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0x60, 0x00, 0x00, // 0x0010 (16) pixels
|
||||
0x80, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, // 0x0020 (32) pixels
|
||||
0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, // 0x0030 (48) pixels
|
||||
0xE0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, // 0x0040 (64) pixels
|
||||
0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF0, 0x60, 0x40, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, // 0x0050 (80) pixels
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x81, 0xFC, 0xFF, 0x0F, 0x03, 0x00, 0x00, 0x00, // 0x0060 (96) pixels
|
||||
0xEE, 0x6F, 0x67, 0xFF, 0xFF, 0x7F, 0x71, 0x30, 0xF0, 0xFF, 0x3F, 0x39, 0x38, 0x18, 0x00, 0x01, // 0x0070 (112) pixels
|
||||
0x00, 0xF8, 0xFF, 0x1F, 0x0F, 0x0C, 0x0D, 0x8D, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // 0x0080 (128) pixels
|
||||
0x00, 0xC0, 0xFF, 0x7F, 0x0F, 0x0C, 0x0D, 0x0D, 0x84, 0x80, 0x80, 0x07, 0x07, 0x83, 0xFF, 0xFF, // 0x0090 (144) pixels
|
||||
0x1F, 0x3F, 0xFE, 0xF8, 0xF8, 0xFE, 0xDF, 0x03, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0x1F, 0x00, // 0x00A0 (160) pixels
|
||||
0x00, 0x80, 0x81, 0xC3, 0xE7, 0x7F, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x06, 0x07, 0x07, 0x03, 0x00, // 0x00B0 (176) pixels
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x0F, 0x0F, 0x07, 0x00, // 0x00C0 (192) pixels
|
||||
0x00, 0x06, 0x06, 0x3F, 0x1F, 0x0F, 0x0F, 0x0E, 0x06, 0x06, 0x06, 0x07, 0x07, 0x03, 0x00, 0x00, // 0x00D0 (208) pixels
|
||||
0x00, 0x00, 0x06, 0x1F, 0x3F, 0x1F, 0x0F, 0x0E, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x03, 0x00, // 0x00E0 (224) pixels
|
||||
0x06, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x18, 0x1C, 0x1F, // 0x00F0 (240) pixels
|
||||
0x0F, 0x07, 0x06, 0x07, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const unsigned char pacman1[] ={
|
||||
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3E, 0x1C, // 0x0010 (16) pixels
|
||||
0x0C, 0x00, 0x00, 0x00, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF9, // 0x0020 (32) pixels
|
||||
0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const unsigned char pacman2[] ={
|
||||
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0x7C, // 0x0010 (16) pixels
|
||||
0x7C, 0x38, 0x20, 0x00, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF9, // 0x0020 (32) pixels
|
||||
0xF9, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const unsigned char pacman3[] ={
|
||||
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, // 0x0010 (16) pixels
|
||||
0xF8, 0xF0, 0xE0, 0x80, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0020 (32) pixels
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xF9, 0x79, 0x19, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const unsigned char pill[] ={
|
||||
0x0E, 0x1F, 0x1F, 0x1F, 0x0E,
|
||||
};
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
// OLED_I2C_NumberFonts
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
extern uint8_t MediumNumbers[];
|
||||
extern uint8_t BigNumbers[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i=0; i<=10000; i++)
|
||||
{
|
||||
myOLED.setFont(MediumNumbers);
|
||||
myOLED.printNumF(float(i)/3, 2, RIGHT, 0);
|
||||
myOLED.setFont(BigNumbers);
|
||||
myOLED.printNumI(i, RIGHT, 40);
|
||||
myOLED.update();
|
||||
}
|
||||
|
||||
myOLED.setFont(SmallFont);
|
||||
myOLED.print("|", LEFT, 24);
|
||||
myOLED.print("|", RIGHT, 24);
|
||||
myOLED.update();
|
||||
delay(500);
|
||||
for (int i=0; i<19; i++)
|
||||
{
|
||||
myOLED.print("\\", 7+(i*6), 24);
|
||||
myOLED.update();
|
||||
delay(250);
|
||||
}
|
||||
myOLED.clrScr();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
// OLED_I2C_Scrolling_Text
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
randomSeed(analogRead(0));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int y = random(0, 56);
|
||||
for (int i=128; i>=-(34*6); i--)
|
||||
{
|
||||
myOLED.print("OLED_I2C Scrolling Text Demo ", i, y);
|
||||
myOLED.update();
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
// OLED_I2C_TinyFont_View
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t TinyFont[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(TinyFont);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.print(" !\"#$%&'()*+,-./", CENTER, 16);
|
||||
myOLED.print("0123456789:;<=>?", CENTER, 22);
|
||||
myOLED.print("@ABCDEFGHIJKLMNO", CENTER, 28);
|
||||
myOLED.print("PQRSTUVWXYZ[\\]^_", CENTER, 34);
|
||||
myOLED.print("`abcdefghijklmno", CENTER, 40);
|
||||
myOLED.print("pqrstuvwxyz{|}~ ", CENTER, 46);
|
||||
myOLED.update();
|
||||
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
// OLED_I2C_ViewFont
|
||||
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
|
||||
// web: http://www.RinkyDinkElectronics.com/
|
||||
//
|
||||
// A quick demo of how to use my OLED_I2C library.
|
||||
//
|
||||
// To use the hardware I2C (TWI) interface of the chipKit you must connect
|
||||
// the pins as follows:
|
||||
//
|
||||
// chipKit Uno32/uC32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Analog 4
|
||||
// SCL pin -> Analog 5
|
||||
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
|
||||
//
|
||||
// chipKit Max32:
|
||||
// ----------------------
|
||||
// Display: SDA pin -> Digital 20 (the pin labeled SDA)
|
||||
// SCL pin -> Digital 21 (the pin labeled SCL)
|
||||
//
|
||||
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
|
||||
// so external pull-up resistors on the data and clock signals are required.
|
||||
//
|
||||
// You can connect the OLED display to any available pin but if you use any
|
||||
// other than what is described above the library will fall back to
|
||||
// a software-based, TWI-like protocol which will require exclusive access
|
||||
// to the pins used.
|
||||
//
|
||||
|
||||
#include <OLED_I2C.h>
|
||||
|
||||
OLED myOLED(SDA, SCL, 8);
|
||||
|
||||
extern uint8_t SmallFont[];
|
||||
|
||||
void setup()
|
||||
{
|
||||
myOLED.begin();
|
||||
myOLED.setFont(SmallFont);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Upper case:", LEFT, 0);
|
||||
myOLED.print("ABCDEFGHIJKLM", CENTER, 16);
|
||||
myOLED.print("NOPQRSTUVWXYZ", CENTER, 24);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Lower case:", LEFT, 0);
|
||||
myOLED.print("abcdefghijklm", CENTER, 16);
|
||||
myOLED.print("nopqrstuvwxyz", CENTER, 24);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Numbers:", LEFT, 0);
|
||||
myOLED.print("0123456789", CENTER, 16);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
|
||||
myOLED.clrScr();
|
||||
myOLED.print("Special:", LEFT, 0);
|
||||
myOLED.print("!\"#$%&'()*+,-.", CENTER, 16);
|
||||
myOLED.print("/:;<=>?@[\\]^_`", CENTER, 24);
|
||||
myOLED.print("{|}~", CENTER, 32);
|
||||
myOLED.update();
|
||||
delay (5000);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
void OLED::_convert_float(char *buf, double num, int width, byte prec)
|
||||
{
|
||||
char format[10];
|
||||
|
||||
sprintf(format, "%%%i.%if", width, prec);
|
||||
sprintf(buf, format, num);
|
||||
}
|
||||
|
||||
|
||||
void OLED::_initTWI()
|
||||
{
|
||||
if ((_sda_pin == SDA) and (_scl_pin == SCL))
|
||||
{
|
||||
twi = TWI1;
|
||||
pmc_enable_periph_clk(WIRE_INTERFACE_ID);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE_SDA].pPort, g_APinDescription[PIN_WIRE_SDA].ulPinType, g_APinDescription[PIN_WIRE_SDA].ulPin, g_APinDescription[PIN_WIRE_SDA].ulPinConfiguration);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE_SCL].pPort, g_APinDescription[PIN_WIRE_SCL].ulPinType, g_APinDescription[PIN_WIRE_SCL].ulPin, g_APinDescription[PIN_WIRE_SCL].ulPinConfiguration);
|
||||
NVIC_DisableIRQ(TWI1_IRQn);
|
||||
NVIC_ClearPendingIRQ(TWI1_IRQn);
|
||||
NVIC_SetPriority(TWI1_IRQn, 0);
|
||||
NVIC_EnableIRQ(TWI1_IRQn);
|
||||
|
||||
}
|
||||
else if ((_sda_pin == SDA1) and (_scl_pin == SCL1))
|
||||
{
|
||||
twi = TWI0;
|
||||
pmc_enable_periph_clk(WIRE1_INTERFACE_ID);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE1_SDA].pPort, g_APinDescription[PIN_WIRE1_SDA].ulPinType, g_APinDescription[PIN_WIRE1_SDA].ulPin, g_APinDescription[PIN_WIRE1_SDA].ulPinConfiguration);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE1_SCL].pPort, g_APinDescription[PIN_WIRE1_SCL].ulPinType, g_APinDescription[PIN_WIRE1_SCL].ulPin, g_APinDescription[PIN_WIRE1_SCL].ulPinConfiguration);
|
||||
NVIC_DisableIRQ(TWI0_IRQn);
|
||||
NVIC_ClearPendingIRQ(TWI0_IRQn);
|
||||
NVIC_SetPriority(TWI0_IRQn, 0);
|
||||
NVIC_EnableIRQ(TWI0_IRQn);
|
||||
}
|
||||
|
||||
// activate internal pullups for twi.
|
||||
digitalWrite(SDA, 1);
|
||||
digitalWrite(SCL, 1);
|
||||
|
||||
// Reset the TWI
|
||||
twi->TWI_CR = TWI_CR_SWRST;
|
||||
// TWI Slave Mode Disabled, TWI Master Mode Disabled.
|
||||
twi->TWI_CR = TWI_CR_SVDIS;
|
||||
twi->TWI_CR = TWI_CR_MSDIS;
|
||||
// Set TWI Speed
|
||||
twi->TWI_CWGR = (TWI_DIV << 16) | (TWI_SPEED << 8) | TWI_SPEED;
|
||||
// Set master mode
|
||||
twi->TWI_CR = TWI_CR_MSEN;
|
||||
}
|
||||
|
||||
void OLED::update()
|
||||
{
|
||||
noInterrupts();
|
||||
_sendTWIcommand(SSD1306_SET_COLUMN_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(127);
|
||||
|
||||
_sendTWIcommand(SSD1306_SET_PAGE_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(7);
|
||||
|
||||
if (_use_hw) // Send TWI Start
|
||||
{
|
||||
// Set slave address and number of internal address bytes.
|
||||
twi->TWI_MMR = (1 << 8) | (SSD1306_ADDR << 16);
|
||||
// Set internal address bytes
|
||||
twi->TWI_IADR = SSD1306_DATA_CONTINUE;
|
||||
// Send start address
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_DATA_CONTINUE);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
for (int b=0; b<1024; b++) // Send data
|
||||
if (_use_hw)
|
||||
{
|
||||
twi->TWI_THR = scrbuf[b];
|
||||
while ((twi->TWI_SR & TWI_SR_TXRDY) != TWI_SR_TXRDY) {};
|
||||
}
|
||||
else
|
||||
{
|
||||
_writeByte(scrbuf[b]);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
if (_use_hw) // Send TWI Stop
|
||||
{
|
||||
// Send STOP condition
|
||||
twi->TWI_CR = TWI_CR_STOP;
|
||||
while ((twi->TWI_SR & TWI_SR_TXCOMP) != TWI_SR_TXCOMP) {};
|
||||
}
|
||||
else
|
||||
_sendStop();
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void OLED::_sendTWIcommand(uint8_t value)
|
||||
{
|
||||
if (_use_hw)
|
||||
{
|
||||
// Set slave address and number of internal address bytes.
|
||||
twi->TWI_MMR = (1 << 8) | (SSD1306_ADDR << 16);
|
||||
// Set internal address bytes
|
||||
twi->TWI_IADR = SSD1306_COMMAND;
|
||||
|
||||
twi->TWI_THR = value;
|
||||
while ((twi->TWI_SR & TWI_SR_TXRDY) != TWI_SR_TXRDY) {};
|
||||
|
||||
// Send STOP condition
|
||||
twi->TWI_CR = TWI_CR_STOP;
|
||||
while ((twi->TWI_SR & TWI_SR_TXCOMP) != TWI_SR_TXCOMP) {};
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_COMMAND);
|
||||
_waitForAck();
|
||||
_writeByte(value);
|
||||
_waitForAck();
|
||||
_sendStop();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// *** Hardwarespecific defines ***
|
||||
#define cbi(reg, bitmask) *reg &= ~bitmask
|
||||
#define sbi(reg, bitmask) *reg |= bitmask
|
||||
#define pulseClock cbi(P_SCK, B_SCK); asm ("nop"); sbi(P_SCK, B_SCK)
|
||||
|
||||
#define fontbyte(x) cfont.font[x]
|
||||
#define bitmapbyte(x) bitmap[x]
|
||||
|
||||
#define bitmapdatatype unsigned char*
|
||||
|
||||
#define SDA 20
|
||||
#define SCL 21
|
||||
#define SDA1 70
|
||||
#define SCL1 71
|
||||
|
||||
#define TWI_SPEED TWI_SPEED_400k // Set default TWI Speed
|
||||
#define TWI_SPEED_100k 208
|
||||
#define TWI_SPEED_400k 101
|
||||
|
||||
#define TWI_DIV TWI_DIV_400k // Set divider for TWI Speed (must match TWI_SPEED setting)
|
||||
#define TWI_DIV_100k 1
|
||||
#define TWI_DIV_400k 0
|
|
@ -0,0 +1,168 @@
|
|||
#include "HardWire.h"
|
||||
#define WIRE_WRITE HWIRE.write
|
||||
|
||||
HardWire HWIRE(2,I2C_FAST_MODE); // stupid compiler
|
||||
|
||||
void OLED::_convert_float(char *buf, double num, int width, byte prec)
|
||||
{
|
||||
char format[10];
|
||||
|
||||
sprintf(format, "%%%i.%if", width, prec);
|
||||
sprintf(buf, format, num);
|
||||
}
|
||||
|
||||
|
||||
void OLED::_initTWI()
|
||||
{
|
||||
if ((_sda_pin == SDA) and (_scl_pin == SCL))
|
||||
{
|
||||
|
||||
// HardWire HWIRE(1,I2C_FAST_MODE); // I2c1
|
||||
|
||||
HWIRE.begin();
|
||||
/*
|
||||
twi = TWI1;
|
||||
|
||||
pmc_enable_periph_clk(WIRE_INTERFACE_ID);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE_SDA].pPort, g_APinDescription[PIN_WIRE_SDA].ulPinType, g_APinDescription[PIN_WIRE_SDA].ulPin, g_APinDescription[PIN_WIRE_SDA].ulPinConfiguration);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE_SCL].pPort, g_APinDescription[PIN_WIRE_SCL].ulPinType, g_APinDescription[PIN_WIRE_SCL].ulPin, g_APinDescription[PIN_WIRE_SCL].ulPinConfiguration);
|
||||
NVIC_DisableIRQ(TWI1_IRQn);
|
||||
NVIC_ClearPendingIRQ(TWI1_IRQn);
|
||||
NVIC_SetPriority(TWI1_IRQn, 0);
|
||||
NVIC_EnableIRQ(TWI1_IRQn);
|
||||
*/
|
||||
|
||||
}
|
||||
else if ((_sda_pin == SDA1) and (_scl_pin == SCL1))
|
||||
{
|
||||
HWIRE.begin();
|
||||
// I2c2
|
||||
// HardWire HWIRE(2,I2C_FAST_MODE);
|
||||
// HWIRE.begin();
|
||||
|
||||
/*
|
||||
twi = TWI0;
|
||||
|
||||
pmc_enable_periph_clk(WIRE1_INTERFACE_ID);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE1_SDA].pPort, g_APinDescription[PIN_WIRE1_SDA].ulPinType, g_APinDescription[PIN_WIRE1_SDA].ulPin, g_APinDescription[PIN_WIRE1_SDA].ulPinConfiguration);
|
||||
PIO_Configure(g_APinDescription[PIN_WIRE1_SCL].pPort, g_APinDescription[PIN_WIRE1_SCL].ulPinType, g_APinDescription[PIN_WIRE1_SCL].ulPin, g_APinDescription[PIN_WIRE1_SCL].ulPinConfiguration);
|
||||
NVIC_DisableIRQ(TWI0_IRQn);
|
||||
NVIC_ClearPendingIRQ(TWI0_IRQn);
|
||||
NVIC_SetPriority(TWI0_IRQn, 0);
|
||||
NVIC_EnableIRQ(TWI0_IRQn);
|
||||
*/
|
||||
}
|
||||
|
||||
// activate internal pullups for twi.
|
||||
// digitalWrite(SDA, 1);
|
||||
//digitalWrite(SCL, 1);
|
||||
/*
|
||||
// Reset the TWI
|
||||
twi->TWI_CR = TWI_CR_SWRST;
|
||||
// TWI Slave Mode Disabled, TWI Master Mode Disabled.
|
||||
twi->TWI_CR = TWI_CR_SVDIS;
|
||||
twi->TWI_CR = TWI_CR_MSDIS;
|
||||
// Set TWI Speed
|
||||
twi->TWI_CWGR = (TWI_DIV << 16) | (TWI_SPEED << 8) | TWI_SPEED;
|
||||
// Set master mode
|
||||
twi->TWI_CR = TWI_CR_MSEN;
|
||||
*/
|
||||
}
|
||||
|
||||
void OLED::update()
|
||||
{
|
||||
//noInterrupts();
|
||||
_sendTWIcommand(SSD1306_SET_COLUMN_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(127);
|
||||
|
||||
_sendTWIcommand(SSD1306_SET_PAGE_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(7);
|
||||
|
||||
if (_use_hw) // Send TWI Start
|
||||
{
|
||||
HWIRE.beginTransmission(SSD1306_ADDR);
|
||||
WIRE_WRITE(SSD1306_DATA_CONTINUE);
|
||||
/*
|
||||
// Set slave address and number of internal address bytes.
|
||||
twi->TWI_MMR = (1 << 8) | (SSD1306_ADDR << 16);
|
||||
// Set internal address bytes
|
||||
twi->TWI_IADR = SSD1306_DATA_CONTINUE;
|
||||
// Send start address
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_DATA_CONTINUE);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
for (int b=0; b<1024; b++) // Send data
|
||||
if (_use_hw)
|
||||
{
|
||||
/*
|
||||
twi->TWI_THR = scrbuf[b];
|
||||
while ((twi->TWI_SR & TWI_SR_TXRDY) != TWI_SR_TXRDY) {};
|
||||
*/
|
||||
static byte aa=scrbuf[b];
|
||||
WIRE_WRITE(aa);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_writeByte(scrbuf[b]);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
if (_use_hw) // Send TWI Stop
|
||||
{
|
||||
HWIRE.endTransmission();
|
||||
/*
|
||||
// Send STOP condition
|
||||
twi->TWI_CR = TWI_CR_STOP;
|
||||
while ((twi->TWI_SR & TWI_SR_TXCOMP) != TWI_SR_TXCOMP) {};
|
||||
*/
|
||||
}
|
||||
else
|
||||
_sendStop();
|
||||
//interrupts();
|
||||
}
|
||||
|
||||
void OLED::_sendTWIcommand(uint8_t value)
|
||||
{
|
||||
if (_use_hw)
|
||||
{
|
||||
HWIRE.beginTransmission(SSD1306_ADDR);
|
||||
WIRE_WRITE(SSD1306_COMMAND);
|
||||
WIRE_WRITE(value);
|
||||
HWIRE.endTransmission();
|
||||
/*
|
||||
// Set slave address and number of internal address bytes.
|
||||
twi->TWI_MMR = (1 << 8) | (SSD1306_ADDR << 16);
|
||||
// Set internal address bytes
|
||||
twi->TWI_IADR = SSD1306_COMMAND;
|
||||
|
||||
twi->TWI_THR = value;
|
||||
while ((twi->TWI_SR & TWI_SR_TXRDY) != TWI_SR_TXRDY) {};
|
||||
|
||||
// Send STOP condition
|
||||
twi->TWI_CR = TWI_CR_STOP;
|
||||
while ((twi->TWI_SR & TWI_SR_TXCOMP) != TWI_SR_TXCOMP) {};
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_COMMAND);
|
||||
_waitForAck();
|
||||
_writeByte(value);
|
||||
_waitForAck();
|
||||
_sendStop();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// *** Hardwarespecific defines ***
|
||||
#define cbi(reg, bitmask) *reg &= ~bitmask
|
||||
#define sbi(reg, bitmask) *reg |= bitmask
|
||||
#define pulseClock cbi(P_SCK, B_SCK); asm ("nop"); sbi(P_SCK, B_SCK)
|
||||
|
||||
#define fontbyte(x) cfont.font[x]
|
||||
#define bitmapbyte(x) bitmap[x]
|
||||
|
||||
#define bitmapdatatype unsigned char*
|
||||
|
||||
#define SDA1 0
|
||||
#define SCL1 1
|
||||
#define SDA 15
|
||||
#define SCL 16
|
||||
|
||||
#define TWI_SPEED TWI_SPEED_400k // Set default TWI Speed
|
||||
#define TWI_SPEED_100k 208
|
||||
#define TWI_SPEED_400k 101
|
||||
|
||||
#define TWI_DIV TWI_DIV_400k // Set divider for TWI Speed (must match TWI_SPEED setting)
|
||||
#define TWI_DIV_100k 1
|
||||
#define TWI_DIV_400k 0
|
|
@ -0,0 +1,103 @@
|
|||
void OLED::_convert_float(char *buf, double num, int width, byte prec)
|
||||
{
|
||||
dtostrf(num, width, prec, buf);
|
||||
}
|
||||
|
||||
void OLED::_initTWI()
|
||||
{
|
||||
// activate internal pullups for twi.
|
||||
digitalWrite(SDA, HIGH);
|
||||
digitalWrite(SCL, HIGH);
|
||||
//delay(1); // Workaround for a linker bug
|
||||
|
||||
// initialize twi prescaler and bit rate
|
||||
__cbi2(TWSR, TWPS0);
|
||||
__cbi2(TWSR, TWPS1);
|
||||
TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
|
||||
|
||||
// enable twi module, acks, and twi interrupt
|
||||
TWCR = _BV(TWEN) | _BV(TWIE)/* | _BV(TWEA)*/;
|
||||
}
|
||||
|
||||
void OLED::update()
|
||||
{
|
||||
noInterrupts();
|
||||
_sendTWIcommand(SSD1306_SET_COLUMN_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(127);
|
||||
|
||||
_sendTWIcommand(SSD1306_SET_PAGE_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(7);
|
||||
|
||||
if (_use_hw) // Send TWI Start
|
||||
{
|
||||
// Send start address
|
||||
TWCR = _BV(TWEN) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);
|
||||
while ((TWCR & _BV(TWINT)) == 0) {};
|
||||
TWDR = SSD1306_ADDR<<1;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWEA);
|
||||
while ((TWCR & _BV(TWINT)) == 0) {};
|
||||
TWDR = SSD1306_DATA_CONTINUE;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWEA);
|
||||
while ((TWCR & _BV(TWINT)) == 0) {};
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_DATA_CONTINUE);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
for (int b=0; b<1024; b++) // Send data
|
||||
if (_use_hw)
|
||||
{
|
||||
TWDR = scrbuf[b];
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWEA); // Clear TWINT to proceed
|
||||
while ((TWCR & _BV(TWINT)) == 0) {}; // Wait for TWI to be ready
|
||||
}
|
||||
else
|
||||
{
|
||||
_writeByte(scrbuf[b]);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
if (_use_hw) // Send TWI Stop
|
||||
TWCR = _BV(TWEN)| _BV(TWINT) | _BV(TWSTO); // Send STOP
|
||||
else
|
||||
_sendStop();
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void OLED::_sendTWIcommand(uint8_t value)
|
||||
{
|
||||
if (_use_hw)
|
||||
{
|
||||
// Send start address
|
||||
TWCR = _BV(TWEN) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA); // Send START
|
||||
while ((TWCR & _BV(TWINT)) == 0) {}; // Wait for TWI to be ready
|
||||
TWDR = SSD1306_ADDR<<1;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWEA); // Clear TWINT to proceed
|
||||
while ((TWCR & _BV(TWINT)) == 0) {}; // Wait for TWI to be ready
|
||||
|
||||
TWDR = SSD1306_COMMAND;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWEA); // Clear TWINT to proceed
|
||||
while ((TWCR & _BV(TWINT)) == 0) {}; // Wait for TWI to be ready
|
||||
TWDR = value;
|
||||
TWCR = _BV(TWEN) | _BV(TWINT) | _BV(TWEA); // Clear TWINT to proceed
|
||||
while ((TWCR & _BV(TWINT)) == 0) {}; // Wait for TWI to be ready
|
||||
|
||||
TWCR = _BV(TWEN)| _BV(TWINT) | _BV(TWSTO); // Send STOP
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_COMMAND);
|
||||
_waitForAck();
|
||||
_writeByte(value);
|
||||
_waitForAck();
|
||||
_sendStop();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
// *** Hardwarespecific defines ***
|
||||
#define __cbi(reg, bitmask) *reg &= ~bitmask
|
||||
#define __cbi2(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
||||
#define __sbi(reg, bitmask) *reg |= bitmask
|
||||
#define pulseClock __cbi(P_SCK, B_SCK); asm ("nop"); __sbi(P_SCK, B_SCK)
|
||||
|
||||
#define fontbyte(x) pgm_read_byte(&cfont.font[x])
|
||||
#define bitmapbyte(x) pgm_read_byte(&bitmap[x])
|
||||
|
||||
#define bitmapdatatype uint8_t*
|
||||
|
||||
#ifndef TWI_FREQ
|
||||
#define TWI_FREQ 400000L
|
||||
#endif
|
|
@ -0,0 +1,121 @@
|
|||
void OLED::_convert_float(char *buf, double num, int width, byte prec)
|
||||
{
|
||||
char format[10];
|
||||
|
||||
sprintf(format, "%%%i.%if", width, prec);
|
||||
sprintf(buf, format, num);
|
||||
}
|
||||
|
||||
inline void _waitForIdleBus() { while (I2C1CON & 0x1f) {} }
|
||||
|
||||
void OLED::_initTWI()
|
||||
{
|
||||
uint32_t tpgd;
|
||||
|
||||
pinMode(SDA, OUTPUT);
|
||||
digitalWrite(SDA, HIGH);
|
||||
IFS0CLR = 0xE0000000; // Clear Interrupt Flag
|
||||
IEC0CLR = 0xE0000000; // Disable Interrupt
|
||||
I2C1CONCLR = (1 << _I2CCON_ON); // Disable I2C interface
|
||||
tpgd = ((F_CPU / 8) * 104) / 125000000;
|
||||
I2C1BRG = (F_CPU / (2 * TWI_FREQ) - tpgd) - 2; // Set I2C Speed
|
||||
I2C1ADD = SSD1306_ADDR; // Set I2C device address
|
||||
I2C1CONSET = (1 << _I2CCON_ON) | (1 << _I2CCON_STREN); // Enable I2C Interface
|
||||
}
|
||||
|
||||
void OLED::update()
|
||||
{
|
||||
noInterrupts();
|
||||
_sendTWIcommand(SSD1306_SET_COLUMN_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(127);
|
||||
|
||||
_sendTWIcommand(SSD1306_SET_PAGE_ADDR);
|
||||
_sendTWIcommand(0);
|
||||
_sendTWIcommand(7);
|
||||
|
||||
if (_use_hw) // Send TWI Start
|
||||
{
|
||||
_waitForIdleBus(); // Wait for I2C bus to be Idle before starting
|
||||
I2C1CONSET = (1 << _I2CCON_SEN); // Send start condition
|
||||
if (I2C1STAT & (1 << _I2CSTAT_BCL)) { return; } // Check if there is a bus collision
|
||||
while (I2C1CON & (1 << _I2CCON_SEN)) {} // Wait for start condition to finish
|
||||
I2C1TRN = (SSD1306_ADDR<<1); // Send device Write address
|
||||
while (I2C1STAT & (1 << _I2CSTAT_IWCOL)) // Check if there is a Write collision
|
||||
{
|
||||
I2C1STATCLR = (1 << _I2CSTAT_IWCOL); // Clear Write collision flag
|
||||
I2C1TRN = (SSD1306_ADDR<<1); // Retry send device Write address
|
||||
}
|
||||
while (I2C1STAT & (1 << _I2CSTAT_TRSTAT)) {} // Wait for transmit to finish
|
||||
while (I2C1STAT & (1 << _I2CSTAT_ACKSTAT)) {} // Wait for ACK
|
||||
I2C1TRN = SSD1306_DATA_CONTINUE; // Send the command for continous data
|
||||
while (I2C1STAT & (1 << _I2CSTAT_TRSTAT)) {} // Wait for transmit to finish
|
||||
while (I2C1STAT & (1 << _I2CSTAT_ACKSTAT)) {} // Wait for ACK
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_DATA_CONTINUE);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
for (int b=0; b<1024; b++) // Send data
|
||||
if (_use_hw)
|
||||
{
|
||||
I2C1TRN = scrbuf[b];
|
||||
while (I2C1STAT & (1 << _I2CSTAT_TRSTAT)) {}
|
||||
while (I2C1STAT & (1 << _I2CSTAT_ACKSTAT)) {}
|
||||
}
|
||||
else
|
||||
{
|
||||
_writeByte(scrbuf[b]);
|
||||
_waitForAck();
|
||||
}
|
||||
|
||||
if (_use_hw) // Send TWI Stop
|
||||
{
|
||||
I2C1CONSET = (1 << _I2CCON_PEN); // Send stop condition
|
||||
while (I2C1CON & (1 << _I2CCON_PEN)) {} // Wait for stop condition to finish
|
||||
}
|
||||
else
|
||||
_sendStop();
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void OLED::_sendTWIcommand(uint8_t value)
|
||||
{
|
||||
if (_use_hw)
|
||||
{
|
||||
_waitForIdleBus(); // Wait for I2C bus to be Idle before starting
|
||||
I2C1CONSET = (1 << _I2CCON_SEN); // Send start condition
|
||||
if (I2C1STAT & (1 << _I2CSTAT_BCL)) { return; } // Check if there is a bus collision
|
||||
while (I2C1CON & (1 << _I2CCON_SEN)) {} // Wait for start condition to finish
|
||||
I2C1TRN = (SSD1306_ADDR<<1); // Send device Write address
|
||||
while (I2C1STAT & (1 << _I2CSTAT_IWCOL)) // Check if there is a Write collision
|
||||
{
|
||||
I2C1STATCLR = (1 << _I2CSTAT_IWCOL); // Clear Write collision flag
|
||||
I2C1TRN = (SSD1306_ADDR<<1); // Retry send device Write address
|
||||
}
|
||||
while (I2C1STAT & (1 << _I2CSTAT_TRSTAT)) {} // Wait for transmit to finish
|
||||
while (I2C1STAT & (1 << _I2CSTAT_ACKSTAT)) {} // Wait for ACK
|
||||
I2C1TRN = SSD1306_COMMAND; // Send the 1st data byte
|
||||
while (I2C1STAT & (1 << _I2CSTAT_TRSTAT)) {} // Wait for transmit to finish
|
||||
while (I2C1STAT & (1 << _I2CSTAT_ACKSTAT)) {} // Wait for ACK
|
||||
I2C1TRN = value; // Send the 2nd data byte
|
||||
while (I2C1STAT & (1 << _I2CSTAT_TRSTAT)) {} // Wait for transmit to finish
|
||||
while (I2C1STAT & (1 << _I2CSTAT_ACKSTAT)) {} // Wait for ACK
|
||||
I2C1CONSET = (1 << _I2CCON_PEN); // Send stop condition
|
||||
while (I2C1CON & (1 << _I2CCON_PEN)) {} // Wait for stop condition to finish
|
||||
}
|
||||
else
|
||||
{
|
||||
_sendStart(SSD1306_ADDR<<1);
|
||||
_waitForAck();
|
||||
_writeByte(SSD1306_COMMAND);
|
||||
_waitForAck();
|
||||
_writeByte(value);
|
||||
_waitForAck();
|
||||
_sendStop();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// *** Hardwarespecific defines ***
|
||||
#define __cbi(reg, bitmask) (*(reg + 1)) = bitmask
|
||||
#define __sbi(reg, bitmask) (*(reg + 2)) = bitmask
|
||||
#define pulseClock digitalWrite(SCK_Pin, LOW); digitalWrite(SCK_Pin, HIGH)
|
||||
|
||||
#define fontbyte(x) cfont.font[x]
|
||||
#define bitmapbyte(x) bitmap[x]
|
||||
|
||||
#define PROGMEM
|
||||
#define bitmapdatatype unsigned char*
|
||||
|
||||
#if !defined(_UP_MCU_)
|
||||
#if defined(__32MX320F128H__)
|
||||
#define SDA 18 // A4 (Remeber to set the jumper correctly)
|
||||
#define SCL 19 // A5 (Remeber to set the jumper correctly)
|
||||
#elif defined(__32MX340F512H__)
|
||||
#define SDA 18 // A4 (Remeber to set the jumper correctly)
|
||||
#define SCL 19 // A5 (Remeber to set the jumper correctly)
|
||||
#elif defined(__32MX795F512L__)
|
||||
#define SDA 20 // Digital 20
|
||||
#define SCL 21 // Digital 21
|
||||
#else
|
||||
#error "Unsupported PIC32 MCU!"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef TWI_FREQ
|
||||
#define TWI_FREQ 400000L
|
||||
#endif
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
OLED KEYWORD1
|
||||
|
||||
begin KEYWORD2
|
||||
setBrightness KEYWORD2
|
||||
update KEYWORD2
|
||||
clrScr KEYWORD2
|
||||
fillScr KEYWORD2
|
||||
invert KEYWORD2
|
||||
setPixel KEYWORD2
|
||||
clrPixel KEYWORD2
|
||||
invPixel KEYWORD2
|
||||
invertText KEYWORD2
|
||||
print KEYWORD2
|
||||
printNumI KEYWORD2
|
||||
printNumF KEYWORD2
|
||||
setFont KEYWORD2
|
||||
drawBitmap KEYWORD2
|
||||
drawLine KEYWORD2
|
||||
clrLine KEYWORD2
|
||||
drawRect KEYWORD2
|
||||
clrRect KEYWORD2
|
||||
drawRoundRect KEYWORD2
|
||||
clrRoundRect KEYWORD2
|
||||
drawCircle KEYWORD2
|
||||
clrCircle KEYWORD2
|
||||
|
||||
LEFT LITERAL1
|
||||
RIGHT LITERAL1
|
||||
CENTER LITERAL1
|
||||
|
||||
RST_NOT_IN_USE LITERAL1
|
Loading…
Reference in New Issue