From 8392ec39657f11415dcb50b68713bdc130c2f8d9 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 14 Oct 2022 21:03:18 +0200 Subject: [PATCH] [Bugfix] P141 PCD8544 Library issue resolutions --- .../Adafruit_PCD8544.cpp | 432 ++++++++++++++++++ .../Adafruit_PCD8544.h | 110 +++++ .../README.md | 24 + .../code-of-conduct.md | 127 +++++ .../examples/pcdtest/pcdtest.ino | 377 +++++++++++++++ .../library.properties | 10 + .../license.txt | 26 ++ 7 files changed, 1106 insertions(+) create mode 100644 lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.cpp create mode 100644 lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.h create mode 100644 lib/Adafruit-PCD8544-Nokia-5110-LCD-library/README.md create mode 100644 lib/Adafruit-PCD8544-Nokia-5110-LCD-library/code-of-conduct.md create mode 100644 lib/Adafruit-PCD8544-Nokia-5110-LCD-library/examples/pcdtest/pcdtest.ino create mode 100644 lib/Adafruit-PCD8544-Nokia-5110-LCD-library/library.properties create mode 100644 lib/Adafruit-PCD8544-Nokia-5110-LCD-library/license.txt diff --git a/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.cpp b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.cpp new file mode 100644 index 000000000..22a64477d --- /dev/null +++ b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.cpp @@ -0,0 +1,432 @@ +/**************************************************************************/ +/*! + @file Adafruit_PCD8544.cpp + + @mainpage Adafruit PCD8544 Nokia 5110 LCD Library + + @section intro Introduction + + 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! + + @section author Author + + Written by Limor Fried/Ladyada for Adafruit Industries. + + @section license License + + BSD license, check license.txt for more information + All text above, and the splash screen below must be included in any + redistribution + + */ +/**************************************************************************/ + +#include "Adafruit_PCD8544.h" +#include "Arduino.h" +#include + +/** 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, +}; + +/*! + @brief Update the bounding box for partial updates + @param xmin left + @param ymin bottom + @param xmax right + @param ymax top + */ +void Adafruit_PCD8544::updateBoundingBox(uint8_t xmin, uint8_t ymin, + uint8_t xmax, uint8_t ymax) { + xUpdateMin = min(xUpdateMin, xmin); + xUpdateMax = max(xUpdateMax, xmax); + yUpdateMin = min(yUpdateMin, ymin); + yUpdateMax = max(yUpdateMax, ymax); +} + +/*! + @brief Constructor for software SPI with explicit CS pin + @param sclk_pin SCLK pin + @param din_pin DIN pin + @param dc_pin DC pin + @param cs_pin CS pin + @param rst_pin RST pin + */ +Adafruit_PCD8544::Adafruit_PCD8544(int8_t sclk_pin, int8_t din_pin, + int8_t dc_pin, int8_t cs_pin, int8_t rst_pin) + : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) { + spi_dev = new Adafruit_SPIDevice(cs_pin, sclk_pin, -1, din_pin, + 4000000); // 4mhz max speed + + _dcpin = dc_pin; + _rstpin = rst_pin; +} + +/*! + @brief Constructor for hardware SPI based on hardware controlled SCK (SCLK) + and MOSI (DIN) pins. CS is still controlled by any IO pin. NOTE: MISO and SS + will be set as an input and output respectively, so be careful sharing those + pins! + @param dc_pin DC pin + @param cs_pin CS pin + @param rst_pin RST pin + @param theSPI Pointer to SPIClass device for hardware SPI + */ +Adafruit_PCD8544::Adafruit_PCD8544(int8_t dc_pin, int8_t cs_pin, int8_t rst_pin, + SPIClass *theSPI) + : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) { + spi_dev = new Adafruit_SPIDevice(cs_pin, 4000000, SPI_BITORDER_MSBFIRST, + SPI_MODE0, theSPI); + + _dcpin = dc_pin; + _rstpin = rst_pin; +} + +/*! + @brief The most basic function, set a single pixel, in the main buffer + @param x x coord + @param y y coord + @param color pixel color (BLACK or WHITE) + */ +void Adafruit_PCD8544::drawPixel(int16_t x, int16_t y, uint16_t color) { + setPixel(x, y, color, pcd8544_buffer); +} + +/*! + @brief The most basic function, set a single pixel + @param x x coord + @param y y coord + @param color pixel color (BLACK or WHITE) + @param buffer The framebuffer to set the pixel in + */ +void Adafruit_PCD8544::setPixel(int16_t x, int16_t y, bool color, + uint8_t *buffer) { + if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) + return; + + int16_t t; + switch (rotation) { + case 1: + t = x; + x = y; + y = LCDHEIGHT - 1 - t; + break; + case 2: + x = LCDWIDTH - 1 - x; + y = LCDHEIGHT - 1 - y; + break; + case 3: + t = x; + x = LCDWIDTH - 1 - y; + y = t; + break; + } + updateBoundingBox(x, y, x, y); + + // x is which column + if (color) + buffer[x + (y / 8) * LCDWIDTH] |= 1 << (y % 8); + else + buffer[x + (y / 8) * LCDWIDTH] &= ~(1 << (y % 8)); +} + +/*! + @brief The most basic function, get a single pixel + @param x x coord + @param y y coord + @param buffer The framebuffer to get the pixel from + @return color of the pixel at x,y + */ +bool Adafruit_PCD8544::getPixel(int16_t x, int16_t y, uint8_t *buffer) { + if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) + return false; + + int16_t t; + switch (rotation) { + case 1: + t = x; + x = y; + y = LCDHEIGHT - 1 - t; + break; + case 2: + x = LCDWIDTH - 1 - x; + y = LCDHEIGHT - 1 - y; + break; + case 3: + t = x; + x = LCDWIDTH - 1 - y; + y = t; + break; + } + + return (buffer[x + (y / 8) * LCDWIDTH] >> (y % 8)) & 0x1; +} + +/*! + @brief Initialize the display. Set bias and contrast, enter normal mode. + */ +void Adafruit_PCD8544::initDisplay() { + + // toggle RST low to reset + if (_rstpin >= 0) { + pinMode(_rstpin, OUTPUT); + digitalWrite(_rstpin, LOW); + delay(1); // 1 ns minimum + digitalWrite(_rstpin, HIGH); + } + + setBias(_bias); + setContrast(_contrast); + + // normal mode + command(PCD8544_FUNCTIONSET); + + // Set display to Normal + command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); +} + +/*! + @brief Set up SPI, initialize the display, set the bounding box + @param contrast Initial contrast value + @param bias Initial bias value + @returns True on initialization success + */ +bool Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) { + + if (!spi_dev->begin()) { + return false; + } + + // Set common pin outputs. + pinMode(_dcpin, OUTPUT); + if (_rstpin >= 0) + pinMode(_rstpin, OUTPUT); + + _bias = bias; + _contrast = contrast; + _reinit_interval = 0; + _display_count = 0; + initDisplay(); + + // 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(); + + return true; +} + +/*! + @brief Send a command to the LCD + @param c Command byte + */ +void Adafruit_PCD8544::command(uint8_t c) { + digitalWrite(_dcpin, LOW); + spi_dev->write(&c, 1); +} + +/*! + @brief Send data to the LCD + @param c Data byte + */ +void Adafruit_PCD8544::data(uint8_t c) { + digitalWrite(_dcpin, HIGH); + spi_dev->write(&c, 1); +} + +/*! + @brief Set the contrast level + @param val Contrast value + */ +void Adafruit_PCD8544::setContrast(uint8_t val) { + if (val > 0x7f) { + val = 0x7f; + } + _contrast = val; + command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION); + command(PCD8544_SETVOP | val); + command(PCD8544_FUNCTIONSET); +} + +/*! + @brief Set the bias level + @param val Bias value + */ +void Adafruit_PCD8544::setBias(uint8_t val) { + if (val > 0x07) { + val = 0x07; + } + _bias = val; + command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION); + command(PCD8544_SETBIAS | val); + command(PCD8544_FUNCTIONSET); +} + +/*! + @brief Get the bias level + @return Bias value + */ +uint8_t Adafruit_PCD8544::getBias() { return _bias; } + +/*! + @brief Get the contrast level + @return Contrast value + */ +uint8_t Adafruit_PCD8544::getContrast() { return _contrast; } + +/*! + @brief Set the interval for reinitializing the display + @param val Reinit after this many calls to display() + */ +void Adafruit_PCD8544::setReinitInterval(uint8_t val) { + _reinit_interval = val; +} + +/*! + @brief Get the reinit interval + @return Reinit interval + */ +uint8_t Adafruit_PCD8544::getReinitInterval() { return _reinit_interval; } + +/*! + @brief Update the display + */ +void Adafruit_PCD8544::display(void) { + if (_reinit_interval) { + _display_count++; + if (_display_count >= _reinit_interval) { + _display_count = 0; + initDisplay(); + } + } + + for (uint8_t page = (yUpdateMin / 8); page < (yUpdateMax / 8) + 1; page++) { + command(PCD8544_SETYADDR | page); + + uint8_t startcol = xUpdateMin; + uint8_t endcol = xUpdateMax; + + command(PCD8544_SETXADDR | startcol); + + digitalWrite(_dcpin, HIGH); + spi_dev->write(pcd8544_buffer + (LCDWIDTH * page) + startcol, + endcol - startcol + 1); + } + + command(PCD8544_SETYADDR); // no idea why this is necessary but it is to + // finish the last byte? + + xUpdateMin = LCDWIDTH - 1; + xUpdateMax = 0; + yUpdateMin = LCDHEIGHT - 1; + yUpdateMax = 0; +} + +/*! + @brief Clear the entire display + */ +void Adafruit_PCD8544::clearDisplay(void) { + memset(pcd8544_buffer, 0, LCDWIDTH * LCDHEIGHT / 8); + updateBoundingBox(0, 0, LCDWIDTH - 1, LCDHEIGHT - 1); + cursor_y = cursor_x = 0; +} + +/*! + @brief Invert the entire display + @param i True to invert the display, false to keep it uninverted + */ +void Adafruit_PCD8544::invertDisplay(bool i) { + command(PCD8544_FUNCTIONSET); + command(PCD8544_DISPLAYCONTROL | + (i ? PCD8544_DISPLAYINVERTED : PCD8544_DISPLAYNORMAL)); +} + +/*! + @brief Scroll the display by creating a new buffer and moving each pixel + @param xpixels The x offset, can be negative to scroll backwards + @param ypixels The y offset, can be negative to scroll updwards + */ +void Adafruit_PCD8544::scroll(int8_t xpixels, int8_t ypixels) { + uint8_t new_buffer[LCDWIDTH * LCDHEIGHT / 8]; + memset(new_buffer, 0, LCDWIDTH * LCDHEIGHT / 8); + + // negative pixels wrap around + while (ypixels < 0) { + ypixels += height(); + } + ypixels %= height(); + while (xpixels < 0) { + xpixels += width(); + } + xpixels %= width(); + + for (int x = 0; x < width(); x++) { + for (int y = 0; y < height(); y++) { + if (getPixel(x, y, pcd8544_buffer)) { + int new_x = (x + xpixels) % _width; + int new_y = (y + ypixels) % _height; + setPixel(new_x, new_y, true, new_buffer); + } + } + } + memcpy(pcd8544_buffer, new_buffer, LCDWIDTH * LCDHEIGHT / 8); + updateBoundingBox(0, 0, LCDWIDTH - 1, LCDHEIGHT - 1); +} diff --git a/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.h b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.h new file mode 100644 index 000000000..a1e39ff1a --- /dev/null +++ b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/Adafruit_PCD8544.h @@ -0,0 +1,110 @@ +/**************************************************************************/ +/*! + @file Adafruit_PCD8544.h + + 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 +*/ +/**************************************************************************/ +#ifndef _ADAFRUIT_PCD8544_H +#define _ADAFRUIT_PCD8544_H + +#include "Arduino.h" +#include +#include +#include + +#define LCDWIDTH 84 ///< LCD is 84 pixels wide +#define LCDHEIGHT 48 ///< 48 pixels high + +#define PCD8544_POWERDOWN 0x04 ///< Function set, Power down mode +#define PCD8544_ENTRYMODE 0x02 ///< Function set, Entry mode +#define PCD8544_EXTENDEDINSTRUCTION \ + 0x01 ///< Function set, Extended instruction set control + +#define PCD8544_DISPLAYBLANK 0x0 ///< Display control, blank +#define PCD8544_DISPLAYNORMAL 0x4 ///< Display control, normal mode +#define PCD8544_DISPLAYALLON 0x1 ///< Display control, all segments on +#define PCD8544_DISPLAYINVERTED 0x5 ///< Display control, inverse mode + +#define PCD8544_FUNCTIONSET 0x20 ///< Basic instruction set +#define PCD8544_DISPLAYCONTROL \ + 0x08 ///< Basic instruction set - Set display configuration +#define PCD8544_SETYADDR \ + 0x40 ///< Basic instruction set - Set Y address of RAM, 0 <= Y <= 5 +#define PCD8544_SETXADDR \ + 0x80 ///< Basic instruction set - Set X address of RAM, 0 <= X <= 83 + +#define PCD8544_SETTEMP \ + 0x04 ///< Extended instruction set - Set temperature coefficient +#define PCD8544_SETBIAS 0x10 ///< Extended instruction set - Set bias system +#define PCD8544_SETVOP \ + 0x80 ///< Extended instruction set - Write Vop to register + +/**************************************************************************/ +/*! + @brief The PCD8544 LCD class + */ +class Adafruit_PCD8544 : public Adafruit_GFX { +public: + Adafruit_PCD8544(int8_t sclk_pin, int8_t din_pin, int8_t dc_pin, + int8_t cs_pin, int8_t rst_pin); + Adafruit_PCD8544(int8_t dc_pin, int8_t cs_pin, int8_t rst_pin, + SPIClass *theSPI = &SPI); + + virtual ~Adafruit_PCD8544() {} + + bool begin(uint8_t contrast = 40, uint8_t bias = 0x04); + + void command(uint8_t c); + void data(uint8_t c); + + void setContrast(uint8_t val); + uint8_t getContrast(void); + + uint8_t getBias(void); + void setBias(uint8_t val); + + void clearDisplay(void); + void display(); + void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, + uint8_t ymax); + + void setReinitInterval(uint8_t val); + uint8_t getReinitInterval(void); + + void drawPixel(int16_t x, int16_t y, uint16_t color); + void setPixel(int16_t x, int16_t y, bool color, uint8_t *buffer); + bool getPixel(int16_t x, int16_t y, uint8_t *buffer); + + void initDisplay(); + void invertDisplay(bool i); + void scroll(int8_t vpixels, int8_t hpixels); + +private: + Adafruit_SPIDevice *spi_dev = NULL; + int8_t _rstpin = -1, _dcpin = -1; + + uint8_t _contrast; ///< Contrast level, Vop + uint8_t _bias; ///< Bias value + uint8_t _reinit_interval; ///< Reinitialize the display after this many calls + ///< to display() + uint8_t _display_count; ///< Count for reinit interval + + uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax; +}; + +#endif diff --git a/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/README.md b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/README.md new file mode 100644 index 000000000..85d629075 --- /dev/null +++ b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/README.md @@ -0,0 +1,24 @@ +# Adafruit PCD8544 Nokia 5110 LCD Library [![Build Status](https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit-PCD8544-Nokia-5110-LCD-library/html/index.html) + +This is a library for our Monochrome Nokia 5110 LCD Displays + + Pick one up today in the Adafruit shop! + ------> https://www.adafruit.com/product/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 install, use the Arduino Library Manager to search for 'Adafruit VCNL4010' +and install the library. + +You will also need the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. +You can get it by searching for 'Adafruit GFX' in the Arduino Library Manager or check it out here: +https://github.com/adafruit/Adafruit-GFX-Library diff --git a/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/code-of-conduct.md b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/code-of-conduct.md new file mode 100644 index 000000000..8ee6e4498 --- /dev/null +++ b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/code-of-conduct.md @@ -0,0 +1,127 @@ +# Adafruit Community Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and leaders pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level or type of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +We are committed to providing a friendly, safe and welcoming environment for +all. + +Examples of behavior that contributes to creating a positive environment +include: + +* Be kind and courteous to others +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Collaborating with other community members +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and sexual attention or advances +* The use of inappropriate images, including in a community member's avatar +* The use of inappropriate language, including in a community member's nickname +* Any spamming, flaming, baiting or other attention-stealing behavior +* Excessive or unwelcome helping; answering outside the scope of the question + asked +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate + +The goal of the standards and moderation guidelines outlined here is to build +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. + +We value many things beyond technical expertise, including collaboration and +supporting others within our community. Providing a positive experience for +other community members can have a much more significant impact than simply +providing the correct answer. + +## Our Responsibilities + +Project leaders are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project leaders have the right and responsibility to remove, edit, or +reject messages, comments, commits, code, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any community member for other behaviors that they deem +inappropriate, threatening, offensive, or harmful. + +## Moderation + +Instances of behaviors that violate the Adafruit Community Code of Conduct +may be reported by any member of the community. Community members are +encouraged to report these situations, including situations they witness +involving other community members. + +You may report in the following ways: + +In any situation, you may send an email to . + +On the Adafruit Discord, you may send an open message from any channel +to all Community Helpers by tagging @community helpers. You may also send an +open message from any channel, or a direct message to @kattni#1507, +@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or +@Andon#8175. + +Email and direct message reports will be kept confidential. + +In situations on Discord where the issue is particularly egregious, possibly +illegal, requires immediate action, or violates the Discord terms of service, +you should also report the message directly to Discord. + +These are the steps for upholding our community’s standards of conduct. + +1. Any member of the community may report any situation that violates the +Adafruit Community Code of Conduct. All reports will be reviewed and +investigated. +2. If the behavior is an egregious violation, the community member who +committed the violation may be banned immediately, without warning. +3. Otherwise, moderators will first respond to such behavior with a warning. +4. Moderators follow a soft "three strikes" policy - the community member may +be given another chance, if they are receptive to the warning and change their +behavior. +5. If the community member is unreceptive or unreasonable when warned by a +moderator, or the warning goes unheeded, they may be banned for a first or +second offense. Repeated offenses will result in the community member being +banned. + +## Scope + +This Code of Conduct and the enforcement policies listed above apply to all +Adafruit Community venues. This includes but is not limited to any community +spaces (both public and private), the entire Adafruit Discord server, and +Adafruit GitHub repositories. Examples of Adafruit Community spaces include +but are not limited to meet-ups, audio chats on the Adafruit Discord, or +interaction at a conference. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. As a community +member, you are representing our community, and are expected to behave +accordingly. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at +, +and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). + +For other projects adopting the Adafruit Community Code of +Conduct, please contact the maintainers of those projects for enforcement. +If you wish to use this code of conduct for your own project, consider +explicitly mentioning your moderation policy or making a copy with your +own moderation policy so as to avoid confusion. diff --git a/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/examples/pcdtest/pcdtest.ino b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/examples/pcdtest/pcdtest.ino new file mode 100644 index 000000000..54e6e8ed8 --- /dev/null +++ b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/examples/pcdtest/pcdtest.ino @@ -0,0 +1,377 @@ +/********************************************************************* +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 +#include +#include + +// Software SPI (slower updates, more flexible pin options): +// 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); + +// Hardware SPI (faster, but must use certain hardware pins): +// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno +// MOSI is LCD DIN - this is pin 11 on an Arduino Uno +// pin 5 - Data/Command select (D/C) +// pin 4 - LCD chip select (CS) +// pin 3 - LCD reset (RST) +// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3); +// Note with hardware SPI MISO and SS pins aren't used but will still be read +// and written to during SPI transfer. Be careful sharing these pins! + +#define NUMFLAKES 10 +#define XPOS 0 +#define YPOS 1 +#define DELTAY 2 + +#define BLACK 1 ///< Black pixel +#define WHITE 0 ///< White pixel + + +#define LOGO16_GLCD_HEIGHT 16 +#define LOGO16_GLCD_WIDTH 16 + +static const unsigned char PROGMEM logo16_glcd_bmp[] = +{ 0B00000000, 0B11000000, + 0B00000001, 0B11000000, + 0B00000001, 0B11000000, + 0B00000011, 0B11100000, + 0B11110011, 0B11100000, + 0B11111110, 0B11111000, + 0B01111110, 0B11111111, + 0B00110011, 0B10011111, + 0B00011111, 0B11111100, + 0B00001101, 0B01110000, + 0B00011011, 0B10100000, + 0B00111111, 0B11100000, + 0B00111111, 0B11110000, + 0B01111100, 0B11110000, + 0B01110000, 0B01110000, + 0B00000000, 0B00110000 }; + +void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { + uint8_t icons[NUMFLAKES][3]; + randomSeed(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], bitmap, w, h, BLACK); + } + display.display(); + delay(200); + + while(Serial.available()) { + switch (Serial.read()) { + case 'w':display.setContrast(display.getContrast() + 1); + break; + case 's':if(display.getContrast()) display.setContrast(display.getContrast() - 1); + break; + case 'e':display.setBias(display.getBias() + 1); + break; + case 'd':if(display.getBias()) display.setBias(display.getBias() - 1); + break; + case 'R':display.setReinitInterval(10); + break; + case 'r':display.initDisplay(); + display.setReinitInterval(0); + break; + } + } + Serial.print("contrast (w/s): 0x"); + Serial.print(display.getContrast(), HEX); + Serial.print(" bias (e/d): 0x"); + Serial.print(display.getBias(), HEX); + Serial.print(" reinitialize display (r/R): 0x"); + Serial.print(display.getReinitInterval(), HEX); + Serial.print(" \r"); + + // 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; i0; 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=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 +sentence=Arduino driver for PC8544, most commonly found in small Nokia 5110's +paragraph=Arduino driver for PC8544, most commonly found in small Nokia 5110's +category=Display +url=https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library +architectures=* +depends=Adafruit GFX Library, Adafruit BusIO diff --git a/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/license.txt b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/license.txt new file mode 100644 index 000000000..f6a0f22b8 --- /dev/null +++ b/lib/Adafruit-PCD8544-Nokia-5110-LCD-library/license.txt @@ -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.