├── library.properties ├── .github ├── workflows │ └── githubci.yml ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── README.md ├── license.txt ├── Adafruit_PCD8544.h ├── code-of-conduct.md ├── examples └── pcdtest │ └── pcdtest.ino └── Adafruit_PCD8544.cpp /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit PCD8544 Nokia 5110 LCD library 2 | version=2.0.3 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino driver for PC8544, most commonly found in small Nokia 5110's 6 | paragraph=Arduino driver for PC8544, most commonly found in small Nokia 5110's 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library 9 | architectures=* 10 | depends=Adafruit GFX Library, Adafruit BusIO 11 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Library CI 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/setup-python@v4 11 | with: 12 | python-version: '3.x' 13 | - uses: actions/checkout@v3 14 | - uses: actions/checkout@v3 15 | with: 16 | repository: adafruit/ci-arduino 17 | path: ci 18 | 19 | - name: pre-install 20 | run: bash ci/actions_install.sh 21 | 22 | - name: test platforms 23 | run: python3 ci/build_platform.py main_platforms 24 | 25 | - name: clang 26 | run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . 27 | 28 | - name: doxygen 29 | env: 30 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} 31 | PRETTYNAME : "Adafruit PCD8544 Nokia 5110 LCD library" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 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) 2 | 3 | This is a library for our Monochrome Nokia 5110 LCD Displays 4 | 5 | Pick one up today in the Adafruit shop! 6 | ------> https://www.adafruit.com/product/338 7 | 8 | These displays use SPI to communicate, 4 or 5 pins are required to 9 | interface. 10 | 11 | Adafruit invests time and resources providing this open source code, 12 | please support Adafruit and open-source hardware by purchasing 13 | products from Adafruit! 14 | 15 | Written by Limor Fried/Ladyada for Adafruit Industries. 16 | BSD license, check license.txt for more information. 17 | All text above must be included in any redistribution. 18 | 19 | To install, use the Arduino Library Manager to search for 'Adafruit VCNL4010' 20 | and install the library. 21 | 22 | You will also need the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. 23 | You can get it by searching for 'Adafruit GFX' in the Arduino Library Manager or check it out here: 24 | https://github.com/adafruit/Adafruit-GFX-Library 25 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /Adafruit_PCD8544.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************/ 2 | /*! 3 | @file Adafruit_PCD8544.h 4 | 5 | This is a library for our Monochrome Nokia 5110 LCD Displays 6 | 7 | Pick one up today in the adafruit shop! 8 | ------> http://www.adafruit.com/products/338 9 | 10 | These displays use SPI to communicate, 4 or 5 pins are required to 11 | interface 12 | 13 | Adafruit invests time and resources providing this open source code, 14 | please support Adafruit and open-source hardware by purchasing 15 | products from Adafruit! 16 | 17 | Written by Limor Fried/Ladyada for Adafruit Industries. 18 | BSD license, check license.txt for more information 19 | All text above, and the splash screen must be included in any redistribution 20 | */ 21 | /**************************************************************************/ 22 | #ifndef _ADAFRUIT_PCD8544_H 23 | #define _ADAFRUIT_PCD8544_H 24 | 25 | #include "Arduino.h" 26 | #include 27 | #include 28 | #include 29 | 30 | #define BLACK 1 ///< Black pixel 31 | #define WHITE 0 ///< White pixel 32 | 33 | #define LCDWIDTH 84 ///< LCD is 84 pixels wide 34 | #define LCDHEIGHT 48 ///< 48 pixels high 35 | 36 | #define PCD8544_POWERDOWN 0x04 ///< Function set, Power down mode 37 | #define PCD8544_ENTRYMODE 0x02 ///< Function set, Entry mode 38 | #define PCD8544_EXTENDEDINSTRUCTION \ 39 | 0x01 ///< Function set, Extended instruction set control 40 | 41 | #define PCD8544_DISPLAYBLANK 0x0 ///< Display control, blank 42 | #define PCD8544_DISPLAYNORMAL 0x4 ///< Display control, normal mode 43 | #define PCD8544_DISPLAYALLON 0x1 ///< Display control, all segments on 44 | #define PCD8544_DISPLAYINVERTED 0x5 ///< Display control, inverse mode 45 | 46 | #define PCD8544_FUNCTIONSET 0x20 ///< Basic instruction set 47 | #define PCD8544_DISPLAYCONTROL \ 48 | 0x08 ///< Basic instruction set - Set display configuration 49 | #define PCD8544_SETYADDR \ 50 | 0x40 ///< Basic instruction set - Set Y address of RAM, 0 <= Y <= 5 51 | #define PCD8544_SETXADDR \ 52 | 0x80 ///< Basic instruction set - Set X address of RAM, 0 <= X <= 83 53 | 54 | #define PCD8544_SETTEMP \ 55 | 0x04 ///< Extended instruction set - Set temperature coefficient 56 | #define PCD8544_SETBIAS 0x10 ///< Extended instruction set - Set bias system 57 | #define PCD8544_SETVOP \ 58 | 0x80 ///< Extended instruction set - Write Vop to register 59 | 60 | /**************************************************************************/ 61 | /*! 62 | @brief The PCD8544 LCD class 63 | */ 64 | class Adafruit_PCD8544 : public Adafruit_GFX { 65 | public: 66 | Adafruit_PCD8544(int8_t sclk_pin, int8_t din_pin, int8_t dc_pin, 67 | int8_t cs_pin, int8_t rst_pin); 68 | Adafruit_PCD8544(int8_t dc_pin, int8_t cs_pin, int8_t rst_pin, 69 | SPIClass *theSPI = &SPI); 70 | 71 | bool begin(uint8_t contrast = 40, uint8_t bias = 0x04); 72 | 73 | void command(uint8_t c); 74 | void data(uint8_t c); 75 | 76 | void setContrast(uint8_t val); 77 | uint8_t getContrast(void); 78 | 79 | uint8_t getBias(void); 80 | void setBias(uint8_t val); 81 | 82 | void clearDisplay(void); 83 | void display(); 84 | void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, 85 | uint8_t ymax); 86 | 87 | void setReinitInterval(uint8_t val); 88 | uint8_t getReinitInterval(void); 89 | 90 | void drawPixel(int16_t x, int16_t y, uint16_t color); 91 | void setPixel(int16_t x, int16_t y, bool color, uint8_t *buffer); 92 | bool getPixel(int16_t x, int16_t y, uint8_t *buffer); 93 | 94 | void initDisplay(); 95 | void invertDisplay(bool i); 96 | void scroll(int8_t vpixels, int8_t hpixels); 97 | 98 | private: 99 | Adafruit_SPIDevice *spi_dev = NULL; 100 | int8_t _rstpin = -1, _dcpin = -1; 101 | 102 | uint8_t _contrast; ///< Contrast level, Vop 103 | uint8_t _bias; ///< Bias value 104 | uint8_t _reinit_interval; ///< Reinitialize the display after this many calls 105 | ///< to display() 106 | uint8_t _display_count; ///< Count for reinit interval 107 | 108 | uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax; 109 | }; 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Adafruit Community Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and leaders pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level or type of 9 | experience, education, socio-economic status, nationality, personal appearance, 10 | race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | We are committed to providing a friendly, safe and welcoming environment for 15 | all. 16 | 17 | Examples of behavior that contributes to creating a positive environment 18 | include: 19 | 20 | * Be kind and courteous to others 21 | * Using welcoming and inclusive language 22 | * Being respectful of differing viewpoints and experiences 23 | * Collaborating with other community members 24 | * Gracefully accepting constructive criticism 25 | * Focusing on what is best for the community 26 | * Showing empathy towards other community members 27 | 28 | Examples of unacceptable behavior by participants include: 29 | 30 | * The use of sexualized language or imagery and sexual attention or advances 31 | * The use of inappropriate images, including in a community member's avatar 32 | * The use of inappropriate language, including in a community member's nickname 33 | * Any spamming, flaming, baiting or other attention-stealing behavior 34 | * Excessive or unwelcome helping; answering outside the scope of the question 35 | asked 36 | * Trolling, insulting/derogatory comments, and personal or political attacks 37 | * Public or private harassment 38 | * Publishing others' private information, such as a physical or electronic 39 | address, without explicit permission 40 | * Other conduct which could reasonably be considered inappropriate 41 | 42 | The goal of the standards and moderation guidelines outlined here is to build 43 | and maintain a respectful community. We ask that you don’t just aim to be 44 | "technically unimpeachable", but rather try to be your best self. 45 | 46 | We value many things beyond technical expertise, including collaboration and 47 | supporting others within our community. Providing a positive experience for 48 | other community members can have a much more significant impact than simply 49 | providing the correct answer. 50 | 51 | ## Our Responsibilities 52 | 53 | Project leaders are responsible for clarifying the standards of acceptable 54 | behavior and are expected to take appropriate and fair corrective action in 55 | response to any instances of unacceptable behavior. 56 | 57 | Project leaders have the right and responsibility to remove, edit, or 58 | reject messages, comments, commits, code, issues, and other contributions 59 | that are not aligned to this Code of Conduct, or to ban temporarily or 60 | permanently any community member for other behaviors that they deem 61 | inappropriate, threatening, offensive, or harmful. 62 | 63 | ## Moderation 64 | 65 | Instances of behaviors that violate the Adafruit Community Code of Conduct 66 | may be reported by any member of the community. Community members are 67 | encouraged to report these situations, including situations they witness 68 | involving other community members. 69 | 70 | You may report in the following ways: 71 | 72 | In any situation, you may send an email to . 73 | 74 | On the Adafruit Discord, you may send an open message from any channel 75 | to all Community Helpers by tagging @community helpers. You may also send an 76 | open message from any channel, or a direct message to @kattni#1507, 77 | @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or 78 | @Andon#8175. 79 | 80 | Email and direct message reports will be kept confidential. 81 | 82 | In situations on Discord where the issue is particularly egregious, possibly 83 | illegal, requires immediate action, or violates the Discord terms of service, 84 | you should also report the message directly to Discord. 85 | 86 | These are the steps for upholding our community’s standards of conduct. 87 | 88 | 1. Any member of the community may report any situation that violates the 89 | Adafruit Community Code of Conduct. All reports will be reviewed and 90 | investigated. 91 | 2. If the behavior is an egregious violation, the community member who 92 | committed the violation may be banned immediately, without warning. 93 | 3. Otherwise, moderators will first respond to such behavior with a warning. 94 | 4. Moderators follow a soft "three strikes" policy - the community member may 95 | be given another chance, if they are receptive to the warning and change their 96 | behavior. 97 | 5. If the community member is unreceptive or unreasonable when warned by a 98 | moderator, or the warning goes unheeded, they may be banned for a first or 99 | second offense. Repeated offenses will result in the community member being 100 | banned. 101 | 102 | ## Scope 103 | 104 | This Code of Conduct and the enforcement policies listed above apply to all 105 | Adafruit Community venues. This includes but is not limited to any community 106 | spaces (both public and private), the entire Adafruit Discord server, and 107 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 108 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 109 | interaction at a conference. 110 | 111 | This Code of Conduct applies both within project spaces and in public spaces 112 | when an individual is representing the project or its community. As a community 113 | member, you are representing our community, and are expected to behave 114 | accordingly. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 1.4, available at 120 | , 121 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 122 | 123 | For other projects adopting the Adafruit Community Code of 124 | Conduct, please contact the maintainers of those projects for enforcement. 125 | If you wish to use this code of conduct for your own project, consider 126 | explicitly mentioning your moderation policy or making a copy with your 127 | own moderation policy so as to avoid confusion. 128 | -------------------------------------------------------------------------------- /examples/pcdtest/pcdtest.ino: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is an example sketch for our Monochrome Nokia 5110 LCD Displays 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/products/338 6 | 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | BSD license, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | // Software SPI (slower updates, more flexible pin options): 24 | // pin 7 - Serial clock out (SCLK) 25 | // pin 6 - Serial data out (DIN) 26 | // pin 5 - Data/Command select (D/C) 27 | // pin 4 - LCD chip select (CS) 28 | // pin 3 - LCD reset (RST) 29 | Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); 30 | 31 | // Hardware SPI (faster, but must use certain hardware pins): 32 | // SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno 33 | // MOSI is LCD DIN - this is pin 11 on an Arduino Uno 34 | // pin 5 - Data/Command select (D/C) 35 | // pin 4 - LCD chip select (CS) 36 | // pin 3 - LCD reset (RST) 37 | // Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3); 38 | // Note with hardware SPI MISO and SS pins aren't used but will still be read 39 | // and written to during SPI transfer. Be careful sharing these pins! 40 | 41 | #define NUMFLAKES 10 42 | #define XPOS 0 43 | #define YPOS 1 44 | #define DELTAY 2 45 | 46 | 47 | #define LOGO16_GLCD_HEIGHT 16 48 | #define LOGO16_GLCD_WIDTH 16 49 | 50 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 51 | { 0B00000000, 0B11000000, 52 | 0B00000001, 0B11000000, 53 | 0B00000001, 0B11000000, 54 | 0B00000011, 0B11100000, 55 | 0B11110011, 0B11100000, 56 | 0B11111110, 0B11111000, 57 | 0B01111110, 0B11111111, 58 | 0B00110011, 0B10011111, 59 | 0B00011111, 0B11111100, 60 | 0B00001101, 0B01110000, 61 | 0B00011011, 0B10100000, 62 | 0B00111111, 0B11100000, 63 | 0B00111111, 0B11110000, 64 | 0B01111100, 0B11110000, 65 | 0B01110000, 0B01110000, 66 | 0B00000000, 0B00110000 }; 67 | 68 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 69 | uint8_t icons[NUMFLAKES][3]; 70 | randomSeed(666); // whatever seed 71 | 72 | // initialize 73 | for (uint8_t f=0; f< NUMFLAKES; f++) { 74 | icons[f][XPOS] = random(display.width()); 75 | icons[f][YPOS] = 0; 76 | icons[f][DELTAY] = random(5) + 1; 77 | 78 | Serial.print("x: "); 79 | Serial.print(icons[f][XPOS], DEC); 80 | Serial.print(" y: "); 81 | Serial.print(icons[f][YPOS], DEC); 82 | Serial.print(" dy: "); 83 | Serial.println(icons[f][DELTAY], DEC); 84 | } 85 | 86 | while (1) { 87 | // draw each icon 88 | for (uint8_t f=0; f< NUMFLAKES; f++) { 89 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); 90 | } 91 | display.display(); 92 | delay(200); 93 | 94 | while(Serial.available()) { 95 | switch (Serial.read()) { 96 | case 'w':display.setContrast(display.getContrast() + 1); 97 | break; 98 | case 's':if(display.getContrast()) display.setContrast(display.getContrast() - 1); 99 | break; 100 | case 'e':display.setBias(display.getBias() + 1); 101 | break; 102 | case 'd':if(display.getBias()) display.setBias(display.getBias() - 1); 103 | break; 104 | case 'R':display.setReinitInterval(10); 105 | break; 106 | case 'r':display.initDisplay(); 107 | display.setReinitInterval(0); 108 | break; 109 | } 110 | } 111 | Serial.print("contrast (w/s): 0x"); 112 | Serial.print(display.getContrast(), HEX); 113 | Serial.print(" bias (e/d): 0x"); 114 | Serial.print(display.getBias(), HEX); 115 | Serial.print(" reinitialize display (r/R): 0x"); 116 | Serial.print(display.getReinitInterval(), HEX); 117 | Serial.print(" \r"); 118 | 119 | // then erase it + move it 120 | for (uint8_t f=0; f< NUMFLAKES; f++) { 121 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); 122 | // move it 123 | icons[f][YPOS] += icons[f][DELTAY]; 124 | // if its gone, reinit 125 | if (icons[f][YPOS] > display.height()) { 126 | icons[f][XPOS] = random(display.width()); 127 | icons[f][YPOS] = 0; 128 | icons[f][DELTAY] = random(5) + 1; 129 | } 130 | } 131 | } 132 | } 133 | 134 | 135 | void testdrawchar(void) { 136 | display.setTextSize(1); 137 | display.setTextColor(BLACK); 138 | display.setCursor(0,0); 139 | 140 | for (uint8_t i=0; i < 168; i++) { 141 | if (i == '\n') continue; 142 | display.write(i); 143 | //if ((i > 0) && (i % 14 == 0)) 144 | //display.println(); 145 | } 146 | display.display(); 147 | } 148 | 149 | void testdrawcircle(void) { 150 | for (int16_t i=0; i0; i-=5) { 178 | display.fillTriangle(display.width()/2, display.height()/2-i, 179 | display.width()/2-i, display.height()/2+i, 180 | display.width()/2+i, display.height()/2+i, color); 181 | if (color == WHITE) color = BLACK; 182 | else color = WHITE; 183 | display.display(); 184 | } 185 | } 186 | 187 | void testdrawroundrect(void) { 188 | for (int16_t i=0; i=0; i-=4) { 228 | display.drawLine(0, display.height()-1, display.width()-1, i, BLACK); 229 | display.display(); 230 | } 231 | delay(250); 232 | 233 | display.clearDisplay(); 234 | for (int16_t i=display.width()-1; i>=0; i-=4) { 235 | display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK); 236 | display.display(); 237 | } 238 | for (int16_t i=display.height()-1; i>=0; i-=4) { 239 | display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK); 240 | display.display(); 241 | } 242 | delay(250); 243 | 244 | display.clearDisplay(); 245 | for (int16_t i=0; i http://www.adafruit.com/products/338 13 | 14 | These displays use SPI to communicate, 4 or 5 pins are required to 15 | interface 16 | 17 | Adafruit invests time and resources providing this open source code, 18 | please support Adafruit and open-source hardware by purchasing 19 | products from Adafruit! 20 | 21 | @section author Author 22 | 23 | Written by Limor Fried/Ladyada for Adafruit Industries. 24 | 25 | @section license License 26 | 27 | BSD license, check license.txt for more information 28 | All text above, and the splash screen below must be included in any 29 | redistribution 30 | 31 | */ 32 | /**************************************************************************/ 33 | 34 | #include "Adafruit_PCD8544.h" 35 | #include "Arduino.h" 36 | #include 37 | 38 | /** the memory buffer for the LCD */ 39 | uint8_t pcd8544_buffer[LCDWIDTH * LCDHEIGHT / 8] = { 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 49 | 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 50 | 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 51 | 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 56 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 57 | 0x9F, 0xFF, 0xFF, 0xFF, 0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 58 | 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 59 | 0xF0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 63 | 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87, 64 | 0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 65 | 0xF8, 0xF8, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 66 | 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 70 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x7E, 0x3F, 0x3F, 0x0F, 71 | 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 72 | 0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 73 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 76 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 77 | 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 78 | 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 79 | 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 82 | }; 83 | 84 | /*! 85 | @brief Update the bounding box for partial updates 86 | @param xmin left 87 | @param ymin bottom 88 | @param xmax right 89 | @param ymax top 90 | */ 91 | void Adafruit_PCD8544::updateBoundingBox(uint8_t xmin, uint8_t ymin, 92 | uint8_t xmax, uint8_t ymax) { 93 | xUpdateMin = min(xUpdateMin, xmin); 94 | xUpdateMax = max(xUpdateMax, xmax); 95 | yUpdateMin = min(yUpdateMin, ymin); 96 | yUpdateMax = max(yUpdateMax, ymax); 97 | } 98 | 99 | /*! 100 | @brief Constructor for software SPI with explicit CS pin 101 | @param sclk_pin SCLK pin 102 | @param din_pin DIN pin 103 | @param dc_pin DC pin 104 | @param cs_pin CS pin 105 | @param rst_pin RST pin 106 | */ 107 | Adafruit_PCD8544::Adafruit_PCD8544(int8_t sclk_pin, int8_t din_pin, 108 | int8_t dc_pin, int8_t cs_pin, int8_t rst_pin) 109 | : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) { 110 | spi_dev = new Adafruit_SPIDevice(cs_pin, sclk_pin, -1, din_pin, 111 | 4000000); // 4mhz max speed 112 | 113 | _dcpin = dc_pin; 114 | _rstpin = rst_pin; 115 | } 116 | 117 | /*! 118 | @brief Constructor for hardware SPI based on hardware controlled SCK (SCLK) 119 | and MOSI (DIN) pins. CS is still controlled by any IO pin. NOTE: MISO and SS 120 | will be set as an input and output respectively, so be careful sharing those 121 | pins! 122 | @param dc_pin DC pin 123 | @param cs_pin CS pin 124 | @param rst_pin RST pin 125 | @param theSPI Pointer to SPIClass device for hardware SPI 126 | */ 127 | Adafruit_PCD8544::Adafruit_PCD8544(int8_t dc_pin, int8_t cs_pin, int8_t rst_pin, 128 | SPIClass *theSPI) 129 | : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) { 130 | spi_dev = new Adafruit_SPIDevice(cs_pin, 4000000, SPI_BITORDER_MSBFIRST, 131 | SPI_MODE0, theSPI); 132 | 133 | _dcpin = dc_pin; 134 | _rstpin = rst_pin; 135 | } 136 | 137 | /*! 138 | @brief The most basic function, set a single pixel, in the main buffer 139 | @param x x coord 140 | @param y y coord 141 | @param color pixel color (BLACK or WHITE) 142 | */ 143 | void Adafruit_PCD8544::drawPixel(int16_t x, int16_t y, uint16_t color) { 144 | setPixel(x, y, color, pcd8544_buffer); 145 | } 146 | 147 | /*! 148 | @brief The most basic function, set a single pixel 149 | @param x x coord 150 | @param y y coord 151 | @param color pixel color (BLACK or WHITE) 152 | @param buffer The framebuffer to set the pixel in 153 | */ 154 | void Adafruit_PCD8544::setPixel(int16_t x, int16_t y, bool color, 155 | uint8_t *buffer) { 156 | if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) 157 | return; 158 | 159 | int16_t t; 160 | switch (rotation) { 161 | case 1: 162 | t = x; 163 | x = y; 164 | y = LCDHEIGHT - 1 - t; 165 | break; 166 | case 2: 167 | x = LCDWIDTH - 1 - x; 168 | y = LCDHEIGHT - 1 - y; 169 | break; 170 | case 3: 171 | t = x; 172 | x = LCDWIDTH - 1 - y; 173 | y = t; 174 | break; 175 | } 176 | updateBoundingBox(x, y, x, y); 177 | 178 | // x is which column 179 | if (color) 180 | buffer[x + (y / 8) * LCDWIDTH] |= 1 << (y % 8); 181 | else 182 | buffer[x + (y / 8) * LCDWIDTH] &= ~(1 << (y % 8)); 183 | } 184 | 185 | /*! 186 | @brief The most basic function, get a single pixel 187 | @param x x coord 188 | @param y y coord 189 | @param buffer The framebuffer to get the pixel from 190 | @return color of the pixel at x,y 191 | */ 192 | bool Adafruit_PCD8544::getPixel(int16_t x, int16_t y, uint8_t *buffer) { 193 | if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) 194 | return false; 195 | 196 | int16_t t; 197 | switch (rotation) { 198 | case 1: 199 | t = x; 200 | x = y; 201 | y = LCDHEIGHT - 1 - t; 202 | break; 203 | case 2: 204 | x = LCDWIDTH - 1 - x; 205 | y = LCDHEIGHT - 1 - y; 206 | break; 207 | case 3: 208 | t = x; 209 | x = LCDWIDTH - 1 - y; 210 | y = t; 211 | break; 212 | } 213 | 214 | return (buffer[x + (y / 8) * LCDWIDTH] >> (y % 8)) & 0x1; 215 | } 216 | 217 | /*! 218 | @brief Initialize the display. Set bias and contrast, enter normal mode. 219 | */ 220 | void Adafruit_PCD8544::initDisplay() { 221 | 222 | // toggle RST low to reset 223 | if (_rstpin >= 0) { 224 | pinMode(_rstpin, OUTPUT); 225 | digitalWrite(_rstpin, LOW); 226 | delay(1); // 1 ns minimum 227 | digitalWrite(_rstpin, HIGH); 228 | } 229 | 230 | setBias(_bias); 231 | setContrast(_contrast); 232 | 233 | // normal mode 234 | command(PCD8544_FUNCTIONSET); 235 | 236 | // Set display to Normal 237 | command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); 238 | } 239 | 240 | /*! 241 | @brief Set up SPI, initialize the display, set the bounding box 242 | @param contrast Initial contrast value 243 | @param bias Initial bias value 244 | @returns True on initialization success 245 | */ 246 | bool Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) { 247 | 248 | if (!spi_dev->begin()) { 249 | return false; 250 | } 251 | 252 | // Set common pin outputs. 253 | pinMode(_dcpin, OUTPUT); 254 | if (_rstpin >= 0) 255 | pinMode(_rstpin, OUTPUT); 256 | 257 | _bias = bias; 258 | _contrast = contrast; 259 | _reinit_interval = 0; 260 | _display_count = 0; 261 | initDisplay(); 262 | 263 | // initial display line 264 | // set page address 265 | // set column address 266 | // write display data 267 | 268 | // set up a bounding box for screen updates 269 | 270 | updateBoundingBox(0, 0, LCDWIDTH - 1, LCDHEIGHT - 1); 271 | // Push out pcd8544_buffer to the Display (will show the AFI logo) 272 | display(); 273 | 274 | return true; 275 | } 276 | 277 | /*! 278 | @brief Send a command to the LCD 279 | @param c Command byte 280 | */ 281 | void Adafruit_PCD8544::command(uint8_t c) { 282 | digitalWrite(_dcpin, LOW); 283 | spi_dev->write(&c, 1); 284 | } 285 | 286 | /*! 287 | @brief Send data to the LCD 288 | @param c Data byte 289 | */ 290 | void Adafruit_PCD8544::data(uint8_t c) { 291 | digitalWrite(_dcpin, HIGH); 292 | spi_dev->write(&c, 1); 293 | } 294 | 295 | /*! 296 | @brief Set the contrast level 297 | @param val Contrast value 298 | */ 299 | void Adafruit_PCD8544::setContrast(uint8_t val) { 300 | if (val > 0x7f) { 301 | val = 0x7f; 302 | } 303 | _contrast = val; 304 | command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION); 305 | command(PCD8544_SETVOP | val); 306 | command(PCD8544_FUNCTIONSET); 307 | } 308 | 309 | /*! 310 | @brief Set the bias level 311 | @param val Bias value 312 | */ 313 | void Adafruit_PCD8544::setBias(uint8_t val) { 314 | if (val > 0x07) { 315 | val = 0x07; 316 | } 317 | _bias = val; 318 | command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION); 319 | command(PCD8544_SETBIAS | val); 320 | command(PCD8544_FUNCTIONSET); 321 | } 322 | 323 | /*! 324 | @brief Get the bias level 325 | @return Bias value 326 | */ 327 | uint8_t Adafruit_PCD8544::getBias() { return _bias; } 328 | 329 | /*! 330 | @brief Get the contrast level 331 | @return Contrast value 332 | */ 333 | uint8_t Adafruit_PCD8544::getContrast() { return _contrast; } 334 | 335 | /*! 336 | @brief Set the interval for reinitializing the display 337 | @param val Reinit after this many calls to display() 338 | */ 339 | void Adafruit_PCD8544::setReinitInterval(uint8_t val) { 340 | _reinit_interval = val; 341 | } 342 | 343 | /*! 344 | @brief Get the reinit interval 345 | @return Reinit interval 346 | */ 347 | uint8_t Adafruit_PCD8544::getReinitInterval() { return _reinit_interval; } 348 | 349 | /*! 350 | @brief Update the display 351 | */ 352 | void Adafruit_PCD8544::display(void) { 353 | if (_reinit_interval) { 354 | _display_count++; 355 | if (_display_count >= _reinit_interval) { 356 | _display_count = 0; 357 | initDisplay(); 358 | } 359 | } 360 | 361 | for (uint8_t page = (yUpdateMin / 8); page < (yUpdateMax / 8) + 1; page++) { 362 | command(PCD8544_SETYADDR | page); 363 | 364 | uint8_t startcol = xUpdateMin; 365 | uint8_t endcol = xUpdateMax; 366 | 367 | command(PCD8544_SETXADDR | startcol); 368 | 369 | digitalWrite(_dcpin, HIGH); 370 | spi_dev->write(pcd8544_buffer + (LCDWIDTH * page) + startcol, 371 | endcol - startcol + 1); 372 | } 373 | 374 | command(PCD8544_SETYADDR); // no idea why this is necessary but it is to 375 | // finish the last byte? 376 | 377 | xUpdateMin = LCDWIDTH - 1; 378 | xUpdateMax = 0; 379 | yUpdateMin = LCDHEIGHT - 1; 380 | yUpdateMax = 0; 381 | } 382 | 383 | /*! 384 | @brief Clear the entire display 385 | */ 386 | void Adafruit_PCD8544::clearDisplay(void) { 387 | memset(pcd8544_buffer, 0, LCDWIDTH * LCDHEIGHT / 8); 388 | updateBoundingBox(0, 0, LCDWIDTH - 1, LCDHEIGHT - 1); 389 | cursor_y = cursor_x = 0; 390 | } 391 | 392 | /*! 393 | @brief Invert the entire display 394 | @param i True to invert the display, false to keep it uninverted 395 | */ 396 | void Adafruit_PCD8544::invertDisplay(bool i) { 397 | command(PCD8544_FUNCTIONSET); 398 | command(PCD8544_DISPLAYCONTROL | 399 | (i ? PCD8544_DISPLAYINVERTED : PCD8544_DISPLAYNORMAL)); 400 | } 401 | 402 | /*! 403 | @brief Scroll the display by creating a new buffer and moving each pixel 404 | @param xpixels The x offset, can be negative to scroll backwards 405 | @param ypixels The y offset, can be negative to scroll updwards 406 | */ 407 | void Adafruit_PCD8544::scroll(int8_t xpixels, int8_t ypixels) { 408 | uint8_t new_buffer[LCDWIDTH * LCDHEIGHT / 8]; 409 | memset(new_buffer, 0, LCDWIDTH * LCDHEIGHT / 8); 410 | 411 | // negative pixels wrap around 412 | while (ypixels < 0) { 413 | ypixels += height(); 414 | } 415 | ypixels %= height(); 416 | while (xpixels < 0) { 417 | xpixels += width(); 418 | } 419 | xpixels %= width(); 420 | 421 | for (int x = 0; x < width(); x++) { 422 | for (int y = 0; y < height(); y++) { 423 | if (getPixel(x, y, pcd8544_buffer)) { 424 | int new_x = (x + xpixels) % _width; 425 | int new_y = (y + ypixels) % _height; 426 | setPixel(new_x, new_y, true, new_buffer); 427 | } 428 | } 429 | } 430 | memcpy(pcd8544_buffer, new_buffer, LCDWIDTH * LCDHEIGHT / 8); 431 | updateBoundingBox(0, 0, LCDWIDTH - 1, LCDHEIGHT - 1); 432 | } 433 | --------------------------------------------------------------------------------