Initialisation
This commit is contained in:
312
libraries/Adafruit_PCD8544/Adafruit_PCD8544.cpp
Normal file
312
libraries/Adafruit_PCD8544/Adafruit_PCD8544.cpp
Normal file
@@ -0,0 +1,312 @@
|
||||
/*********************************************************************
|
||||
This is a library for our Monochrome Nokia 5110 LCD Displays
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/338
|
||||
|
||||
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 <Wire.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include <util/delay.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_PCD8544.h"
|
||||
|
||||
// the memory buffer for the LCD
|
||||
uint8_t pcd8544_buffer[LCDWIDTH * LCDHEIGHT / 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, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0,
|
||||
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, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,
|
||||
0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 0xFF,
|
||||
0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE,
|
||||
0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 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, 0x80, 0xC0, 0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87,
|
||||
0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 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, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
|
||||
0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 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, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01,
|
||||
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 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,
|
||||
};
|
||||
|
||||
|
||||
// reduces how much is refreshed, which speeds it up!
|
||||
// originally derived from Steve Evans/JCW's mod but cleaned up and
|
||||
// optimized
|
||||
//#define enablePartialUpdate
|
||||
|
||||
#ifdef enablePartialUpdate
|
||||
static uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) {
|
||||
#ifdef enablePartialUpdate
|
||||
if (xmin < xUpdateMin) xUpdateMin = xmin;
|
||||
if (xmax > xUpdateMax) xUpdateMax = xmax;
|
||||
if (ymin < yUpdateMin) yUpdateMin = ymin;
|
||||
if (ymax > yUpdateMax) yUpdateMax = ymax;
|
||||
#endif
|
||||
}
|
||||
|
||||
Adafruit_PCD8544::Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC,
|
||||
int8_t CS, int8_t RST) : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) {
|
||||
_din = DIN;
|
||||
_sclk = SCLK;
|
||||
_dc = DC;
|
||||
_rst = RST;
|
||||
_cs = CS;
|
||||
}
|
||||
|
||||
Adafruit_PCD8544::Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC,
|
||||
int8_t RST) : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) {
|
||||
_din = DIN;
|
||||
_sclk = SCLK;
|
||||
_dc = DC;
|
||||
_rst = RST;
|
||||
_cs = -1;
|
||||
}
|
||||
|
||||
|
||||
// the most basic function, set a single pixel
|
||||
void Adafruit_PCD8544::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT))
|
||||
return;
|
||||
|
||||
// x is which column
|
||||
if (color)
|
||||
pcd8544_buffer[x+ (y/8)*LCDWIDTH] |= _BV(y%8);
|
||||
else
|
||||
pcd8544_buffer[x+ (y/8)*LCDWIDTH] &= ~_BV(y%8);
|
||||
|
||||
updateBoundingBox(x,y,x,y);
|
||||
}
|
||||
|
||||
|
||||
// the most basic function, get a single pixel
|
||||
uint8_t Adafruit_PCD8544::getPixel(int8_t x, int8_t y) {
|
||||
if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT))
|
||||
return 0;
|
||||
|
||||
return (pcd8544_buffer[x+ (y/8)*LCDWIDTH] >> (y%8)) & 0x1;
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_PCD8544::begin(uint8_t contrast) {
|
||||
// set pin directions
|
||||
pinMode(_din, OUTPUT);
|
||||
pinMode(_sclk, OUTPUT);
|
||||
pinMode(_dc, OUTPUT);
|
||||
if (_rst > 0)
|
||||
pinMode(_rst, OUTPUT);
|
||||
if (_cs > 0)
|
||||
pinMode(_cs, OUTPUT);
|
||||
|
||||
// toggle RST low to reset
|
||||
if (_rst > 0) {
|
||||
digitalWrite(_rst, LOW);
|
||||
_delay_ms(500);
|
||||
digitalWrite(_rst, HIGH);
|
||||
}
|
||||
|
||||
clkport = portOutputRegister(digitalPinToPort(_sclk));
|
||||
clkpinmask = digitalPinToBitMask(_sclk);
|
||||
mosiport = portOutputRegister(digitalPinToPort(_din));
|
||||
mosipinmask = digitalPinToBitMask(_din);
|
||||
csport = portOutputRegister(digitalPinToPort(_cs));
|
||||
cspinmask = digitalPinToBitMask(_cs);
|
||||
dcport = portOutputRegister(digitalPinToPort(_dc));
|
||||
dcpinmask = digitalPinToBitMask(_dc);
|
||||
|
||||
// get into the EXTENDED mode!
|
||||
command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );
|
||||
|
||||
// LCD bias select (4 is optimal?)
|
||||
command(PCD8544_SETBIAS | 0x4);
|
||||
|
||||
// set VOP
|
||||
if (contrast > 0x7f)
|
||||
contrast = 0x7f;
|
||||
|
||||
command( PCD8544_SETVOP | contrast); // Experimentally determined
|
||||
|
||||
|
||||
// normal mode
|
||||
command(PCD8544_FUNCTIONSET);
|
||||
|
||||
// Set display to Normal
|
||||
command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
|
||||
|
||||
// initial display line
|
||||
// set page address
|
||||
// set column address
|
||||
// write display data
|
||||
|
||||
// set up a bounding box for screen updates
|
||||
|
||||
updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
|
||||
// Push out pcd8544_buffer to the Display (will show the AFI logo)
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
inline void Adafruit_PCD8544::fastSPIwrite(uint8_t d) {
|
||||
|
||||
for(uint8_t bit = 0x80; bit; bit >>= 1) {
|
||||
*clkport &= ~clkpinmask;
|
||||
if(d & bit) *mosiport |= mosipinmask;
|
||||
else *mosiport &= ~mosipinmask;
|
||||
*clkport |= clkpinmask;
|
||||
}
|
||||
}
|
||||
|
||||
inline void Adafruit_PCD8544::slowSPIwrite(uint8_t c) {
|
||||
shiftOut(_din, _sclk, MSBFIRST, c);
|
||||
}
|
||||
|
||||
void Adafruit_PCD8544::command(uint8_t c) {
|
||||
digitalWrite(_dc, LOW);
|
||||
if (_cs > 0)
|
||||
digitalWrite(_cs, LOW);
|
||||
fastSPIwrite(c);
|
||||
if (_cs > 0)
|
||||
digitalWrite(_cs, HIGH);
|
||||
}
|
||||
|
||||
void Adafruit_PCD8544::data(uint8_t c) {
|
||||
digitalWrite(_dc, HIGH);
|
||||
if (_cs > 0)
|
||||
digitalWrite(_cs, LOW);
|
||||
fastSPIwrite(c);
|
||||
if (_cs > 0)
|
||||
digitalWrite(_cs, HIGH);
|
||||
}
|
||||
|
||||
void Adafruit_PCD8544::setContrast(uint8_t val) {
|
||||
if (val > 0x7f) {
|
||||
val = 0x7f;
|
||||
}
|
||||
command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION );
|
||||
command( PCD8544_SETVOP | val);
|
||||
command(PCD8544_FUNCTIONSET);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Adafruit_PCD8544::display(void) {
|
||||
uint8_t col, maxcol, p;
|
||||
|
||||
for(p = 0; p < 6; p++) {
|
||||
#ifdef enablePartialUpdate
|
||||
// check if this page is part of update
|
||||
if ( yUpdateMin >= ((p+1)*8) ) {
|
||||
continue; // nope, skip it!
|
||||
}
|
||||
if (yUpdateMax < p*8) {
|
||||
break;
|
||||
}d
|
||||
#endif
|
||||
|
||||
command(PCD8544_SETYADDR | p);
|
||||
|
||||
|
||||
#ifdef enablePartialUpdate
|
||||
col = xUpdateMin;
|
||||
maxcol = xUpdateMax;
|
||||
#else
|
||||
// start at the beginning of the row
|
||||
col = 0;
|
||||
maxcol = LCDWIDTH-1;
|
||||
#endif
|
||||
|
||||
command(PCD8544_SETXADDR | col);
|
||||
|
||||
digitalWrite(_dc, HIGH);
|
||||
if (_cs > 0)
|
||||
digitalWrite(_cs, LOW);
|
||||
for(; col <= maxcol; col++) {
|
||||
//uart_putw_dec(col);
|
||||
//uart_putchar(' ');
|
||||
fastSPIwrite(pcd8544_buffer[(LCDWIDTH*p)+col]);
|
||||
}
|
||||
if (_cs > 0)
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
}
|
||||
|
||||
command(PCD8544_SETYADDR ); // no idea why this is necessary but it is to finish the last byte?
|
||||
#ifdef enablePartialUpdate
|
||||
xUpdateMin = LCDWIDTH - 1;
|
||||
xUpdateMax = 0;
|
||||
yUpdateMin = LCDHEIGHT-1;
|
||||
yUpdateMax = 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// clear everything
|
||||
void Adafruit_PCD8544::clearDisplay(void) {
|
||||
memset(pcd8544_buffer, 0, LCDWIDTH*LCDHEIGHT/8);
|
||||
updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
|
||||
cursor_y = cursor_x = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
// this doesnt touch the buffer, just clears the display RAM - might be handy
|
||||
void Adafruit_PCD8544::clearDisplay(void) {
|
||||
|
||||
uint8_t p, c;
|
||||
|
||||
for(p = 0; p < 8; p++) {
|
||||
|
||||
st7565_command(CMD_SET_PAGE | p);
|
||||
for(c = 0; c < 129; c++) {
|
||||
//uart_putw_dec(c);
|
||||
//uart_putchar(' ');
|
||||
st7565_command(CMD_SET_COLUMN_LOWER | (c & 0xf));
|
||||
st7565_command(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf));
|
||||
st7565_data(0x0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
76
libraries/Adafruit_PCD8544/Adafruit_PCD8544.h
Normal file
76
libraries/Adafruit_PCD8544/Adafruit_PCD8544.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*********************************************************************
|
||||
This is a library for our Monochrome Nokia 5110 LCD Displays
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/338
|
||||
|
||||
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 defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#include "pins_arduino.h"
|
||||
#endif
|
||||
|
||||
#define BLACK 1
|
||||
#define WHITE 0
|
||||
|
||||
#define LCDWIDTH 84
|
||||
#define LCDHEIGHT 48
|
||||
|
||||
#define PCD8544_POWERDOWN 0x04
|
||||
#define PCD8544_ENTRYMODE 0x02
|
||||
#define PCD8544_EXTENDEDINSTRUCTION 0x01
|
||||
|
||||
#define PCD8544_DISPLAYBLANK 0x0
|
||||
#define PCD8544_DISPLAYNORMAL 0x4
|
||||
#define PCD8544_DISPLAYALLON 0x1
|
||||
#define PCD8544_DISPLAYINVERTED 0x5
|
||||
|
||||
// H = 0
|
||||
#define PCD8544_FUNCTIONSET 0x20
|
||||
#define PCD8544_DISPLAYCONTROL 0x08
|
||||
#define PCD8544_SETYADDR 0x40
|
||||
#define PCD8544_SETXADDR 0x80
|
||||
|
||||
// H = 1
|
||||
#define PCD8544_SETTEMP 0x04
|
||||
#define PCD8544_SETBIAS 0x10
|
||||
#define PCD8544_SETVOP 0x80
|
||||
|
||||
class Adafruit_PCD8544 : public Adafruit_GFX {
|
||||
public:
|
||||
Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST);
|
||||
Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, int8_t RST);
|
||||
|
||||
void begin(uint8_t contrast = 40);
|
||||
|
||||
void command(uint8_t c);
|
||||
void data(uint8_t c);
|
||||
|
||||
void setContrast(uint8_t val);
|
||||
void clearDisplay(void);
|
||||
void display();
|
||||
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
uint8_t getPixel(int8_t x, int8_t y);
|
||||
|
||||
private:
|
||||
int8_t _din, _sclk, _dc, _rst, _cs;
|
||||
volatile uint8_t *mosiport, *clkport, *csport, *dcport;
|
||||
uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
|
||||
|
||||
void slowSPIwrite(uint8_t c);
|
||||
void fastSPIwrite(uint8_t c);
|
||||
};
|
||||
23
libraries/Adafruit_PCD8544/README.txt
Normal file
23
libraries/Adafruit_PCD8544/README.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
This is a library for our Monochrome Nokia 5110 LCD Displays
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/338
|
||||
|
||||
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 must be included in any redistribution
|
||||
|
||||
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_PCD8544. Check that the Adafruit_PCD8544 folder contains Adafruit_PCD8544.cpp and Adafruit_PCD8544.h
|
||||
|
||||
Place the Adafruit_PCD8544 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
|
||||
323
libraries/Adafruit_PCD8544/examples/pcdtest/pcdtest.pde
Normal file
323
libraries/Adafruit_PCD8544/examples/pcdtest/pcdtest.pde
Normal file
@@ -0,0 +1,323 @@
|
||||
/*********************************************************************
|
||||
This is an example sketch for our Monochrome Nokia 5110 LCD Displays
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
------> http://www.adafruit.com/products/338
|
||||
|
||||
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
|
||||
*********************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_PCD8544.h>
|
||||
|
||||
// pin 7 - Serial clock out (SCLK)
|
||||
// pin 6 - Serial data out (DIN)
|
||||
// pin 5 - Data/Command select (D/C)
|
||||
// pin 4 - LCD chip select (CS)
|
||||
// pin 3 - LCD reset (RST)
|
||||
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
|
||||
#define LOGO16_GLCD_HEIGHT 16
|
||||
#define LOGO16_GLCD_WIDTH 16
|
||||
|
||||
static 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 };
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
display.begin();
|
||||
// init done
|
||||
|
||||
// you can change the contrast around to adapt the display
|
||||
// for the best viewing!
|
||||
display.setContrast(50);
|
||||
|
||||
display.display(); // show splashscreen
|
||||
delay(2000);
|
||||
display.clearDisplay(); // clears the screen and buffer
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, BLACK);
|
||||
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 circle, 10 pixel radius
|
||||
display.fillCircle(display.width()/2, display.height()/2, 10, BLACK);
|
||||
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();
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(BLACK);
|
||||
display.setCursor(0,0);
|
||||
display.println("Hello, world!");
|
||||
display.setTextColor(WHITE, BLACK); // 'inverted' text
|
||||
display.println(3.141592);
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(BLACK);
|
||||
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];
|
||||
srandom(666); // whatever seed
|
||||
|
||||
// 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, BLACK);
|
||||
}
|
||||
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, WHITE);
|
||||
// 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(BLACK);
|
||||
display.setCursor(0,0);
|
||||
|
||||
for (uint8_t i=0; i < 168; i++) {
|
||||
if (i == '\n') continue;
|
||||
display.write(i);
|
||||
//if ((i > 0) && (i % 14 == 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, BLACK);
|
||||
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, BLACK);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
uint8_t color = BLACK;
|
||||
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, color);
|
||||
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, BLACK);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
uint8_t color = BLACK;
|
||||
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, BLACK);
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, 0, i, display.height()-1, BLACK);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(0, 0, display.width()-1, i, BLACK);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, display.height()-1, i, 0, BLACK);
|
||||
display.display();
|
||||
}
|
||||
for (int8_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, i, BLACK);
|
||||
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, BLACK);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, 0, i, BLACK);
|
||||
display.display();
|
||||
}
|
||||
for (int16_t i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, i, display.height()-1, BLACK);
|
||||
display.display();
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
26
libraries/Adafruit_PCD8544/license.txt
Normal file
26
libraries/Adafruit_PCD8544/license.txt
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user