Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c63ee9bd9 | ||
|
|
1d0c5a4a73 | ||
|
|
7097afb14a | ||
|
|
521daecd91 | ||
|
|
47c83e929a | ||
|
|
cd4ff4fd25 |
4 changed files with 604 additions and 868 deletions
|
|
@ -1,379 +1,126 @@
|
|||
/***************************************************
|
||||
This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/684
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_SSD1331.h"
|
||||
#include "glcdfont.c"
|
||||
|
||||
#ifdef __AVR
|
||||
#include <avr/pgmspace.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <pgmspace.h>
|
||||
#endif
|
||||
|
||||
#include "pins_arduino.h"
|
||||
#include "wiring_private.h"
|
||||
#include <SPI.h>
|
||||
|
||||
/********************************** low level pin interface */
|
||||
|
||||
inline void Adafruit_SSD1331::spiwrite(uint8_t c) {
|
||||
|
||||
if (!_sid) {
|
||||
SPI.transfer(c);
|
||||
return;
|
||||
}
|
||||
|
||||
int8_t i;
|
||||
|
||||
*sclkportreg |= sclkpin;
|
||||
|
||||
for (i=7; i>=0; i--) {
|
||||
*sclkportreg &= ~sclkpin;
|
||||
//SCLK_PORT &= ~_BV(SCLK);
|
||||
|
||||
if (c & _BV(i)) {
|
||||
*sidportreg |= sidpin;
|
||||
//digitalWrite(_sid, HIGH);
|
||||
//SID_PORT |= _BV(SID);
|
||||
} else {
|
||||
*sidportreg &= ~sidpin;
|
||||
//digitalWrite(_sid, LOW);
|
||||
//SID_PORT &= ~_BV(SID);
|
||||
}
|
||||
|
||||
*sclkportreg |= sclkpin;
|
||||
//SCLK_PORT |= _BV(SCLK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_SSD1331::writeCommand(uint8_t c) {
|
||||
*rsportreg &= ~ rspin;
|
||||
//digitalWrite(_rs, LOW);
|
||||
|
||||
*csportreg &= ~ cspin;
|
||||
//digitalWrite(_cs, LOW);
|
||||
|
||||
//Serial.print("C ");
|
||||
spiwrite(c);
|
||||
|
||||
*csportreg |= cspin;
|
||||
//digitalWrite(_cs, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_SSD1331::writeData(uint8_t c) {
|
||||
*rsportreg |= rspin;
|
||||
//digitalWrite(_rs, HIGH);
|
||||
|
||||
*csportreg &= ~ cspin;
|
||||
//digitalWrite(_cs, LOW);
|
||||
|
||||
//Serial.print("D ");
|
||||
spiwrite(c);
|
||||
|
||||
*csportreg |= cspin;
|
||||
//digitalWrite(_cs, HIGH);
|
||||
}
|
||||
|
||||
/***********************************/
|
||||
|
||||
void Adafruit_SSD1331::goHome(void) {
|
||||
goTo(0,0);
|
||||
}
|
||||
|
||||
void Adafruit_SSD1331::goTo(int x, int y) {
|
||||
if ((x >= WIDTH) || (y >= HEIGHT)) return;
|
||||
|
||||
// set x and y coordinate
|
||||
writeCommand(SSD1331_CMD_SETCOLUMN);
|
||||
writeCommand(x);
|
||||
writeCommand(WIDTH-1);
|
||||
|
||||
writeCommand(SSD1331_CMD_SETROW);
|
||||
writeCommand(y);
|
||||
writeCommand(HEIGHT-1);
|
||||
}
|
||||
|
||||
uint16_t Adafruit_SSD1331::Color565(uint8_t r, uint8_t g, uint8_t b) {
|
||||
uint16_t c;
|
||||
c = r >> 3;
|
||||
c <<= 6;
|
||||
c |= g >> 2;
|
||||
c <<= 5;
|
||||
c |= b >> 3;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Draws a filled rectangle using HW acceleration
|
||||
*/
|
||||
/**************************************************************************/
|
||||
/*
|
||||
void Adafruit_SSD1331::fillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor)
|
||||
{
|
||||
//Serial.println("fillRect");
|
||||
// check rotation, move rect around if necessary
|
||||
switch (getRotation()) {
|
||||
case 1:
|
||||
swap(x, y);
|
||||
swap(w, h);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
swap(x, y);
|
||||
swap(w, h);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// Bounds check
|
||||
if ((x >= TFTWIDTH) || (y >= TFTHEIGHT))
|
||||
return;
|
||||
|
||||
// Y bounds check
|
||||
if (y+h > TFTHEIGHT)
|
||||
{
|
||||
h = TFTHEIGHT - y;
|
||||
}
|
||||
|
||||
// X bounds check
|
||||
if (x+w > TFTWIDTH)
|
||||
{
|
||||
w = TFTWIDTH - x;
|
||||
}
|
||||
|
||||
// fill!
|
||||
writeCommand(SSD1331_CMD_FILL);
|
||||
writeCommand(0x01);
|
||||
|
||||
writeCommand(SSD1331_CMD_DRAWRECT);
|
||||
writeCommand(x & 0xFF); // Starting column
|
||||
writeCommand(y & 0xFF); // Starting row
|
||||
writeCommand((x+w-1) & 0xFF); // End column
|
||||
writeCommand((y+h-1) & 0xFF); // End row
|
||||
|
||||
// Outline color
|
||||
writeCommand((uint8_t)((fillcolor >> 11) << 1));
|
||||
writeCommand((uint8_t)((fillcolor >> 5) & 0x3F));
|
||||
writeCommand((uint8_t)((fillcolor << 1) & 0x3F));
|
||||
// Fill color
|
||||
writeCommand((uint8_t)((fillcolor >> 11) << 1));
|
||||
writeCommand((uint8_t)((fillcolor >> 5) & 0x3F));
|
||||
writeCommand((uint8_t)((fillcolor << 1) & 0x3F));
|
||||
|
||||
// Delay while the fill completes
|
||||
delay(SSD1331_DELAYS_HWFILL);
|
||||
}
|
||||
*/
|
||||
|
||||
void Adafruit_SSD1331::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
|
||||
// check rotation, move pixel around if necessary
|
||||
switch (getRotation()) {
|
||||
case 1:
|
||||
gfx_swap(x0, y0);
|
||||
gfx_swap(x1, y1);
|
||||
x0 = WIDTH - x0 - 1;
|
||||
x1 = WIDTH - x1 - 1;
|
||||
break;
|
||||
case 2:
|
||||
x0 = WIDTH - x0 - 1;
|
||||
y0 = HEIGHT - y0 - 1;
|
||||
x1 = WIDTH - x1 - 1;
|
||||
y1 = HEIGHT - y1 - 1;
|
||||
break;
|
||||
case 3:
|
||||
gfx_swap(x0, y0);
|
||||
gfx_swap(x1, y1);
|
||||
y0 = HEIGHT - y0 - 1;
|
||||
y1 = HEIGHT - y1 - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// Boundary check
|
||||
if ((y0 >= TFTHEIGHT) && (y1 >= TFTHEIGHT))
|
||||
return;
|
||||
if ((x0 >= TFTWIDTH) && (x1 >= TFTWIDTH))
|
||||
return;
|
||||
if (x0 >= TFTWIDTH)
|
||||
x0 = TFTWIDTH - 1;
|
||||
if (y0 >= TFTHEIGHT)
|
||||
y0 = TFTHEIGHT - 1;
|
||||
if (x1 >= TFTWIDTH)
|
||||
x1 = TFTWIDTH - 1;
|
||||
if (y1 >= TFTHEIGHT)
|
||||
y1 = TFTHEIGHT - 1;
|
||||
|
||||
writeCommand(SSD1331_CMD_DRAWLINE);
|
||||
writeCommand(x0);
|
||||
writeCommand(y0);
|
||||
writeCommand(x1);
|
||||
writeCommand(y1);
|
||||
delay(SSD1331_DELAYS_HWLINE);
|
||||
writeCommand((uint8_t)((color >> 11) << 1));
|
||||
writeCommand((uint8_t)((color >> 5) & 0x3F));
|
||||
writeCommand((uint8_t)((color << 1) & 0x3F));
|
||||
delay(SSD1331_DELAYS_HWLINE);
|
||||
}
|
||||
|
||||
void Adafruit_SSD1331::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:
|
||||
gfx_swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
gfx_swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
goTo(x, y);
|
||||
|
||||
// setup for data
|
||||
*rsportreg |= rspin;
|
||||
*csportreg &= ~ cspin;
|
||||
|
||||
spiwrite(color >> 8);
|
||||
spiwrite(color);
|
||||
|
||||
*csportreg |= cspin;
|
||||
}
|
||||
|
||||
void Adafruit_SSD1331::pushColor(uint16_t color) {
|
||||
// setup for data
|
||||
*rsportreg |= rspin;
|
||||
*csportreg &= ~ cspin;
|
||||
|
||||
spiwrite(color >> 8);
|
||||
spiwrite(color);
|
||||
|
||||
*csportreg |= cspin;
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_SSD1331::begin(void) {
|
||||
// set pin directions
|
||||
pinMode(_rs, OUTPUT);
|
||||
|
||||
if (_sclk) {
|
||||
pinMode(_sclk, OUTPUT);
|
||||
sclkportreg = portOutputRegister(digitalPinToPort(_sclk));
|
||||
sclkpin = digitalPinToBitMask(_sclk);
|
||||
|
||||
pinMode(_sid, OUTPUT);
|
||||
sidportreg = portOutputRegister(digitalPinToPort(_sid));
|
||||
sidpin = digitalPinToBitMask(_sid);
|
||||
} else {
|
||||
// using the hardware SPI
|
||||
SPI.begin();
|
||||
SPI.setDataMode(SPI_MODE3);
|
||||
}
|
||||
|
||||
// Toggle RST low to reset; CS low so it'll listen to us
|
||||
pinMode(_cs, OUTPUT);
|
||||
digitalWrite(_cs, LOW);
|
||||
cspin = digitalPinToBitMask(_cs);
|
||||
csportreg = portOutputRegister(digitalPinToPort(_cs));
|
||||
|
||||
rspin = digitalPinToBitMask(_rs);
|
||||
rsportreg = portOutputRegister(digitalPinToPort(_rs));
|
||||
|
||||
if (_rst) {
|
||||
pinMode(_rst, OUTPUT);
|
||||
digitalWrite(_rst, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(_rst, LOW);
|
||||
delay(500);
|
||||
digitalWrite(_rst, HIGH);
|
||||
delay(500);
|
||||
}
|
||||
// Initialization Sequence
|
||||
writeCommand(SSD1331_CMD_DISPLAYOFF); // 0xAE
|
||||
writeCommand(SSD1331_CMD_SETREMAP); // 0xA0
|
||||
#if defined SSD1331_COLORORDER_RGB
|
||||
writeCommand(0x72); // RGB Color
|
||||
#else
|
||||
writeCommand(0x76); // BGR Color
|
||||
#endif
|
||||
writeCommand(SSD1331_CMD_STARTLINE); // 0xA1
|
||||
writeCommand(0x0);
|
||||
writeCommand(SSD1331_CMD_DISPLAYOFFSET); // 0xA2
|
||||
writeCommand(0x0);
|
||||
writeCommand(SSD1331_CMD_NORMALDISPLAY); // 0xA4
|
||||
writeCommand(SSD1331_CMD_SETMULTIPLEX); // 0xA8
|
||||
writeCommand(0x3F); // 0x3F 1/64 duty
|
||||
writeCommand(SSD1331_CMD_SETMASTER); // 0xAD
|
||||
writeCommand(0x8E);
|
||||
writeCommand(SSD1331_CMD_POWERMODE); // 0xB0
|
||||
writeCommand(0x0B);
|
||||
writeCommand(SSD1331_CMD_PRECHARGE); // 0xB1
|
||||
writeCommand(0x31);
|
||||
writeCommand(SSD1331_CMD_CLOCKDIV); // 0xB3
|
||||
writeCommand(0xF0); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
|
||||
writeCommand(SSD1331_CMD_PRECHARGEA); // 0x8A
|
||||
writeCommand(0x64);
|
||||
writeCommand(SSD1331_CMD_PRECHARGEB); // 0x8B
|
||||
writeCommand(0x78);
|
||||
writeCommand(SSD1331_CMD_PRECHARGEA); // 0x8C
|
||||
writeCommand(0x64);
|
||||
writeCommand(SSD1331_CMD_PRECHARGELEVEL); // 0xBB
|
||||
writeCommand(0x3A);
|
||||
writeCommand(SSD1331_CMD_VCOMH); // 0xBE
|
||||
writeCommand(0x3E);
|
||||
writeCommand(SSD1331_CMD_MASTERCURRENT); // 0x87
|
||||
writeCommand(0x06);
|
||||
writeCommand(SSD1331_CMD_CONTRASTA); // 0x81
|
||||
writeCommand(0x91);
|
||||
writeCommand(SSD1331_CMD_CONTRASTB); // 0x82
|
||||
writeCommand(0x50);
|
||||
writeCommand(SSD1331_CMD_CONTRASTC); // 0x83
|
||||
writeCommand(0x7D);
|
||||
writeCommand(SSD1331_CMD_DISPLAYON); //--turn on oled panel
|
||||
}
|
||||
|
||||
/********************************* low level pin initialization */
|
||||
|
||||
Adafruit_SSD1331::Adafruit_SSD1331(uint8_t cs, uint8_t rs, uint8_t sid, uint8_t sclk, uint8_t rst) : Adafruit_GFX(TFTWIDTH, TFTHEIGHT) {
|
||||
_cs = cs;
|
||||
_rs = rs;
|
||||
_sid = sid;
|
||||
_sclk = sclk;
|
||||
_rst = rst;
|
||||
}
|
||||
|
||||
Adafruit_SSD1331::Adafruit_SSD1331(uint8_t cs, uint8_t rs, uint8_t rst) : Adafruit_GFX(TFTWIDTH, TFTHEIGHT) {
|
||||
_cs = cs;
|
||||
_rs = rs;
|
||||
_sid = 0;
|
||||
_sclk = 0;
|
||||
_rst = rst;
|
||||
}
|
||||
/***************************************************
|
||||
This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/684
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include "Adafruit_SSD1331.h"
|
||||
#include "pins_arduino.h"
|
||||
#include "wiring_private.h"
|
||||
|
||||
/***********************************/
|
||||
|
||||
|
||||
void Adafruit_SSD1331::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
|
||||
uint8_t x1 = x;
|
||||
uint8_t y1 = y;
|
||||
if (x1 > 95) x1 = 95;
|
||||
if (y1 > 63) y1 = 63;
|
||||
|
||||
uint8_t x2 = (x+w-1);
|
||||
uint8_t y2 = (y+h-1);
|
||||
if (x2 > 95) x2 = 95;
|
||||
if (y2 > 63) y2 = 63;
|
||||
|
||||
if (x1 > x2) {
|
||||
uint8_t t = x2;
|
||||
x2 = x1;
|
||||
x1 = t;
|
||||
}
|
||||
if (y1 > y2) {
|
||||
uint8_t t = y2;
|
||||
y2 = y1;
|
||||
y1 = t;
|
||||
}
|
||||
|
||||
|
||||
startWrite();
|
||||
writeCommand(0x15); // Column addr set
|
||||
writeCommand(x1);
|
||||
writeCommand(x2);
|
||||
endWrite();
|
||||
|
||||
startWrite();
|
||||
writeCommand(0x75); // Column addr set
|
||||
writeCommand(y1);
|
||||
writeCommand(y2);
|
||||
endWrite();
|
||||
|
||||
startWrite();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Adafruit_SSD1331::begin(uint32_t freq) {
|
||||
initSPI(freq);
|
||||
|
||||
startWrite();
|
||||
|
||||
// Initialization Sequence
|
||||
writeCommand(SSD1331_CMD_DISPLAYOFF); // 0xAE
|
||||
writeCommand(SSD1331_CMD_SETREMAP); // 0xA0
|
||||
#if defined SSD1331_COLORORDER_RGB
|
||||
writeCommand(0x72); // RGB Color
|
||||
#else
|
||||
writeCommand(0x76); // BGR Color
|
||||
#endif
|
||||
writeCommand(SSD1331_CMD_STARTLINE); // 0xA1
|
||||
writeCommand(0x0);
|
||||
writeCommand(SSD1331_CMD_DISPLAYOFFSET); // 0xA2
|
||||
writeCommand(0x0);
|
||||
writeCommand(SSD1331_CMD_NORMALDISPLAY); // 0xA4
|
||||
writeCommand(SSD1331_CMD_SETMULTIPLEX); // 0xA8
|
||||
writeCommand(0x3F); // 0x3F 1/64 duty
|
||||
writeCommand(SSD1331_CMD_SETMASTER); // 0xAD
|
||||
writeCommand(0x8E);
|
||||
writeCommand(SSD1331_CMD_POWERMODE); // 0xB0
|
||||
writeCommand(0x0B);
|
||||
writeCommand(SSD1331_CMD_PRECHARGE); // 0xB1
|
||||
writeCommand(0x31);
|
||||
writeCommand(SSD1331_CMD_CLOCKDIV); // 0xB3
|
||||
writeCommand(0xF0); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio (A[3:0]+1 = 1..16)
|
||||
writeCommand(SSD1331_CMD_PRECHARGEA); // 0x8A
|
||||
writeCommand(0x64);
|
||||
writeCommand(SSD1331_CMD_PRECHARGEB); // 0x8B
|
||||
writeCommand(0x78);
|
||||
writeCommand(SSD1331_CMD_PRECHARGEA); // 0x8C
|
||||
writeCommand(0x64);
|
||||
writeCommand(SSD1331_CMD_PRECHARGELEVEL); // 0xBB
|
||||
writeCommand(0x3A);
|
||||
writeCommand(SSD1331_CMD_VCOMH); // 0xBE
|
||||
writeCommand(0x3E);
|
||||
writeCommand(SSD1331_CMD_MASTERCURRENT); // 0x87
|
||||
writeCommand(0x06);
|
||||
writeCommand(SSD1331_CMD_CONTRASTA); // 0x81
|
||||
writeCommand(0x91);
|
||||
writeCommand(SSD1331_CMD_CONTRASTB); // 0x82
|
||||
writeCommand(0x50);
|
||||
writeCommand(SSD1331_CMD_CONTRASTC); // 0x83
|
||||
writeCommand(0x7D);
|
||||
writeCommand(SSD1331_CMD_DISPLAYON); //--turn on oled panel
|
||||
|
||||
endWrite();
|
||||
_width = TFTWIDTH;
|
||||
_height = TFTHEIGHT;
|
||||
}
|
||||
|
||||
/********************************* low level pin initialization */
|
||||
|
||||
Adafruit_SSD1331::Adafruit_SSD1331(uint8_t cs, uint8_t dc, uint8_t mosi, uint8_t sclk, uint8_t rst) : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, mosi, sclk, rst, -1) {
|
||||
}
|
||||
|
||||
Adafruit_SSD1331::Adafruit_SSD1331(uint8_t cs, uint8_t dc, uint8_t rst) : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, rst) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,115 +1,81 @@
|
|||
/***************************************************
|
||||
This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/684
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define gfx_swap(a, b) { uint16_t t = a; a = b; b = t; }
|
||||
|
||||
#ifdef __SAM3X8E__
|
||||
typedef volatile RwReg PortReg;
|
||||
typedef uint32_t PortMask;
|
||||
#define _BV(b) (1<<(b))
|
||||
#else
|
||||
typedef volatile uint8_t PortReg;
|
||||
typedef uint8_t PortMask;
|
||||
#endif
|
||||
|
||||
// Select one of these defines to set the pixel color order
|
||||
#define SSD1331_COLORORDER_RGB
|
||||
// #define SSD1331_COLORORDER_BGR
|
||||
|
||||
#if defined SSD1331_COLORORDER_RGB && defined SSD1331_COLORORDER_BGR
|
||||
#error "RGB and BGR can not both be defined for SSD1331_COLORODER."
|
||||
#endif
|
||||
|
||||
// Timing Delays
|
||||
#define SSD1331_DELAYS_HWFILL (3)
|
||||
#define SSD1331_DELAYS_HWLINE (1)
|
||||
|
||||
// SSD1331 Commands
|
||||
#define SSD1331_CMD_DRAWLINE 0x21
|
||||
#define SSD1331_CMD_DRAWRECT 0x22
|
||||
#define SSD1331_CMD_FILL 0x26
|
||||
#define SSD1331_CMD_SETCOLUMN 0x15
|
||||
#define SSD1331_CMD_SETROW 0x75
|
||||
#define SSD1331_CMD_CONTRASTA 0x81
|
||||
#define SSD1331_CMD_CONTRASTB 0x82
|
||||
#define SSD1331_CMD_CONTRASTC 0x83
|
||||
#define SSD1331_CMD_MASTERCURRENT 0x87
|
||||
#define SSD1331_CMD_SETREMAP 0xA0
|
||||
#define SSD1331_CMD_STARTLINE 0xA1
|
||||
#define SSD1331_CMD_DISPLAYOFFSET 0xA2
|
||||
#define SSD1331_CMD_NORMALDISPLAY 0xA4
|
||||
#define SSD1331_CMD_DISPLAYALLON 0xA5
|
||||
#define SSD1331_CMD_DISPLAYALLOFF 0xA6
|
||||
#define SSD1331_CMD_INVERTDISPLAY 0xA7
|
||||
#define SSD1331_CMD_SETMULTIPLEX 0xA8
|
||||
#define SSD1331_CMD_SETMASTER 0xAD
|
||||
#define SSD1331_CMD_DISPLAYOFF 0xAE
|
||||
#define SSD1331_CMD_DISPLAYON 0xAF
|
||||
#define SSD1331_CMD_POWERMODE 0xB0
|
||||
#define SSD1331_CMD_PRECHARGE 0xB1
|
||||
#define SSD1331_CMD_CLOCKDIV 0xB3
|
||||
#define SSD1331_CMD_PRECHARGEA 0x8A
|
||||
#define SSD1331_CMD_PRECHARGEB 0x8B
|
||||
#define SSD1331_CMD_PRECHARGEC 0x8C
|
||||
#define SSD1331_CMD_PRECHARGELEVEL 0xBB
|
||||
#define SSD1331_CMD_VCOMH 0xBE
|
||||
|
||||
class Adafruit_SSD1331 : public virtual Adafruit_GFX {
|
||||
public:
|
||||
Adafruit_SSD1331(uint8_t CS, uint8_t RS, uint8_t SID, uint8_t SCLK, uint8_t RST);
|
||||
Adafruit_SSD1331(uint8_t CS, uint8_t RS, uint8_t RST);
|
||||
|
||||
uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
// drawing primitives!
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
|
||||
//void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t fillcolor);
|
||||
void pushColor(uint16_t c);
|
||||
|
||||
// commands
|
||||
void begin(void);
|
||||
void goHome(void);
|
||||
void goTo(int x, int y);
|
||||
|
||||
void reset(void);
|
||||
|
||||
/* low level */
|
||||
|
||||
void writeData(uint8_t d);
|
||||
void writeCommand(uint8_t c);
|
||||
|
||||
static const int16_t TFTWIDTH = 96;
|
||||
static const int16_t TFTHEIGHT = 64;
|
||||
|
||||
void writeData_unsafe(uint16_t d);
|
||||
|
||||
void setWriteDir(void);
|
||||
void write8(uint8_t d);
|
||||
|
||||
private:
|
||||
void spiwrite(uint8_t);
|
||||
|
||||
uint8_t _cs, _rs, _rst, _sid, _sclk;
|
||||
PortReg *csportreg, *rsportreg, *sidportreg, *sclkportreg;
|
||||
PortMask cspin, rspin, sidpin, sclkpin;
|
||||
};
|
||||
/***************************************************
|
||||
This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/684
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SPITFT.h>
|
||||
#include <Adafruit_SPITFT_Macros.h>
|
||||
|
||||
|
||||
// Select one of these defines to set the pixel color order
|
||||
#define SSD1331_COLORORDER_RGB
|
||||
// #define SSD1331_COLORORDER_BGR
|
||||
|
||||
#if defined SSD1331_COLORORDER_RGB && defined SSD1331_COLORORDER_BGR
|
||||
#error "RGB and BGR can not both be defined for SSD1331_COLORODER."
|
||||
#endif
|
||||
|
||||
// Timing Delays
|
||||
#define SSD1331_DELAYS_HWFILL (3)
|
||||
#define SSD1331_DELAYS_HWLINE (1)
|
||||
|
||||
// SSD1331 Commands
|
||||
#define SSD1331_CMD_DRAWLINE 0x21
|
||||
#define SSD1331_CMD_DRAWRECT 0x22
|
||||
#define SSD1331_CMD_FILL 0x26
|
||||
#define SSD1331_CMD_SETCOLUMN 0x15
|
||||
#define SSD1331_CMD_SETROW 0x75
|
||||
#define SSD1331_CMD_CONTRASTA 0x81
|
||||
#define SSD1331_CMD_CONTRASTB 0x82
|
||||
#define SSD1331_CMD_CONTRASTC 0x83
|
||||
#define SSD1331_CMD_MASTERCURRENT 0x87
|
||||
#define SSD1331_CMD_SETREMAP 0xA0
|
||||
#define SSD1331_CMD_STARTLINE 0xA1
|
||||
#define SSD1331_CMD_DISPLAYOFFSET 0xA2
|
||||
#define SSD1331_CMD_NORMALDISPLAY 0xA4
|
||||
#define SSD1331_CMD_DISPLAYALLON 0xA5
|
||||
#define SSD1331_CMD_DISPLAYALLOFF 0xA6
|
||||
#define SSD1331_CMD_INVERTDISPLAY 0xA7
|
||||
#define SSD1331_CMD_SETMULTIPLEX 0xA8
|
||||
#define SSD1331_CMD_SETMASTER 0xAD
|
||||
#define SSD1331_CMD_DISPLAYOFF 0xAE
|
||||
#define SSD1331_CMD_DISPLAYON 0xAF
|
||||
#define SSD1331_CMD_POWERMODE 0xB0
|
||||
#define SSD1331_CMD_PRECHARGE 0xB1
|
||||
#define SSD1331_CMD_CLOCKDIV 0xB3
|
||||
#define SSD1331_CMD_PRECHARGEA 0x8A
|
||||
#define SSD1331_CMD_PRECHARGEB 0x8B
|
||||
#define SSD1331_CMD_PRECHARGEC 0x8C
|
||||
#define SSD1331_CMD_PRECHARGELEVEL 0xBB
|
||||
#define SSD1331_CMD_VCOMH 0xBE
|
||||
|
||||
class Adafruit_SSD1331 : public Adafruit_SPITFT {
|
||||
public:
|
||||
Adafruit_SSD1331(uint8_t _CS, uint8_t _DC, uint8_t _MOSI, uint8_t _SCLK, uint8_t _RST);
|
||||
Adafruit_SSD1331(uint8_t _CS, uint8_t _DC, uint8_t _RST);
|
||||
|
||||
// commands
|
||||
void begin(uint32_t begin=8000000);
|
||||
|
||||
void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
uint8_t readcommand8(uint8_t reg, uint8_t index = 0);
|
||||
|
||||
static const int16_t TFTWIDTH = 96;
|
||||
static const int16_t TFTHEIGHT = 64;
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ void setup(void) {
|
|||
|
||||
if (!SD.begin(SD_CS)) {
|
||||
Serial.println("failed!");
|
||||
return;
|
||||
while(1);
|
||||
}
|
||||
Serial.println("SD OK!");
|
||||
|
||||
|
|
@ -87,6 +87,7 @@ void setup(void) {
|
|||
void loop() {
|
||||
}
|
||||
|
||||
|
||||
// This function opens a Windows Bitmap (BMP) file and
|
||||
// displays it at the given coordinates. It's sped up
|
||||
// by reading many pixels worth of data at a time
|
||||
|
|
@ -97,7 +98,7 @@ void loop() {
|
|||
|
||||
#define BUFFPIXEL 20
|
||||
|
||||
void bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
||||
void bmpDraw(char *filename, int16_t x, int16_t y) {
|
||||
|
||||
File bmpFile;
|
||||
int bmpWidth, bmpHeight; // W+H in pixels
|
||||
|
|
@ -108,40 +109,40 @@ void bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
|||
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
|
||||
boolean goodBmp = false; // Set to true on valid header parse
|
||||
boolean flip = true; // BMP is stored bottom-to-top
|
||||
int w, h, row, col;
|
||||
int w, h, row, col, x2, y2, bx1, by1;
|
||||
uint8_t r, g, b;
|
||||
uint32_t pos = 0, startTime = millis();
|
||||
|
||||
if((x >= tft.width()) || (y >= tft.height())) return;
|
||||
|
||||
Serial.println();
|
||||
Serial.print("Loading image '");
|
||||
Serial.print(F("Loading image '"));
|
||||
Serial.print(filename);
|
||||
Serial.println('\'');
|
||||
|
||||
// Open requested file on SD card
|
||||
if ((bmpFile = SD.open(filename)) == NULL) {
|
||||
Serial.print("File not found");
|
||||
Serial.print(F("File not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse BMP header
|
||||
if(read16(bmpFile) == 0x4D42) { // BMP signature
|
||||
Serial.print("File size: "); Serial.println(read32(bmpFile));
|
||||
Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
|
||||
(void)read32(bmpFile); // Read & ignore creator bytes
|
||||
bmpImageoffset = read32(bmpFile); // Start of image data
|
||||
Serial.print("Image Offset: "); Serial.println(bmpImageoffset, DEC);
|
||||
Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
|
||||
// Read DIB header
|
||||
Serial.print("Header size: "); Serial.println(read32(bmpFile));
|
||||
Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
|
||||
bmpWidth = read32(bmpFile);
|
||||
bmpHeight = read32(bmpFile);
|
||||
if(read16(bmpFile) == 1) { // # planes -- must be '1'
|
||||
bmpDepth = read16(bmpFile); // bits per pixel
|
||||
Serial.print("Bit Depth: "); Serial.println(bmpDepth);
|
||||
Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
|
||||
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
|
||||
|
||||
goodBmp = true; // Supported BMP format -- proceed!
|
||||
Serial.print("Image size: ");
|
||||
Serial.print(F("Image size: "));
|
||||
Serial.print(bmpWidth);
|
||||
Serial.print('x');
|
||||
Serial.println(bmpHeight);
|
||||
|
|
@ -157,48 +158,66 @@ void bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
|||
}
|
||||
|
||||
// Crop area to be loaded
|
||||
w = bmpWidth;
|
||||
h = bmpHeight;
|
||||
if((x+w-1) >= tft.width()) w = tft.width() - x;
|
||||
if((y+h-1) >= tft.height()) h = tft.height() - y;
|
||||
|
||||
for (row=0; row<h; row++) { // For each scanline...
|
||||
tft.goTo(x, y+row);
|
||||
|
||||
// Seek to start of scan line. It might seem labor-
|
||||
// intensive to be doing this on every line, but this
|
||||
// method covers a lot of gritty details like cropping
|
||||
// and scanline padding. Also, the seek only takes
|
||||
// place if the file position actually needs to change
|
||||
// (avoids a lot of cluster math in SD library).
|
||||
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
|
||||
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
|
||||
else // Bitmap is stored top-to-bottom
|
||||
pos = bmpImageoffset + row * rowSize;
|
||||
if(bmpFile.position() != pos) { // Need seek?
|
||||
bmpFile.seek(pos);
|
||||
buffidx = sizeof(sdbuffer); // Force buffer reload
|
||||
x2 = x + bmpWidth - 1; // Lower-right corner
|
||||
y2 = y + bmpHeight - 1;
|
||||
if((x2 >= 0) && (y2 >= 0)) { // On screen?
|
||||
w = bmpWidth; // Width/height of section to load/display
|
||||
h = bmpHeight;
|
||||
bx1 = by1 = 0; // UL coordinate in BMP file
|
||||
if(x < 0) { // Clip left
|
||||
bx1 = -x;
|
||||
x = 0;
|
||||
w = x2 + 1;
|
||||
}
|
||||
|
||||
// optimize by setting pins now
|
||||
for (col=0; col<w; col++) { // For each pixel...
|
||||
// Time to read more pixel data?
|
||||
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
||||
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
||||
buffidx = 0; // Set index to beginning
|
||||
if(y < 0) { // Clip top
|
||||
by1 = -y;
|
||||
y = 0;
|
||||
h = y2 + 1;
|
||||
}
|
||||
if(x2 >= tft.width()) w = tft.width() - x; // Clip right
|
||||
if(y2 >= tft.height()) h = tft.height() - y; // Clip bottom
|
||||
|
||||
// Set TFT address window to clipped image bounds
|
||||
tft.startWrite(); // Requires start/end transaction now
|
||||
tft.setAddrWindow(x, y, w, h);
|
||||
|
||||
for (row=0; row<h; row++) { // For each scanline...
|
||||
|
||||
// Seek to start of scan line. It might seem labor-
|
||||
// intensive to be doing this on every line, but this
|
||||
// method covers a lot of gritty details like cropping
|
||||
// and scanline padding. Also, the seek only takes
|
||||
// place if the file position actually needs to change
|
||||
// (avoids a lot of cluster math in SD library).
|
||||
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
|
||||
pos = bmpImageoffset + (bmpHeight - 1 - (row + by1)) * rowSize;
|
||||
else // Bitmap is stored top-to-bottom
|
||||
pos = bmpImageoffset + (row + by1) * rowSize;
|
||||
pos += bx1 * 3; // Factor in starting column (bx1)
|
||||
if(bmpFile.position() != pos) { // Need seek?
|
||||
tft.endWrite(); // End TFT transaction
|
||||
bmpFile.seek(pos);
|
||||
buffidx = sizeof(sdbuffer); // Force buffer reload
|
||||
tft.startWrite(); // Start new TFT transaction
|
||||
}
|
||||
|
||||
// Convert pixel from BMP to TFT format, push to display
|
||||
b = sdbuffer[buffidx++];
|
||||
g = sdbuffer[buffidx++];
|
||||
r = sdbuffer[buffidx++];
|
||||
|
||||
//tft.drawPixel(x+col, y+row, tft.Color565(r,g,b));
|
||||
// optimized!
|
||||
tft.pushColor(tft.Color565(r,g,b));
|
||||
} // end pixel
|
||||
} // end scanline
|
||||
Serial.print("Loaded in ");
|
||||
for (col=0; col<w; col++) { // For each pixel...
|
||||
// Time to read more pixel data?
|
||||
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
||||
tft.endWrite(); // End TFT transaction
|
||||
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
||||
buffidx = 0; // Set index to beginning
|
||||
tft.startWrite(); // Start new TFT transaction
|
||||
}
|
||||
// Convert pixel from BMP to TFT format, push to display
|
||||
b = sdbuffer[buffidx++];
|
||||
g = sdbuffer[buffidx++];
|
||||
r = sdbuffer[buffidx++];
|
||||
tft.writePixel(tft.color565(r,g,b));
|
||||
} // end pixel
|
||||
} // end scanline
|
||||
tft.endWrite(); // End last TFT transaction
|
||||
} // end onscreen
|
||||
Serial.print(F("Loaded in "));
|
||||
Serial.print(millis() - startTime);
|
||||
Serial.println(" ms");
|
||||
} // end goodBmp
|
||||
|
|
@ -206,25 +225,25 @@ void bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
|||
}
|
||||
|
||||
bmpFile.close();
|
||||
if(!goodBmp) Serial.println("BMP format not recognized.");
|
||||
if(!goodBmp) Serial.println(F("BMP format not recognized."));
|
||||
}
|
||||
|
||||
// These read 16- and 32-bit types from the SD card file.
|
||||
// BMP data is stored little-endian, Arduino is little-endian too.
|
||||
// May need to reverse subscript order if porting elsewhere.
|
||||
|
||||
uint16_t read16(File f) {
|
||||
uint16_t read16(File &f) {
|
||||
uint16_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t read32(File f) {
|
||||
uint32_t read32(File &f) {
|
||||
uint32_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read();
|
||||
((uint8_t *)&result)[2] = f.read();
|
||||
((uint8_t *)&result)[3] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,320 +1,324 @@
|
|||
/***************************************************
|
||||
This is a example sketch demonstrating the graphics
|
||||
capabilities of the SSD1331 library for the 0.96"
|
||||
16-bit Color OLED with SSD1331 driver chip
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/684
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
|
||||
// You can use any (4 or) 5 pins
|
||||
#define sclk 13
|
||||
#define mosi 11
|
||||
#define cs 10
|
||||
#define rst 9
|
||||
#define dc 8
|
||||
|
||||
|
||||
// Color definitions
|
||||
#define BLACK 0x0000
|
||||
#define BLUE 0x001F
|
||||
#define RED 0xF800
|
||||
#define GREEN 0x07E0
|
||||
#define CYAN 0x07FF
|
||||
#define MAGENTA 0xF81F
|
||||
#define YELLOW 0xFFE0
|
||||
#define WHITE 0xFFFF
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1331.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// Option 1: use any pins but a little slower
|
||||
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);
|
||||
|
||||
// Option 2: must use the hardware SPI pins
|
||||
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
|
||||
// an output. This is much faster - also required if you want
|
||||
// to use the microSD card (see the image drawing example)
|
||||
//Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print("hello!");
|
||||
display.begin();
|
||||
|
||||
Serial.println("init");
|
||||
uint16_t time = millis();
|
||||
display.fillScreen(BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
lcdTestPattern();
|
||||
delay(1000);
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
display.setCursor(0,0);
|
||||
display.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(2000);
|
||||
|
||||
//a single pixel
|
||||
display.drawPixel(display.width()/2, display.height()/2, GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(RED, BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(GREEN);
|
||||
delay(1000);
|
||||
|
||||
testfillrects(YELLOW, MAGENTA);
|
||||
delay(1000);
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
testfillcircles(10, BLUE);
|
||||
testdrawcircles(10, WHITE);
|
||||
delay(1000);
|
||||
|
||||
testroundrects();
|
||||
delay(500);
|
||||
|
||||
testtriangles();
|
||||
delay(500);
|
||||
|
||||
Serial.println("done");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void testlines(uint16_t color) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(0, 0, x, display.height()-1, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(0, 0, display.width()-1, y, color);
|
||||
}
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(display.width()-1, 0, x, display.height()-1, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(display.width()-1, 0, 0, y, color);
|
||||
}
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(0, display.height()-1, x, 0, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, y, color);
|
||||
}
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(display.width()-1, display.height()-1, x, 0, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, y, color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void testdrawtext(char *text, uint16_t color) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void testfastlines(uint16_t color1, uint16_t color2) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t y=0; y < display.height()-1; y+=5) {
|
||||
display.drawFastHLine(0, y, display.width()-1, color1);
|
||||
}
|
||||
for (int16_t x=0; x < display.width()-1; x+=5) {
|
||||
display.drawFastVLine(x, 0, display.height()-1, color2);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrects(uint16_t color) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.height()-1; x+=6) {
|
||||
display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrects(uint16_t color1, uint16_t color2) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=display.height()-1; x > 6; x-=6) {
|
||||
display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1);
|
||||
display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillcircles(uint8_t radius, uint16_t color) {
|
||||
for (uint8_t x=radius; x < display.width()-1; x+=radius*2) {
|
||||
for (uint8_t y=radius; y < display.height()-1; y+=radius*2) {
|
||||
display.fillCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawcircles(uint8_t radius, uint16_t color) {
|
||||
for (int16_t x=0; x < display.width()-1+radius; x+=radius*2) {
|
||||
for (int16_t y=0; y < display.height()-1+radius; y+=radius*2) {
|
||||
display.drawCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testtriangles() {
|
||||
display.fillScreen(BLACK);
|
||||
int color = 0xF800;
|
||||
int t;
|
||||
int w = display.width()/2;
|
||||
int x = display.height();
|
||||
int y = 0;
|
||||
int z = display.width();
|
||||
for(t = 0 ; t <= 15; t+=1) {
|
||||
display.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
display.fillScreen(BLACK);
|
||||
int color = 100;
|
||||
int i;
|
||||
int t;
|
||||
for(t = 0 ; t <= 4; t+=1) {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = display.width();
|
||||
int h = display.height();
|
||||
for(i = 0 ; i <= 24; i+=1) {
|
||||
display.drawRoundRect(x, y, w, h, 5, color);
|
||||
x+=2;
|
||||
y+=3;
|
||||
w-=4;
|
||||
h-=6;
|
||||
color+=1100;
|
||||
}
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void tftPrintTest() {
|
||||
display.fillScreen(BLACK);
|
||||
display.setCursor(0, 5);
|
||||
display.setTextColor(RED);
|
||||
display.setTextSize(1);
|
||||
display.println("Hello World!");
|
||||
display.setTextColor(YELLOW, GREEN);
|
||||
display.setTextSize(2);
|
||||
display.print("Hello Wo");
|
||||
display.setTextColor(BLUE);
|
||||
display.setTextSize(3);
|
||||
display.print(1234.567);
|
||||
delay(1500);
|
||||
display.setCursor(0, 5);
|
||||
display.fillScreen(BLACK);
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(0);
|
||||
display.println("Hello World!");
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(GREEN);
|
||||
display.print(p, 5);
|
||||
display.println(" Want pi?");
|
||||
display.print(8675309, HEX); // print 8,675,309 out in HEX!
|
||||
display.print(" Print HEX");
|
||||
display.setTextColor(WHITE);
|
||||
display.println("Sketch has been");
|
||||
display.println("running for: ");
|
||||
display.setTextColor(MAGENTA);
|
||||
display.print(millis() / 1000);
|
||||
display.setTextColor(WHITE);
|
||||
display.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
display.fillScreen(BLACK);
|
||||
display.fillRoundRect(25, 10, 78, 60, 8, WHITE);
|
||||
display.fillTriangle(42, 20, 42, 60, 90, 40, RED);
|
||||
delay(500);
|
||||
// pause
|
||||
display.fillRoundRect(25, 90, 78, 60, 8, WHITE);
|
||||
display.fillRoundRect(39, 98, 20, 45, 5, GREEN);
|
||||
display.fillRoundRect(69, 98, 20, 45, 5, GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
display.fillTriangle(42, 20, 42, 60, 90, 40, BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
display.fillRoundRect(39, 98, 20, 45, 5, RED);
|
||||
display.fillRoundRect(69, 98, 20, 45, 5, RED);
|
||||
// play color
|
||||
display.fillTriangle(42, 20, 42, 60, 90, 40, GREEN);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Renders a simple test pattern on the LCD
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void lcdTestPattern(void)
|
||||
{
|
||||
uint32_t i,j;
|
||||
display.goTo(0, 0);
|
||||
|
||||
for(i=0;i<64;i++)
|
||||
{
|
||||
for(j=0;j<96;j++)
|
||||
{
|
||||
if(i>55){display.writeData(WHITE>>8);display.writeData(WHITE);}
|
||||
else if(i>47){display.writeData(BLUE>>8);display.writeData(BLUE);}
|
||||
else if(i>39){display.writeData(GREEN>>8);display.writeData(GREEN);}
|
||||
else if(i>31){display.writeData(CYAN>>8);display.writeData(CYAN);}
|
||||
else if(i>23){display.writeData(RED>>8);display.writeData(RED);}
|
||||
else if(i>15){display.writeData(MAGENTA>>8);display.writeData(MAGENTA);}
|
||||
else if(i>7){display.writeData(YELLOW>>8);display.writeData(YELLOW);}
|
||||
else {display.writeData(BLACK>>8);display.writeData(BLACK);}
|
||||
}
|
||||
}
|
||||
}
|
||||
/***************************************************
|
||||
This is a example sketch demonstrating the graphics
|
||||
capabilities of the SSD1331 library for the 0.96"
|
||||
16-bit Color OLED with SSD1331 driver chip
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/684
|
||||
|
||||
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, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1331.h>
|
||||
#include <SPI.h>
|
||||
|
||||
|
||||
// You can use any (4 or) 5 pins
|
||||
#define sclk 13
|
||||
#define mosi 11
|
||||
#define cs 10
|
||||
#define rst 9
|
||||
#define dc 8
|
||||
|
||||
|
||||
// Color definitions
|
||||
#define BLACK 0x0000
|
||||
#define BLUE 0x001F
|
||||
#define RED 0xF800
|
||||
#define GREEN 0x07E0
|
||||
#define CYAN 0x07FF
|
||||
#define MAGENTA 0xF81F
|
||||
#define YELLOW 0xFFE0
|
||||
#define WHITE 0xFFFF
|
||||
|
||||
// Option 1: use any pins but a little slower
|
||||
//Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);
|
||||
|
||||
// Option 2: must use the hardware SPI pins
|
||||
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
|
||||
// an output. This is much faster - also required if you want
|
||||
// to use the microSD card (see the image drawing example)
|
||||
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print("hello!");
|
||||
display.begin();
|
||||
|
||||
Serial.println("init");
|
||||
uint16_t time = millis();
|
||||
display.fillScreen(BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
lcdTestPattern();
|
||||
delay(1000);
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
display.setCursor(0,0);
|
||||
display.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa");
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(2000);
|
||||
|
||||
//a single pixel
|
||||
display.drawPixel(display.width()/2, display.height()/2, GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(RED, BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(GREEN);
|
||||
delay(1000);
|
||||
|
||||
testfillrects(YELLOW, MAGENTA);
|
||||
delay(1000);
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
testfillcircles(10, BLUE);
|
||||
testdrawcircles(10, WHITE);
|
||||
delay(1000);
|
||||
|
||||
testroundrects();
|
||||
delay(500);
|
||||
|
||||
testtriangles();
|
||||
delay(500);
|
||||
|
||||
Serial.println("done");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void testlines(uint16_t color) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(0, 0, x, display.height()-1, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(0, 0, display.width()-1, y, color);
|
||||
}
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(display.width()-1, 0, x, display.height()-1, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(display.width()-1, 0, 0, y, color);
|
||||
}
|
||||
|
||||
// To avoid ESP8266 watchdog timer resets when not using the hardware SPI pins
|
||||
delay(0);
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(0, display.height()-1, x, 0, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, y, color);
|
||||
}
|
||||
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.width()-1; x+=6) {
|
||||
display.drawLine(display.width()-1, display.height()-1, x, 0, color);
|
||||
}
|
||||
for (int16_t y=0; y < display.height()-1; y+=6) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, y, color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void testdrawtext(char *text, uint16_t color) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void testfastlines(uint16_t color1, uint16_t color2) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t y=0; y < display.height()-1; y+=5) {
|
||||
display.drawFastHLine(0, y, display.width()-1, color1);
|
||||
}
|
||||
for (int16_t x=0; x < display.width()-1; x+=5) {
|
||||
display.drawFastVLine(x, 0, display.height()-1, color2);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrects(uint16_t color) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=0; x < display.height()-1; x+=6) {
|
||||
display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrects(uint16_t color1, uint16_t color2) {
|
||||
display.fillScreen(BLACK);
|
||||
for (int16_t x=display.height()-1; x > 6; x-=6) {
|
||||
display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1);
|
||||
display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillcircles(uint8_t radius, uint16_t color) {
|
||||
for (uint8_t x=radius; x < display.width()-1; x+=radius*2) {
|
||||
for (uint8_t y=radius; y < display.height()-1; y+=radius*2) {
|
||||
display.fillCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawcircles(uint8_t radius, uint16_t color) {
|
||||
for (int16_t x=0; x < display.width()-1+radius; x+=radius*2) {
|
||||
for (int16_t y=0; y < display.height()-1+radius; y+=radius*2) {
|
||||
display.drawCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testtriangles() {
|
||||
display.fillScreen(BLACK);
|
||||
int color = 0xF800;
|
||||
int t;
|
||||
int w = display.width()/2;
|
||||
int x = display.height();
|
||||
int y = 0;
|
||||
int z = display.width();
|
||||
for(t = 0 ; t <= 15; t+=1) {
|
||||
display.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
display.fillScreen(BLACK);
|
||||
int color = 100;
|
||||
int i;
|
||||
int t;
|
||||
for(t = 0 ; t <= 4; t+=1) {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = display.width();
|
||||
int h = display.height();
|
||||
for(i = 0 ; i <= 8; i+=1) {
|
||||
display.drawRoundRect(x, y, w, h, 5, color);
|
||||
x+=2;
|
||||
y+=3;
|
||||
w-=4;
|
||||
h-=6;
|
||||
color+=1100;
|
||||
}
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void tftPrintTest() {
|
||||
display.fillScreen(BLACK);
|
||||
display.setCursor(0, 5);
|
||||
display.setTextColor(RED);
|
||||
display.setTextSize(1);
|
||||
display.println("Hello World!");
|
||||
display.setTextColor(YELLOW, GREEN);
|
||||
display.setTextSize(2);
|
||||
display.print("Hello Wo");
|
||||
display.setTextColor(BLUE);
|
||||
display.setTextSize(3);
|
||||
display.print(1234.567);
|
||||
delay(1500);
|
||||
display.setCursor(0, 5);
|
||||
display.fillScreen(BLACK);
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextSize(0);
|
||||
display.println("Hello World!");
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(GREEN);
|
||||
display.print(p, 5);
|
||||
display.println(" Want pi?");
|
||||
display.print(8675309, HEX); // print 8,675,309 out in HEX!
|
||||
display.print(" Print HEX");
|
||||
display.setTextColor(WHITE);
|
||||
display.println("Sketch has been");
|
||||
display.println("running for: ");
|
||||
display.setTextColor(MAGENTA);
|
||||
display.print(millis() / 1000);
|
||||
display.setTextColor(WHITE);
|
||||
display.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
display.fillScreen(BLACK);
|
||||
display.fillRoundRect(25, 10, 78, 60, 8, WHITE);
|
||||
display.fillTriangle(42, 20, 42, 60, 90, 40, RED);
|
||||
delay(500);
|
||||
// pause
|
||||
display.fillRoundRect(25, 90, 78, 60, 8, WHITE);
|
||||
display.fillRoundRect(39, 98, 20, 45, 5, GREEN);
|
||||
display.fillRoundRect(69, 98, 20, 45, 5, GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
display.fillTriangle(42, 20, 42, 60, 90, 40, BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
display.fillRoundRect(39, 98, 20, 45, 5, RED);
|
||||
display.fillRoundRect(69, 98, 20, 45, 5, RED);
|
||||
// play color
|
||||
display.fillTriangle(42, 20, 42, 60, 90, 40, GREEN);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Renders a simple test pattern on the LCD
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void lcdTestPattern(void)
|
||||
{
|
||||
uint8_t w,h;
|
||||
display.setAddrWindow(0, 0, 96, 64);
|
||||
|
||||
for(h=0; h<64; h++)
|
||||
{
|
||||
for(w=0; w<96; w++)
|
||||
{
|
||||
if(w>83){display.writePixel(WHITE);}
|
||||
else if(w>71){display.writePixel(BLUE);}
|
||||
else if(w>59){display.writePixel(GREEN);}
|
||||
else if(w>47){display.writePixel(CYAN);}
|
||||
else if(w>35){display.writePixel(RED);}
|
||||
else if(w>23){display.writePixel(MAGENTA);}
|
||||
else if(w>11){display.writePixel(YELLOW);}
|
||||
else {display.writePixel(BLACK);}
|
||||
}
|
||||
}
|
||||
display.endWrite();
|
||||
}
|
||||
Loading…
Reference in a new issue