├── examples ├── LCDGFXDemo │ ├── .esp8266.test.skip │ ├── README.md │ ├── smileytongue24.h │ ├── google32.h │ └── LCDGFXDemo.ino ├── displayOnOffTest │ └── displayOnOffTest.ino └── test │ └── test.ino ├── .gitignore ├── library.properties ├── .github ├── workflows │ └── githubci.yml ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── license.txt ├── README.md ├── Adafruit_SSD1331.h └── Adafruit_SSD1331.cpp /examples/LCDGFXDemo/.esp8266.test.skip: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Our handy .gitignore for automation ease 2 | Doxyfile* 3 | doxygen_sqlite3.db 4 | html 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit SSD1331 OLED Driver Library for Arduino 2 | version=1.3.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=For 0.96" OLEDs in the Adafruit shop 6 | paragraph=For 0.96" OLEDs in the Adafruit shop 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit-SSD1331-OLED-Driver-Library-for-Arduino 9 | architectures=* 10 | depends=Adafruit GFX Library 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 SSD1331 Arduino Library" 32 | run: bash ci/doxy_gen_and_deploy.sh 33 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Adafruit SSD1331 Arduino Library [![Build Status](https://github.com/adafruit/Adafruit-SSD1331-OLED-Driver-Library-for-Arduino/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-SSD1331-OLED-Driver-Library-for-Arduino/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit-SSD1331-OLED-Driver-Library-for-Arduino/html/index.html) 2 | This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/products/684 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 must be included in any redistribution 17 | 18 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_SSD1131. Check that the Adafruit_SSD1331 folder contains Adafruit_SSD1331.cpp and Adafruit_SSD1331.h 19 | 20 | Place the Adafruit_SSD1331 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. 21 | 22 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from 23 | https://github.com/adafruit/Adafruit-GFX-Library 24 | and download/install that library as well 25 | -------------------------------------------------------------------------------- /examples/LCDGFXDemo/README.md: -------------------------------------------------------------------------------- 1 | This is a hello world GFX demo written and ported to multiple GFX supported backends. 2 | 3 | It is not fully optimized for SD1331 but simply meant to show how it works on that backend, including the issue of clear() being slow. Pixmap sync was changed to work with and without full frame clear. In real life, code for these panels should be rewritten to only clear an area around the area being redrawn to avoid flashing and slower refreshes (HWSPI at full 80Mhz speed on ESP8266 can reach over 80fps but still shows noticeable flashing if you clear the whole screen before displaying the next frame). 4 | 5 | A lot of the demo code was meant for lower resolution displays (down to 8x8 or 16x8), see http://marc.merlins.org/perso/arduino/post_2017-04-24_Adafruit-GFX-on-NeoMatrix-and-RGB-Matrix-Panel-Demo.html , but it's interesting to see how the code and the GFX library scales from 8x8 to 96x64. 6 | 7 | ![image](https://user-images.githubusercontent.com/1369412/57587320-32682000-74b8-11e9-92c0-577df34d4447.png) 8 | ![image](https://user-images.githubusercontent.com/1369412/57587336-50ce1b80-74b8-11e9-9020-043a0eeaa01d.png) 9 | 10 | 11 | This same demo is already present in these trees: 12 | * https://github.com/adafruit/Adafruit_NeoMatrix/tree/master/examples/MatrixGFXDemo 13 | * https://github.com/adafruit/RGB-matrix-Panel/blob/master/examples/PanelGFXDemo_16x32/PanelGFXDemo_16x32.ino 14 | * https://github.com/marcmerlin/FastLED_NeoMatrix/tree/master/examples/MatrixGFXDemo 15 | * https://github.com/marcmerlin/LED-Matrix/blob/master/examples/directmatrix8x8_tricolor_direct_sr/directmatrix8x8_tricolor_direct_sr.ino 16 | * https://github.com/mrfaptastic/ESP32-RGB64x32MatrixPanel-I2S-DMA/blob/master/examples/PanelGFXDemo/PanelGFXDemo.ino 17 | * https://github.com/marcmerlin/SmartMatrix_GFX/tree/master/examples/MatrixGFXDemo 18 | -------------------------------------------------------------------------------- /.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_SSD1331.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_SSD1331.h 3 | */ 4 | 5 | #ifndef ADAFRUIT_SSD1331_H 6 | #define ADAFRUIT_SSD1331_H 7 | 8 | #include 9 | 10 | /*! 11 | * @brief Select one of these defines to set the pixel color order 12 | */ 13 | #define SSD1331_COLORORDER_RGB 14 | // #define SSD1331_COLORORDER_BGR 15 | 16 | #if defined SSD1331_COLORORDER_RGB && defined SSD1331_COLORORDER_BGR 17 | #error "RGB and BGR can not both be defined for SSD1331_COLORORDER." 18 | #endif 19 | 20 | // Timing Delays 21 | #define SSD1331_DELAYS_HWFILL (3) //!< Fill delay 22 | #define SSD1331_DELAYS_HWLINE (1) //!< Line delay 23 | 24 | // SSD1331 Commands 25 | #define SSD1331_CMD_DRAWLINE 0x21 //!< Draw line 26 | #define SSD1331_CMD_DRAWRECT 0x22 //!< Draw rectangle 27 | #define SSD1331_CMD_FILL 0x26 //!< Fill enable/disable 28 | #define SSD1331_CMD_SETCOLUMN 0x15 //!< Set column address 29 | #define SSD1331_CMD_SETROW 0x75 //!< Set row adress 30 | #define SSD1331_CMD_CONTRASTA 0x81 //!< Set contrast for color A 31 | #define SSD1331_CMD_CONTRASTB 0x82 //!< Set contrast for color B 32 | #define SSD1331_CMD_CONTRASTC 0x83 //!< Set contrast for color C 33 | #define SSD1331_CMD_MASTERCURRENT 0x87 //!< Master current control 34 | #define SSD1331_CMD_SETREMAP 0xA0 //!< Set re-map & data format 35 | #define SSD1331_CMD_STARTLINE 0xA1 //!< Set display start line 36 | #define SSD1331_CMD_DISPLAYOFFSET 0xA2 //!< Set display offset 37 | #define SSD1331_CMD_NORMALDISPLAY 0xA4 //!< Set display to normal mode 38 | #define SSD1331_CMD_DISPLAYALLON 0xA5 //!< Set entire display ON 39 | #define SSD1331_CMD_DISPLAYALLOFF 0xA6 //!< Set entire display OFF 40 | #define SSD1331_CMD_INVERTDISPLAY 0xA7 //!< Invert display 41 | #define SSD1331_CMD_SETMULTIPLEX 0xA8 //!< Set multiplex ratio 42 | #define SSD1331_CMD_SETMASTER 0xAD //!< Set master configuration 43 | #define SSD1331_CMD_DISPLAYOFF 0xAE //!< Display OFF (sleep mode) 44 | #define SSD1331_CMD_DISPLAYON 0xAF //!< Normal Brightness Display ON 45 | #define SSD1331_CMD_POWERMODE 0xB0 //!< Power save mode 46 | #define SSD1331_CMD_PRECHARGE 0xB1 //!< Phase 1 and 2 period adjustment 47 | #define SSD1331_CMD_CLOCKDIV \ 48 | 0xB3 //!< Set display clock divide ratio/oscillator frequency 49 | #define SSD1331_CMD_PRECHARGEA 0x8A //!< Set second pre-charge speed for color A 50 | #define SSD1331_CMD_PRECHARGEB 0x8B //!< Set second pre-charge speed for color B 51 | #define SSD1331_CMD_PRECHARGEC 0x8C //!< Set second pre-charge speed for color C 52 | #define SSD1331_CMD_PRECHARGELEVEL 0xBB //!< Set pre-charge voltage 53 | #define SSD1331_CMD_VCOMH 0xBE //!< Set Vcomh voltge 54 | 55 | /// Class to manage hardware interface with SSD1331 chipset 56 | class Adafruit_SSD1331 : public Adafruit_SPITFT { 57 | public: 58 | Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk, int8_t rst); 59 | Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t rst); 60 | // 3-4 args using hardware SPI (must specify peripheral) (reset optional) 61 | Adafruit_SSD1331(SPIClass *spi, int8_t cs, int8_t dc, int8_t rst = -1); 62 | 63 | // commands 64 | void begin(uint32_t begin = 8000000); 65 | void setRotation(uint8_t r); 66 | void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 67 | 68 | void enableDisplay(boolean enable); 69 | 70 | static const int16_t TFTWIDTH = 96; ///< The width of the display 71 | static const int16_t TFTHEIGHT = 64; ///< The height of the display 72 | 73 | private: 74 | }; 75 | 76 | #endif // ADAFRUIT_SSD1331_H -------------------------------------------------------------------------------- /examples/displayOnOffTest/displayOnOffTest.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an example sketch that shows how to toggle the SSD1331 OLED display 3 | * on and off at runtime to avoid screen burn-in. 4 | * 5 | * The sketch also demonstrates how to erase a previous value by re-drawing the 6 | * older value in the screen background color prior to writing a new value in 7 | * the same location. This avoids the need to call fillScreen() to erase the 8 | * entire screen followed by a complete redraw of screen contents. 9 | * 10 | * Written by Phill Kelley. BSD license. 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define SerialDebugging true 19 | 20 | // The SSD1331 is connected like this (plus VCC plus GND) 21 | const uint8_t OLED_pin_scl_sck = 13; 22 | const uint8_t OLED_pin_sda_mosi = 11; 23 | const uint8_t OLED_pin_cs_ss = 10; 24 | const uint8_t OLED_pin_res_rst = 9; 25 | const uint8_t OLED_pin_dc_rs = 8; 26 | 27 | // connect a push button to ... 28 | const uint8_t Button_pin = 2; 29 | 30 | // SSD1331 color definitions 31 | const uint16_t OLED_Color_Black = 0x0000; 32 | const uint16_t OLED_Color_Blue = 0x001F; 33 | const uint16_t OLED_Color_Red = 0xF800; 34 | const uint16_t OLED_Color_Green = 0x07E0; 35 | const uint16_t OLED_Color_Cyan = 0x07FF; 36 | const uint16_t OLED_Color_Magenta = 0xF81F; 37 | const uint16_t OLED_Color_Yellow = 0xFFE0; 38 | const uint16_t OLED_Color_White = 0xFFFF; 39 | 40 | // The colors we actually want to use 41 | uint16_t OLED_Text_Color = OLED_Color_Black; 42 | uint16_t OLED_Backround_Color = OLED_Color_Blue; 43 | 44 | // declare the display 45 | Adafruit_SSD1331 oled = 46 | Adafruit_SSD1331( 47 | OLED_pin_cs_ss, 48 | OLED_pin_dc_rs, 49 | OLED_pin_sda_mosi, 50 | OLED_pin_scl_sck, 51 | OLED_pin_res_rst 52 | ); 53 | 54 | // assume the display is off until configured in setup() 55 | bool isDisplayVisible = false; 56 | 57 | // declare size of working string buffers. Basic strlen("d hh:mm:ss") = 10 58 | const size_t MaxString = 16; 59 | 60 | // the string being displayed on the SSD1331 (initially empty) 61 | char oldTimeString[MaxString] = { 0 }; 62 | 63 | // the interrupt service routine affects this 64 | volatile bool isButtonPressed = false; 65 | 66 | 67 | // interrupt service routine 68 | void senseButtonPressed() { 69 | if (!isButtonPressed) { 70 | isButtonPressed = true; 71 | } 72 | } 73 | 74 | 75 | void displayUpTime() { 76 | 77 | // calculate seconds, truncated to the nearest whole second 78 | unsigned long upSeconds = millis() / 1000; 79 | 80 | // calculate days, truncated to nearest whole day 81 | unsigned long days = upSeconds / 86400; 82 | 83 | // the remaining hhmmss are 84 | upSeconds = upSeconds % 86400; 85 | 86 | // calculate hours, truncated to the nearest whole hour 87 | unsigned long hours = upSeconds / 3600; 88 | 89 | // the remaining mmss are 90 | upSeconds = upSeconds % 3600; 91 | 92 | // calculate minutes, truncated to the nearest whole minute 93 | unsigned long minutes = upSeconds / 60; 94 | 95 | // the remaining ss are 96 | upSeconds = upSeconds % 60; 97 | 98 | // allocate a buffer 99 | char newTimeString[MaxString] = { 0 }; 100 | 101 | // construct the string representation 102 | sprintf( 103 | newTimeString, 104 | "%lu %02lu:%02lu:%02lu", 105 | days, hours, minutes, upSeconds 106 | ); 107 | 108 | // has the time string changed since the last oled update? 109 | if (strcmp(newTimeString,oldTimeString) != 0) { 110 | 111 | // yes! home the cursor 112 | oled.setCursor(0,0); 113 | 114 | // change the text color to the background color 115 | oled.setTextColor(OLED_Backround_Color); 116 | 117 | // redraw the old value to erase 118 | oled.print(oldTimeString); 119 | 120 | // home the cursor 121 | oled.setCursor(0,0); 122 | 123 | // change the text color to foreground color 124 | oled.setTextColor(OLED_Text_Color); 125 | 126 | // draw the new time value 127 | oled.print(newTimeString); 128 | 129 | // and remember the new value 130 | strcpy(oldTimeString,newTimeString); 131 | 132 | } 133 | 134 | } 135 | 136 | 137 | void setup() { 138 | 139 | // button press pulls pin LOW so configure HIGH 140 | pinMode(Button_pin,INPUT_PULLUP); 141 | 142 | // use an interrupt to sense when the button is pressed 143 | attachInterrupt(digitalPinToInterrupt(Button_pin), senseButtonPressed, FALLING); 144 | 145 | #if (SerialDebugging) 146 | Serial.begin(115200); while (!Serial); Serial.println(); 147 | #endif 148 | 149 | // settling time 150 | delay(250); 151 | 152 | // ignore any power-on-reboot garbage 153 | isButtonPressed = false; 154 | 155 | // initialise the SSD1331 156 | oled.begin(); 157 | oled.setFont(); 158 | oled.fillScreen(OLED_Backround_Color); 159 | oled.setTextColor(OLED_Text_Color); 160 | oled.setTextSize(1); 161 | 162 | // the display is now on 163 | isDisplayVisible = true; 164 | 165 | } 166 | 167 | 168 | void loop() { 169 | 170 | // unconditional display, regardless of whether display is visible 171 | displayUpTime(); 172 | 173 | // has the button been pressed? 174 | if (isButtonPressed) { 175 | 176 | // yes! toggle display visibility 177 | isDisplayVisible = !isDisplayVisible; 178 | 179 | // apply 180 | oled.enableDisplay(isDisplayVisible); 181 | 182 | #if (SerialDebugging) 183 | Serial.print("button pressed @ "); 184 | Serial.print(millis()); 185 | Serial.print(", display is now "); 186 | Serial.println((isDisplayVisible ? "ON" : "OFF")); 187 | #endif 188 | 189 | // confirm button handled 190 | isButtonPressed = false; 191 | 192 | } 193 | 194 | // no need to be in too much of a hurry 195 | delay(100); 196 | 197 | } 198 | -------------------------------------------------------------------------------- /examples/LCDGFXDemo/smileytongue24.h: -------------------------------------------------------------------------------- 1 | // Generated by : UTFTConverter v0.1 2 | // Generated from : smiley_tongue_24.jpg 3 | // Time generated : 2017-04-24 16:31:50.352856 UTC 4 | // Image Size : 24x24 pixels 5 | // Memory usage : 1152 bytes 6 | 7 | #if defined(__AVR__) 8 | #include 9 | #elif defined(__PIC32MX__) 10 | #define PROGMEM 11 | #elif defined(__arm__) 12 | #define PROGMEM 13 | #endif 14 | 15 | const unsigned short 16 | bitmap24[576] PROGMEM = 17 | { 18 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 19 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 20 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0010 (16) pixels 21 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 22 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 23 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0020 (32) pixels 24 | 0x0000, 0x0000, 0x4207, 0xFFDD, 0xCE57, 0x0000, 25 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 26 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0030 (48) pixels 27 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 28 | 0x0000, 0xFFBB, 0xFF56, 0xE501, 0xE501, 0xE501, 29 | 0xE501, 0xE501, 0xE564, 0xFF99, // 0x0040 (64) pixels 30 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 31 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 32 | 0x0000, 0xAD33, 0xF6D1, 0xE501, // 0x0050 (80) pixels 33 | 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 34 | 0xE501, 0xE501, 0xE501, 0xFF9A, 0x0000, 0x0000, 35 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0060 (96) pixels 36 | 0x0000, 0x0000, 0x0000, 0x0000, 0xFFBB, 0xE501, 37 | 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 38 | 0xE501, 0xE501, 0xE501, 0xE501, // 0x0070 (112) pixels 39 | 0xE501, 0xE501, 0xFF57, 0x0000, 0x0000, 0x0000, 40 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFDC, 41 | 0xE501, 0xE501, 0xDD01, 0xE501, // 0x0080 (128) pixels 42 | 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 43 | 0xE501, 0xE501, 0xDD01, 0xE501, 0xE501, 0xFF78, 44 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0090 (144) pixels 45 | 0x0000, 0x0000, 0x0000, 0xE501, 0xDD01, 0xE501, 46 | 0xE501, 0xE501, 0xE501, 0xE501, 0xE502, 0xE501, 47 | 0xE501, 0xDD01, 0xDD01, 0xE501, // 0x00A0 (160) pixels 48 | 0xE501, 0xDD01, 0xE501, 0xE501, 0xE501, 0x0000, 49 | 0x0000, 0x0000, 0x0000, 0x0000, 0xFF99, 0xE501, 50 | 0xE502, 0xE501, 0x4A69, 0x4A6A, // 0x00B0 (176) pixels 51 | 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 52 | 0xE502, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 53 | 0xDD01, 0x0000, 0x0000, 0x0000, // 0x00C0 (192) pixels 54 | 0x0000, 0x0000, 0xE501, 0xE501, 0xE501, 0x0000, 55 | 0x0000, 0x0000, 0x0000, 0x94B2, 0xE501, 0xE502, 56 | 0xE501, 0xE501, 0xE501, 0xE501, // 0x00D0 (208) pixels 57 | 0xDD01, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 58 | 0x0000, 0x0000, 0x0000, 0xFFDC, 0xE501, 0xE501, 59 | 0xE501, 0x0000, 0x4A69, 0xE502, // 0x00E0 (224) pixels 60 | 0x4A69, 0x0000, 0xE501, 0xE501, 0xE501, 0xE501, 61 | 0xE501, 0x4A69, 0x0000, 0x0000, 0xE501, 0xE501, 62 | 0xE501, 0xFF58, 0x0000, 0x0000, // 0x00F0 (240) pixels 63 | 0x0000, 0xFF9A, 0xE501, 0xE501, 0xE501, 0xE501, 64 | 0xE501, 0xE501, 0xE501, 0x94B3, 0xE501, 0xE501, 65 | 0xE501, 0xE502, 0x0000, 0x0000, // 0x0100 (256) pixels 66 | 0x4A69, 0x0000, 0x0000, 0xE501, 0xE501, 0xE5A7, 67 | 0x0000, 0x0000, 0x0000, 0xFF79, 0xE501, 0xE501, 68 | 0xE501, 0xE501, 0xE501, 0xDD01, // 0x0110 (272) pixels 69 | 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 0xE502, 70 | 0x94B2, 0xE501, 0xE501, 0xE501, 0x0000, 0xDD01, 71 | 0xDD01, 0xE501, 0x0000, 0x0000, // 0x0120 (288) pixels 72 | 0x0000, 0xFF79, 0xE501, 0xE501, 0xFE31, 0xFD91, 73 | 0xF5B0, 0xF5F1, 0xF5EC, 0xE501, 0xDD01, 0xE501, 74 | 0xE501, 0xE501, 0xE501, 0xE501, // 0x0130 (304) pixels 75 | 0xE501, 0xE501, 0xE501, 0xE502, 0xE501, 0xE501, 76 | 0x0000, 0x0000, 0x0000, 0xFF9A, 0xE501, 0xE501, 77 | 0xFE31, 0xF4D0, 0xF800, 0xF800, // 0x0140 (320) pixels 78 | 0xF800, 0xDC4D, 0xE4AE, 0xE50F, 0xED90, 0xFE52, 79 | 0xE501, 0xE501, 0xE502, 0xE501, 0xE501, 0xE501, 80 | 0xE501, 0xEDA7, 0x0000, 0x0000, // 0x0150 (336) pixels 81 | 0x0000, 0xFFDC, 0xE501, 0xE501, 0xED66, 0xE48E, 82 | 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xDBAC, 83 | 0xE40D, 0xF4F0, 0xF4F0, 0xF530, // 0x0160 (352) pixels 84 | 0xFD91, 0xE501, 0xE501, 0xE501, 0xE501, 0xFF57, 85 | 0x0000, 0x0000, 0x0000, 0x0000, 0xE501, 0xE501, 86 | 0xE501, 0xF800, 0xF800, 0xF800, // 0x0170 (368) pixels 87 | 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 88 | 0xF800, 0xF4F0, 0xFDB1, 0xDD01, 0xE501, 0xE501, 89 | 0xE501, 0xE501, 0x0000, 0x0000, // 0x0180 (384) pixels 90 | 0x0000, 0x0000, 0xFF78, 0xE501, 0xED70, 0xF800, 91 | 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 92 | 0xF800, 0xF800, 0xF800, 0xF550, // 0x0190 (400) pixels 93 | 0xE501, 0xE501, 0xDD01, 0xE501, 0xE501, 0x0000, 94 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xE501, 95 | 0xE50E, 0xF800, 0xF800, 0xF800, // 0x01A0 (416) pixels 96 | 0xF800, 0xF800, 0xF800, 0xF800, 0xF800, 0xF4F0, 97 | 0xF550, 0xE501, 0xE501, 0xE501, 0xE501, 0xE501, 98 | 0xE501, 0x0000, 0x0000, 0x0000, // 0x01B0 (432) pixels 99 | 0x0000, 0x0000, 0x0000, 0xFFBC, 0xED90, 0xDC0D, 100 | 0xE30A, 0xF800, 0xF800, 0xDC0C, 0xE46E, 0xF510, 101 | 0xF570, 0xFE11, 0xE501, 0xE502, // 0x01C0 (448) pixels 102 | 0xDD01, 0xE501, 0xE501, 0xFF77, 0x0000, 0x0000, 103 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 104 | 0xFF7A, 0xE4AE, 0xE3CB, 0xE36A, // 0x01D0 (464) pixels 105 | 0xDBCC, 0xDC8E, 0xE501, 0xE501, 0xE501, 0xE501, 106 | 0xE501, 0xE501, 0xE501, 0xE501, 0xFF57, 0x0000, 107 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x01E0 (480) pixels 108 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFF9C, 109 | 0xEDD2, 0xED2F, 0xEDB0, 0xDD01, 0xE501, 0xE501, 110 | 0xDD01, 0xE501, 0xE521, 0xE501, // 0x01F0 (496) pixels 111 | 0xE501, 0xFF99, 0x0000, 0x0000, 0x0000, 0x0000, 112 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 113 | 0x0000, 0x0000, 0x0000, 0xFFBB, // 0x0200 (512) pixels 114 | 0xFF55, 0xE501, 0xE501, 0xE501, 0xE501, 0xE502, 115 | 0xE501, 0xFF79, 0x0000, 0x0000, 0x0000, 0x0000, 116 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0210 (528) pixels 117 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 118 | 0x0000, 0x0000, 0x0000, 0x0000, 0xEF5B, 0xE501, 119 | 0xE501, 0x2103, 0x0000, 0x0000, // 0x0220 (544) pixels 120 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 121 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 122 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 123 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 124 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 125 | 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels 126 | }; 127 | -------------------------------------------------------------------------------- /Adafruit_SSD1331.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file Adafruit_SSD1331.cpp 3 | * 4 | * @mainpage Adafruit SSD1331 Arduino Library 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip 9 | * 10 | * Pick one up today in the adafruit shop! 11 | * ------> http://www.adafruit.com/products/684 12 | * 13 | * These displays use SPI to communicate, 4 or 5 pins are required to 14 | * interface 15 | * Adafruit invests time and resources providing this open source code, 16 | * please support Adafruit and open-source hardware by purchasing 17 | * products from Adafruit! 18 | * 19 | * @section author Author 20 | * 21 | * Written by Limor Fried/Ladyada for Adafruit Industries. 22 | * 23 | * @section license License 24 | * 25 | * BSD license, all text above must be included in any redistribution 26 | */ 27 | 28 | #include "Adafruit_SSD1331.h" 29 | 30 | /***********************************/ 31 | 32 | #define ssd1331_swap(a, b) \ 33 | (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) ///< No-temp-var swap operation 34 | 35 | /*! 36 | @brief SPI displays set an address window rectangle for blitting pixels 37 | @param x Top left corner x coordinate 38 | @param y Top left corner x coordinate 39 | @param w Width of window 40 | @param h Height of window 41 | */ 42 | void Adafruit_SSD1331::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, 43 | uint16_t h) { 44 | uint8_t x1 = x; 45 | uint8_t y1 = y; 46 | if (x1 > _width - 1) 47 | x1 = _width - 1; 48 | if (y1 > _height - 1) 49 | y1 = _height - 1; 50 | 51 | uint8_t x2 = (x + w - 1); 52 | uint8_t y2 = (y + h - 1); 53 | if (x2 > _width - 1) 54 | x2 = _width - 1; 55 | if (y2 > _height - 1) 56 | y2 = _height - 1; 57 | 58 | if (x1 > x2) { 59 | ssd1331_swap(x1, x2); 60 | } 61 | if (y1 > y2) { 62 | ssd1331_swap(y1, y2); 63 | } 64 | 65 | if (rotation & 1) { // Vertical address increment mode 66 | ssd1331_swap(x1, y1); 67 | ssd1331_swap(x2, y2); 68 | } 69 | 70 | SPI_DC_LOW(); // Command mode 71 | 72 | spiWrite(SSD1331_CMD_SETCOLUMN); // Column addr set 73 | spiWrite(x1); 74 | spiWrite(x2); 75 | 76 | spiWrite(SSD1331_CMD_SETROW); // Row addr set 77 | spiWrite(y1); 78 | spiWrite(y2); 79 | SPI_DC_HIGH(); // Exit Command mode 80 | } 81 | 82 | /**************************************************************************/ 83 | /*! 84 | @brief Initialize SSD1331 chip 85 | Connects to the SSD1331 over SPI and sends initialization procedure commands 86 | @param freq Desired SPI clock frequency 87 | */ 88 | /**************************************************************************/ 89 | void Adafruit_SSD1331::begin(uint32_t freq) { 90 | initSPI(freq); 91 | 92 | // Initialization Sequence 93 | sendCommand(SSD1331_CMD_DISPLAYOFF); // 0xAE 94 | sendCommand(SSD1331_CMD_SETREMAP); // 0xA0 95 | sendCommand(SSD1331_CMD_STARTLINE); // 0xA1 96 | sendCommand(0x0); 97 | sendCommand(SSD1331_CMD_DISPLAYOFFSET); // 0xA2 98 | sendCommand(0x0); 99 | sendCommand(SSD1331_CMD_NORMALDISPLAY); // 0xA4 100 | sendCommand(SSD1331_CMD_SETMULTIPLEX); // 0xA8 101 | sendCommand(0x3F); // 0x3F 1/64 duty 102 | sendCommand(SSD1331_CMD_SETMASTER); // 0xAD 103 | sendCommand(0x8E); 104 | sendCommand(SSD1331_CMD_POWERMODE); // 0xB0 105 | sendCommand(0x0B); 106 | sendCommand(SSD1331_CMD_PRECHARGE); // 0xB1 107 | sendCommand(0x31); 108 | sendCommand(SSD1331_CMD_CLOCKDIV); // 0xB3 109 | sendCommand(0xF0); // 7:4 = Oscillator Frequency, 3:0 = CLK Div Ratio 110 | // (A[3:0]+1 = 1..16) 111 | sendCommand(SSD1331_CMD_PRECHARGEA); // 0x8A 112 | sendCommand(0x64); 113 | sendCommand(SSD1331_CMD_PRECHARGEB); // 0x8B 114 | sendCommand(0x78); 115 | sendCommand(SSD1331_CMD_PRECHARGEC); // 0x8C 116 | sendCommand(0x64); 117 | sendCommand(SSD1331_CMD_PRECHARGELEVEL); // 0xBB 118 | sendCommand(0x3A); 119 | sendCommand(SSD1331_CMD_VCOMH); // 0xBE 120 | sendCommand(0x3E); 121 | sendCommand(SSD1331_CMD_MASTERCURRENT); // 0x87 122 | sendCommand(0x06); 123 | sendCommand(SSD1331_CMD_CONTRASTA); // 0x81 124 | sendCommand(0x91); 125 | sendCommand(SSD1331_CMD_CONTRASTB); // 0x82 126 | sendCommand(0x50); 127 | sendCommand(SSD1331_CMD_CONTRASTC); // 0x83 128 | sendCommand(0x7D); 129 | sendCommand(SSD1331_CMD_DISPLAYON); //--turn on oled panel 130 | _width = TFTWIDTH; 131 | _height = TFTHEIGHT; 132 | setRotation(0); 133 | } 134 | 135 | /**************************************************************************/ 136 | /*! 137 | @brief Instantiate Adafruit SSD1331 driver with software SPI 138 | @param cs Chip select pin # 139 | @param dc Data/Command pin # 140 | @param mosi SPI MOSI pin # 141 | @param sclk SPI Clock pin # 142 | @param rst Reset pin # (optional, pass -1 if unused) 143 | */ 144 | /**************************************************************************/ 145 | Adafruit_SSD1331::Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t mosi, 146 | int8_t sclk, int8_t rst) 147 | : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, mosi, sclk, rst, -1) {} 148 | 149 | /**************************************************************************/ 150 | /*! 151 | @brief Instantiate Adafruit SSD1331 driver with hardware SPI 152 | @param cs Chip select pin # 153 | @param dc Data/Command pin # 154 | @param rst Reset pin # (optional, pass -1 if unused) 155 | */ 156 | /**************************************************************************/ 157 | Adafruit_SSD1331::Adafruit_SSD1331(int8_t cs, int8_t dc, int8_t rst) 158 | : Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, rst) {} 159 | 160 | /**************************************************************************/ 161 | /*! 162 | @brief Instantiate Adafruit SSD1331 driver with hardware SPI 163 | @param spi Pointer to an existing SPIClass instance (e.g. &SPI, the 164 | microcontroller's primary SPI bus). 165 | @param cs Chip select pin # 166 | @param dc Data/Command pin # 167 | @param rst Reset pin # (optional, pass -1 if unused) 168 | */ 169 | /**************************************************************************/ 170 | Adafruit_SSD1331::Adafruit_SSD1331(SPIClass *spi, int8_t cs, int8_t dc, 171 | int8_t rst) 172 | : 173 | #if defined(ESP8266) 174 | Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, cs, dc, rst) { 175 | #else 176 | Adafruit_SPITFT(TFTWIDTH, TFTHEIGHT, spi, cs, dc, rst) { 177 | #endif 178 | } 179 | 180 | /**************************************************************************/ 181 | /*! 182 | @brief Change whether display is on or off 183 | @param enable True if you want the display ON, false OFF 184 | */ 185 | /**************************************************************************/ 186 | void Adafruit_SSD1331::enableDisplay(boolean enable) { 187 | sendCommand(enable ? SSD1331_CMD_DISPLAYON : SSD1331_CMD_DISPLAYOFF); 188 | } 189 | 190 | /**************************************************************************/ 191 | /*! 192 | @brief Set origin of (0,0) and orientation of OLED display 193 | @param r 194 | The index for rotation, from 0-3 inclusive 195 | @return None (void). 196 | @note SSD1331 works differently than most (all?) other SPITFT 197 | displays. With certain rotation changes the screen contents 198 | may change immediately into a peculiar format (mirrored, not 199 | necessarily rotated) (other displays, this only affects new 200 | drawing -- rotation combinations can apply to different 201 | areas). Therefore, it's recommend to clear the screen 202 | (fillScreen(0)) before changing rotation. 203 | */ 204 | /**************************************************************************/ 205 | void Adafruit_SSD1331::setRotation(uint8_t r) { 206 | // madctl bits: 207 | // 6,7 Color depth (01 = 64K) 208 | // 5 Odd/even split COM (0: disable, 1: enable) 209 | // 4 Scan direction (0: top-down, 1: bottom-up) 210 | // 3 Left-Right swapping on COM (0: disable, 1: enable) 211 | // 2 Color remap (0: A->B->C, 1: C->B->A) 212 | // 1 Column remap (0: 0-95, 1: 95-0) 213 | // 0 Address increment (0: horizontal, 1: vertical) 214 | 215 | #if defined SSD1331_COLORORDER_RGB 216 | uint8_t madctl = 0b01100000; // 64K, enable split, ABC 217 | #else 218 | uint8_t madctl = 0b01100100; // 64K, enable split, CBA 219 | #endif 220 | rotation = r & 3; // Clip input to valid range 221 | 222 | switch (rotation) { 223 | case 0: 224 | madctl |= 0b00010010; // Scan bottom-up, column remap 95-0 225 | _width = WIDTH; 226 | _height = HEIGHT; 227 | break; 228 | case 1: 229 | madctl |= 0b00000011; // column remap 95-0, vertical 230 | _width = HEIGHT; 231 | _height = WIDTH; 232 | break; 233 | case 2: 234 | madctl |= 0b00000000; // None 235 | _width = WIDTH; 236 | _height = HEIGHT; 237 | break; 238 | case 3: 239 | madctl |= 0b00010001; // Scan bottom-up, Vertical 240 | _width = HEIGHT; 241 | _height = WIDTH; 242 | break; 243 | } 244 | 245 | sendCommand(SSD1331_CMD_SETREMAP); 246 | sendCommand(madctl); 247 | } 248 | -------------------------------------------------------------------------------- /examples/test/test.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a example sketch demonstrating the graphics 3 | capabilities of the SSD1331 library for the 0.96" 4 | 16-bit Color OLED with SSD1331 driver chip 5 | 6 | Pick one up today in the adafruit shop! 7 | ------> http://www.adafruit.com/products/684 8 | 9 | These displays use SPI to communicate, 4 or 5 pins are required to 10 | interface 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, all text above must be included in any redistribution 17 | ****************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | // You can use any (4 or) 5 pins 25 | #define sclk 13 26 | #define mosi 11 27 | #define cs 10 28 | #define rst 9 29 | #define dc 8 30 | 31 | 32 | // Color definitions 33 | #define BLACK 0x0000 34 | #define BLUE 0x001F 35 | #define RED 0xF800 36 | #define GREEN 0x07E0 37 | #define CYAN 0x07FF 38 | #define MAGENTA 0xF81F 39 | #define YELLOW 0xFFE0 40 | #define WHITE 0xFFFF 41 | 42 | // Option 1: use any pins but a little slower 43 | //Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst); 44 | 45 | // Option 2: must use the hardware SPI pins 46 | // (for UNO thats sclk = 13 and sid = 11) and pin 10 must be 47 | // an output. This is much faster - also required if you want 48 | // to use the microSD card (see the image drawing example) 49 | Adafruit_SSD1331 display = Adafruit_SSD1331(&SPI, cs, dc, rst); 50 | 51 | float p = 3.1415926; 52 | 53 | void setup(void) { 54 | Serial.begin(9600); 55 | Serial.print("hello!"); 56 | display.begin(); 57 | 58 | Serial.println("init"); 59 | uint16_t time = millis(); 60 | display.fillScreen(BLACK); 61 | time = millis() - time; 62 | 63 | Serial.println(time, DEC); 64 | delay(500); 65 | 66 | lcdTestPattern(); 67 | delay(1000); 68 | 69 | display.fillScreen(BLACK); 70 | display.setCursor(0,0); 71 | display.print("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa"); 72 | delay(1000); 73 | 74 | // tft print function! 75 | tftPrintTest(); 76 | delay(2000); 77 | 78 | //a single pixel 79 | display.drawPixel(display.width()/2, display.height()/2, GREEN); 80 | delay(500); 81 | 82 | // line draw test 83 | testlines(YELLOW); 84 | delay(500); 85 | 86 | // optimized lines 87 | testfastlines(RED, BLUE); 88 | delay(500); 89 | 90 | testdrawrects(GREEN); 91 | delay(1000); 92 | 93 | testfillrects(YELLOW, MAGENTA); 94 | delay(1000); 95 | 96 | display.fillScreen(BLACK); 97 | testfillcircles(10, BLUE); 98 | testdrawcircles(10, WHITE); 99 | delay(1000); 100 | 101 | testroundrects(); 102 | delay(500); 103 | 104 | testtriangles(); 105 | delay(500); 106 | 107 | Serial.println("done"); 108 | delay(1000); 109 | } 110 | 111 | void loop() { 112 | } 113 | 114 | void testlines(uint16_t color) { 115 | display.fillScreen(BLACK); 116 | for (int16_t x=0; x < display.width()-1; x+=6) { 117 | display.drawLine(0, 0, x, display.height()-1, color); 118 | } 119 | for (int16_t y=0; y < display.height()-1; y+=6) { 120 | display.drawLine(0, 0, display.width()-1, y, color); 121 | } 122 | 123 | display.fillScreen(BLACK); 124 | for (int16_t x=0; x < display.width()-1; x+=6) { 125 | display.drawLine(display.width()-1, 0, x, display.height()-1, color); 126 | } 127 | for (int16_t y=0; y < display.height()-1; y+=6) { 128 | display.drawLine(display.width()-1, 0, 0, y, color); 129 | } 130 | 131 | // To avoid ESP8266 watchdog timer resets when not using the hardware SPI pins 132 | delay(0); 133 | 134 | display.fillScreen(BLACK); 135 | for (int16_t x=0; x < display.width()-1; x+=6) { 136 | display.drawLine(0, display.height()-1, x, 0, color); 137 | } 138 | for (int16_t y=0; y < display.height()-1; y+=6) { 139 | display.drawLine(0, display.height()-1, display.width()-1, y, color); 140 | } 141 | 142 | display.fillScreen(BLACK); 143 | for (int16_t x=0; x < display.width()-1; x+=6) { 144 | display.drawLine(display.width()-1, display.height()-1, x, 0, color); 145 | } 146 | for (int16_t y=0; y < display.height()-1; y+=6) { 147 | display.drawLine(display.width()-1, display.height()-1, 0, y, color); 148 | } 149 | 150 | } 151 | 152 | void testdrawtext(char *text, uint16_t color) { 153 | display.setTextSize(1); 154 | display.setTextColor(WHITE); 155 | display.setCursor(0,0); 156 | 157 | for (uint8_t i=0; i < 168; i++) { 158 | if (i == '\n') continue; 159 | display.write(i); 160 | if ((i > 0) && (i % 21 == 0)) 161 | display.println(); 162 | } 163 | } 164 | 165 | void testfastlines(uint16_t color1, uint16_t color2) { 166 | display.fillScreen(BLACK); 167 | for (int16_t y=0; y < display.height()-1; y+=5) { 168 | display.drawFastHLine(0, y, display.width()-1, color1); 169 | } 170 | for (int16_t x=0; x < display.width()-1; x+=5) { 171 | display.drawFastVLine(x, 0, display.height()-1, color2); 172 | } 173 | } 174 | 175 | void testdrawrects(uint16_t color) { 176 | display.fillScreen(BLACK); 177 | for (int16_t x=0; x < display.height()-1; x+=6) { 178 | display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color); 179 | } 180 | } 181 | 182 | void testfillrects(uint16_t color1, uint16_t color2) { 183 | display.fillScreen(BLACK); 184 | for (int16_t x=display.height()-1; x > 6; x-=6) { 185 | display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1); 186 | display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2); 187 | } 188 | } 189 | 190 | void testfillcircles(uint8_t radius, uint16_t color) { 191 | for (uint8_t x=radius; x < display.width()-1; x+=radius*2) { 192 | for (uint8_t y=radius; y < display.height()-1; y+=radius*2) { 193 | display.fillCircle(x, y, radius, color); 194 | } 195 | } 196 | } 197 | 198 | void testdrawcircles(uint8_t radius, uint16_t color) { 199 | for (int16_t x=0; x < display.width()-1+radius; x+=radius*2) { 200 | for (int16_t y=0; y < display.height()-1+radius; y+=radius*2) { 201 | display.drawCircle(x, y, radius, color); 202 | } 203 | } 204 | } 205 | 206 | void testtriangles() { 207 | display.fillScreen(BLACK); 208 | int color = 0xF800; 209 | int t; 210 | int w = display.width()/2; 211 | int x = display.height(); 212 | int y = 0; 213 | int z = display.width(); 214 | for (t = 0 ; t <= 15; t+=1) { 215 | display.drawTriangle(w, y, y, x, z, x, color); 216 | x-=4; 217 | y+=4; 218 | z-=4; 219 | color+=100; 220 | } 221 | } 222 | 223 | void testroundrects() { 224 | display.fillScreen(BLACK); 225 | int color = 100; 226 | int i; 227 | int t; 228 | for(t = 0 ; t <= 4; t+=1) { 229 | int x = 0; 230 | int y = 0; 231 | int w = display.width(); 232 | int h = display.height(); 233 | for(i = 0 ; i <= 8; i+=1) { 234 | display.drawRoundRect(x, y, w, h, 5, color); 235 | x+=2; 236 | y+=3; 237 | w-=4; 238 | h-=6; 239 | color+=1100; 240 | } 241 | color+=100; 242 | } 243 | } 244 | 245 | void tftPrintTest() { 246 | display.fillScreen(BLACK); 247 | display.setCursor(0, 5); 248 | display.setTextColor(RED); 249 | display.setTextSize(1); 250 | display.println("Hello World!"); 251 | display.setTextColor(YELLOW, GREEN); 252 | display.setTextSize(2); 253 | display.print("Hello Wo"); 254 | display.setTextColor(BLUE); 255 | display.setTextSize(3); 256 | display.print(1234.567); 257 | delay(1500); 258 | display.setCursor(0, 5); 259 | display.fillScreen(BLACK); 260 | display.setTextColor(WHITE); 261 | display.setTextSize(0); 262 | display.println("Hello World!"); 263 | display.setTextSize(1); 264 | display.setTextColor(GREEN); 265 | display.print(p, 5); 266 | display.println(" Want pi?"); 267 | display.print(8675309, HEX); // print 8,675,309 out in HEX! 268 | display.print(" Print HEX"); 269 | display.setTextColor(WHITE); 270 | display.println("Sketch has been"); 271 | display.println("running for: "); 272 | display.setTextColor(MAGENTA); 273 | display.print(millis() / 1000); 274 | display.setTextColor(WHITE); 275 | display.print(" seconds."); 276 | } 277 | 278 | void mediabuttons() { 279 | // play 280 | display.fillScreen(BLACK); 281 | display.fillRoundRect(25, 10, 78, 60, 8, WHITE); 282 | display.fillTriangle(42, 20, 42, 60, 90, 40, RED); 283 | delay(500); 284 | // pause 285 | display.fillRoundRect(25, 90, 78, 60, 8, WHITE); 286 | display.fillRoundRect(39, 98, 20, 45, 5, GREEN); 287 | display.fillRoundRect(69, 98, 20, 45, 5, GREEN); 288 | delay(500); 289 | // play color 290 | display.fillTriangle(42, 20, 42, 60, 90, 40, BLUE); 291 | delay(50); 292 | // pause color 293 | display.fillRoundRect(39, 98, 20, 45, 5, RED); 294 | display.fillRoundRect(69, 98, 20, 45, 5, RED); 295 | // play color 296 | display.fillTriangle(42, 20, 42, 60, 90, 40, GREEN); 297 | } 298 | 299 | /**************************************************************************/ 300 | /*! 301 | @brief Renders a simple test pattern on the LCD 302 | */ 303 | /**************************************************************************/ 304 | void lcdTestPattern(void) 305 | { 306 | uint8_t w,h; 307 | display.setAddrWindow(0, 0, 96, 64); 308 | 309 | for (h = 0; h < 64; h++) { 310 | for (w = 0; w < 96; w++) { 311 | if (w > 83) { 312 | display.writePixel(w, h, WHITE); 313 | } else if (w > 71) { 314 | display.writePixel(w, h, BLUE); 315 | } else if (w > 59) { 316 | display.writePixel(w, h, GREEN); 317 | } else if (w > 47) { 318 | display.writePixel(w, h, CYAN); 319 | } else if (w > 35) { 320 | display.writePixel(w, h, RED); 321 | } else if (w > 23) { 322 | display.writePixel(w, h, MAGENTA); 323 | } else if (w > 11) { 324 | display.writePixel(w, h, YELLOW); 325 | } else { 326 | display.writePixel(w, h, BLACK); 327 | } 328 | } 329 | } 330 | display.endWrite(); 331 | } 332 | -------------------------------------------------------------------------------- /examples/LCDGFXDemo/google32.h: -------------------------------------------------------------------------------- 1 | // Generated by : UTFTConverter v0.1 2 | // Generated from : google.jpg 3 | // Time generated : 2018-02-08 06:09:41.424425 UTC 4 | // Image Size : 32x32 pixels 5 | // Memory usage : 2048 bytes 6 | 7 | #if defined(__AVR__) 8 | #include 9 | #elif defined(__PIC32MX__) 10 | #define PROGMEM 11 | #elif defined(__arm__) 12 | #define PROGMEM 13 | #endif 14 | 15 | const unsigned short 16 | bitmap32[1024] PROGMEM = 17 | { 18 | 0xFFFE, 0xFFFE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 19 | 0xFFDF, 0xFFDF, 0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE, 20 | 0xFFFF, 0xFFFF, 0xFFDF, 0xFFDF, // 0x0010 (16) pixels 21 | 0xFFFF, 0xFFFF, 0xFFDE, 0xFFDE, 0xFFFF, 0xFFFF, 22 | 0xFFDF, 0xFFFF, 0xFFFE, 0xFFDE, 0xFFFE, 0xFFFE, 23 | 0xFFFF, 0xFFFF, 0xFFBF, 0xFFDF, // 0x0020 (32) pixels 24 | 0xFFFE, 0x0840, 0x0820, 0x0841, 0x0040, 0x0020, 25 | 0x1020, 0x0800, 0x0040, 0x0060, 0x0020, 0x0840, 26 | 0x0000, 0x0040, 0x1022, 0x0821, // 0x0030 (48) pixels 27 | 0x0861, 0x0020, 0x1020, 0x0800, 0x0820, 0x0820, 28 | 0x0001, 0x0821, 0x0800, 0x1020, 0x0820, 0x1040, 29 | 0x0041, 0x0021, 0x0821, 0xFFDF, // 0x0040 (64) pixels 30 | 0xFFFF, 0x0021, 0x0042, 0x1926, 0x343A, 0x1B98, 31 | 0x02F7, 0x0318, 0x031A, 0x033A, 0x43F8, 0x8E7F, 32 | 0xF7DF, 0xEF9F, 0xEF9D, 0xEFBD, // 0x0050 (80) pixels 33 | 0xEBF0, 0x9966, 0xE801, 0xE001, 0xD821, 0xD800, 34 | 0xE001, 0xE000, 0xD820, 0xD000, 0xD001, 0xC000, 35 | 0x3020, 0x2800, 0x0861, 0xF7FF, // 0x0060 (96) pixels 36 | 0xFFFF, 0x0021, 0x10E5, 0xB5D8, 0x2BF9, 0x0B36, 37 | 0x02F7, 0x0338, 0x031A, 0x031A, 0x2315, 0x54BB, 38 | 0xE75E, 0xF7FF, 0xF7FE, 0xFFFF, // 0x0070 (112) pixels 39 | 0xFE9B, 0xCAEC, 0xE801, 0xE801, 0xD821, 0xD800, 40 | 0xE801, 0xE001, 0xD800, 0xE040, 0xD042, 0xD022, 41 | 0x5964, 0x2800, 0x0020, 0xFFFF, // 0x0080 (128) pixels 42 | 0xFFFD, 0x0880, 0xB63C, 0x9D58, 0x0BBB, 0x0339, 43 | 0x0B1B, 0x02DB, 0x02F8, 0x0B39, 0x031B, 0x139C, 44 | 0x9E1B, 0xE7FF, 0xFFFF, 0xFFDE, // 0x0090 (144) pixels 45 | 0xFFDE, 0xC5B5, 0xF863, 0xE000, 0xE001, 0xE001, 46 | 0xD821, 0xD821, 0xE020, 0xD800, 0xF000, 0xF000, 47 | 0xC801, 0xC800, 0x0040, 0xFFFE, // 0x00A0 (160) pixels 48 | 0xFFFD, 0x10C0, 0xD71F, 0xA59A, 0x0B9A, 0x0339, 49 | 0x0B3C, 0x02FB, 0x0B39, 0x0B19, 0x02FA, 0x0B7C, 50 | 0x6C95, 0xD7DF, 0xFFFF, 0xFFDE, // 0x00B0 (176) pixels 51 | 0xFFDE, 0xEEDA, 0xF8C4, 0xE801, 0xE001, 0xE001, 52 | 0xE041, 0xD821, 0xE020, 0xE000, 0xF801, 0xF801, 53 | 0xD022, 0xC801, 0x0860, 0xFFFD, // 0x00C0 (192) pixels 54 | 0xFFFF, 0x62EB, 0xCF5E, 0x9597, 0x1BB9, 0x1337, 55 | 0x02D9, 0x031A, 0x0319, 0x0319, 0x031B, 0x033B, 56 | 0x4396, 0xB71F, 0xFFFE, 0xFFFE, // 0x00D0 (208) pixels 57 | 0xFFBF, 0xFF1C, 0xF924, 0xE041, 0xF000, 0xF000, 58 | 0xE820, 0xE000, 0xF000, 0xF800, 0xE000, 0xD800, 59 | 0xD801, 0xD801, 0x4947, 0xFF9F, // 0x00E0 (224) pixels 60 | 0xFFFF, 0x738D, 0xCF7F, 0xAE7B, 0x23B9, 0x0B37, 61 | 0x02FA, 0x0B1A, 0x0339, 0x0339, 0x033C, 0x031B, 62 | 0x3B76, 0x963F, 0xFFFE, 0xFFFE, // 0x00F0 (240) pixels 63 | 0xFF9E, 0xFF3D, 0xF945, 0xD820, 0xF801, 0xF800, 64 | 0xE800, 0xE820, 0xF800, 0xF800, 0xE821, 0xE020, 65 | 0xE001, 0xD800, 0x5167, 0xFF7F, // 0x0100 (256) pixels 66 | 0xFFFF, 0x6B8F, 0xE71D, 0xE6FD, 0x4439, 0x2335, 67 | 0x033A, 0x035A, 0x0317, 0x0B58, 0x0319, 0x0319, 68 | 0x2B76, 0x7E1F, 0xF7FF, 0xFFFF, // 0x0110 (272) pixels 69 | 0xFF7E, 0xFE7A, 0xE904, 0xD021, 0xB8C2, 0xB8C2, 70 | 0xA8C0, 0xB101, 0xC881, 0xC880, 0xF001, 0xF001, 71 | 0xE000, 0xD800, 0x5166, 0xFF9E, // 0x0120 (288) pixels 72 | 0xF7BF, 0x73B0, 0xEF3E, 0xF79F, 0x655E, 0x2356, 73 | 0x037B, 0x033A, 0x0B58, 0x0316, 0x0319, 0x033A, 74 | 0x2356, 0x7E1F, 0xFFFF, 0xF7FF, // 0x0130 (304) pixels 75 | 0xFF9E, 0xCCF4, 0xE0A3, 0xD862, 0xB8C2, 0xC0E2, 76 | 0xB942, 0xB101, 0xC8A1, 0xC8A1, 0xF001, 0xF001, 77 | 0xD800, 0xD800, 0x5166, 0xFFBF, // 0x0140 (320) pixels 78 | 0xFFFE, 0x6B6C, 0xFEFC, 0xFF7E, 0xAEFF, 0x3B94, 79 | 0x039D, 0x033B, 0x0358, 0x0379, 0x033C, 0x035C, 80 | 0x3B74, 0x963E, 0xFFFF, 0xFFFF, // 0x0150 (336) pixels 81 | 0xD7FC, 0x5C6D, 0x13C6, 0x1C07, 0x1407, 0x1407, 82 | 0x04C8, 0x0487, 0x1BE7, 0x1BE7, 0x3B45, 0x3324, 83 | 0xA101, 0xA0C0, 0x4984, 0xFFDD, // 0x0160 (352) pixels 84 | 0xFFFE, 0x73AD, 0xFF1C, 0xFF9E, 0xD7FF, 0x85DD, 85 | 0x03BE, 0x039D, 0x0358, 0x0358, 0x035C, 0x035C, 86 | 0x5437, 0xBF9F, 0xFFFF, 0xFFBE, // 0x0170 (368) pixels 87 | 0x7D72, 0x3B49, 0x1C07, 0x1C07, 0x1448, 0x1448, 88 | 0x04A8, 0x04A8, 0x1C28, 0x1C28, 0x4386, 0x3B86, 89 | 0xB142, 0xA101, 0x4984, 0xFFDD, // 0x0180 (384) pixels 90 | 0xFFFF, 0x6350, 0xDFBC, 0xEFFD, 0xFFDE, 0xF77D, 91 | 0x853A, 0x4B53, 0x2375, 0x2355, 0x3B34, 0x5C18, 92 | 0xC63A, 0xFFFF, 0xCFFC, 0x6E11, // 0x0190 (400) pixels 93 | 0x04A8, 0x0467, 0x04A7, 0x0487, 0x0466, 0x0C86, 94 | 0x0486, 0x04A6, 0x0467, 0x0488, 0x04A7, 0x04C7, 95 | 0x0447, 0x03E6, 0x41A8, 0xFFDF, // 0x01A0 (416) pixels 96 | 0xFFFF, 0x422B, 0xCF19, 0xEFFD, 0xFFFF, 0xFFFF, 97 | 0xE7FF, 0xB69F, 0x6D9E, 0x655D, 0x95DF, 0xC75F, 98 | 0xFFDF, 0xFFBF, 0x5D8F, 0x23A8, // 0x01B0 (432) pixels 99 | 0x0487, 0x04A8, 0x04A7, 0x04A7, 0x0466, 0x0C86, 100 | 0x04C7, 0x04A6, 0x0488, 0x0488, 0x04A7, 0x04A7, 101 | 0x0467, 0x0406, 0x49C8, 0xFFDF, // 0x01C0 (448) pixels 102 | 0xF7FF, 0x2968, 0x3C5B, 0x7E7F, 0xD7DF, 0xE7FF, 103 | 0xEFFF, 0xEFFF, 0xFFFF, 0xF7DF, 0xFFFF, 0xFFBF, 104 | 0xD7FC, 0x652F, 0x0487, 0x04A7, // 0x01D0 (464) pixels 105 | 0x1447, 0x1447, 0x04A8, 0x0488, 0x0467, 0x0467, 106 | 0x0C68, 0x0447, 0x0489, 0x0489, 0x0468, 0x0488, 107 | 0x0448, 0x0407, 0x3227, 0xF7FF, // 0x01E0 (480) pixels 108 | 0xFFFF, 0x2127, 0x1336, 0x1B97, 0x6433, 0x74D6, 109 | 0x9539, 0x9D9A, 0xE75E, 0xFFFF, 0xFFBF, 0xFFFF, 110 | 0xAF57, 0x3388, 0x0487, 0x04A8, // 0x01F0 (496) pixels 111 | 0x1427, 0x1427, 0x04A8, 0x0488, 0x04A8, 0x0467, 112 | 0x0C68, 0x0C68, 0x0469, 0x0469, 0x0468, 0x0488, 113 | 0x0448, 0x0407, 0x3227, 0xF7FF, // 0x0200 (512) pixels 114 | 0xEFFF, 0x1147, 0x02D9, 0x033A, 0x0B1A, 0x0B1A, 115 | 0x137A, 0x349E, 0xF79D, 0xFFFE, 0xFFDF, 0xFFDF, 116 | 0x9F9A, 0x23CB, 0x0467, 0x0488, // 0x0210 (528) pixels 117 | 0x0C48, 0x0C47, 0x0487, 0x04A7, 0x04A7, 0x04A7, 118 | 0x0488, 0x0488, 0x0488, 0x0488, 0x0488, 0x04A8, 119 | 0x0428, 0x03E7, 0x3227, 0xF7FF, // 0x0220 (544) pixels 120 | 0xEFFF, 0x1167, 0x02D9, 0x02F9, 0x0B1A, 0x02FA, 121 | 0x0B39, 0x2C3D, 0xF7DD, 0xFFFE, 0xFFBE, 0xFFDF, 122 | 0xC7FF, 0x7E55, 0x0467, 0x0467, // 0x0230 (560) pixels 123 | 0x0C68, 0x0C68, 0x04A7, 0x0466, 0x04C7, 0x0486, 124 | 0x0467, 0x04A8, 0x0488, 0x0488, 0x0488, 0x04A8, 125 | 0x0428, 0x03E7, 0x3227, 0xF7FF, // 0x0240 (576) pixels 126 | 0xEFFF, 0x1948, 0x02F7, 0x02F7, 0x0338, 0x0338, 127 | 0x0337, 0x243A, 0xCE9D, 0xF7FF, 0xFFFF, 0xFFFF, 128 | 0xFFFD, 0xFFFD, 0x9674, 0x43EA, // 0x0250 (592) pixels 129 | 0x0447, 0x0488, 0x04A7, 0x04E8, 0x0446, 0x0487, 130 | 0x0CA8, 0x0467, 0x0C67, 0x0C67, 0x0487, 0x0487, 131 | 0x0468, 0x0427, 0x3A26, 0xFFFE, // 0x0260 (608) pixels 132 | 0xF7FF, 0x1948, 0x02F7, 0x0338, 0x0B99, 0x13BA, 133 | 0x1BD9, 0x2C7C, 0xA558, 0xF7DF, 0xFFFF, 0xFFFF, 134 | 0xFFFD, 0xFFFD, 0xDFFD, 0xB758, // 0x0270 (624) pixels 135 | 0x1D8C, 0x0488, 0x0487, 0x0487, 0x0CA8, 0x0467, 136 | 0x0C88, 0x0467, 0x0C67, 0x0C67, 0x0487, 0x0487, 137 | 0x0468, 0x0427, 0x3A26, 0xFFFE, // 0x0280 (640) pixels 138 | 0xEFFF, 0x1186, 0x5336, 0x743A, 0x9558, 0xB63B, 139 | 0xCF1A, 0xD75B, 0xFF9A, 0xFFDB, 0xFFFD, 0xFFFD, 140 | 0xFFFF, 0xFFDF, 0xFFFF, 0xFFFF, // 0x0290 (656) pixels 141 | 0xD79B, 0x640D, 0x0C48, 0x0C69, 0x0447, 0x0447, 142 | 0x0C68, 0x0447, 0x0467, 0x0467, 0x0487, 0x0487, 143 | 0x0448, 0x0407, 0x3227, 0xF7FF, // 0x02A0 (672) pixels 144 | 0xE7FF, 0x3ACB, 0xAE1F, 0xDF7F, 0xEFFF, 0xEFFF, 145 | 0xEFFE, 0xE7BD, 0xFF58, 0xF738, 0xF73A, 0xFF9C, 146 | 0xF7DF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x02B0 (688) pixels 147 | 0xEFFE, 0xDFBC, 0x1CEB, 0x0428, 0x0C68, 0x0447, 148 | 0x0447, 0x0C68, 0x0467, 0x0467, 0x0487, 0x0487, 149 | 0x0448, 0x0407, 0x3227, 0xF7FF, // 0x02C0 (704) pixels 150 | 0xFFFF, 0x738F, 0xF736, 0xFF98, 0xFF0D, 0xFE6B, 151 | 0xF646, 0xF625, 0xFDA3, 0xFE04, 0xEDC4, 0xFE66, 152 | 0xFF34, 0xFFB6, 0xFFDE, 0xFFFF, // 0x02D0 (720) pixels 153 | 0xFFBF, 0xFFDF, 0x9F78, 0x23A9, 0x0468, 0x04CA, 154 | 0x0448, 0x0489, 0x04A8, 0x04A8, 0x0487, 0x0487, 155 | 0x0448, 0x0407, 0x3227, 0xF7FF, // 0x02E0 (736) pixels 156 | 0xFFDF, 0x736F, 0xE6B4, 0xD653, 0xEDE8, 0xE5A7, 157 | 0xE5C4, 0xEDE4, 0xFD82, 0xF582, 0xEDC4, 0xEDE4, 158 | 0xE5AE, 0xFEB2, 0xFFFF, 0xFFFF, // 0x02F0 (752) pixels 159 | 0xFFDF, 0xFFBF, 0xC7FD, 0x552F, 0x0488, 0x0468, 160 | 0x0488, 0x0468, 0x04A8, 0x04A8, 0x0487, 0x0487, 161 | 0x0448, 0x0407, 0x3227, 0xF7FF, // 0x0300 (768) pixels 162 | 0xFFFD, 0x734A, 0xE584, 0xEDC5, 0xF5C1, 0xF5C1, 163 | 0xEDC0, 0xEDC0, 0xED82, 0xF5A2, 0xE5E1, 0xE5E1, 164 | 0xFDC1, 0xFDE2, 0xE6B2, 0xFFF7, // 0x0310 (784) pixels 165 | 0xFFFF, 0xF7FF, 0xEFFE, 0xA5D4, 0x0448, 0x0C89, 166 | 0x0468, 0x0468, 0x0487, 0x04A7, 0x0447, 0x0447, 167 | 0x0469, 0x03E7, 0x2A27, 0xEFFF, // 0x0320 (800) pixels 168 | 0xFFDD, 0x5AA8, 0xDD43, 0xDD64, 0xED80, 0xF5C1, 169 | 0xF5E0, 0xEDC0, 0xF5A2, 0xF5A3, 0xE5E1, 0xE5C1, 170 | 0xF5A1, 0xF5A1, 0xD60F, 0xF713, // 0x0330 (816) pixels 171 | 0xF7FF, 0xFFFF, 0xF7FE, 0xB656, 0x0427, 0x0448, 172 | 0x0488, 0x0468, 0x0487, 0x04C8, 0x0C88, 0x0426, 173 | 0x0468, 0x03E6, 0x21E6, 0xF7FF, // 0x0340 (832) pixels 174 | 0xF7FF, 0x00A2, 0xE501, 0xED62, 0xFD81, 0xFD81, 175 | 0xF562, 0xFDA3, 0xE5C0, 0xEDE0, 0xEDC1, 0xEDA0, 176 | 0xF5C0, 0xF5C0, 0xEDE3, 0xFE65, // 0x0350 (848) pixels 177 | 0xFFDE, 0xFFDE, 0xE7FC, 0xA634, 0x0487, 0x04A8, 178 | 0x0488, 0x0467, 0x04C7, 0x0487, 0x0466, 0x0487, 179 | 0x1408, 0x0BC7, 0x08A1, 0xFFFE, // 0x0360 (864) pixels 180 | 0xF7FF, 0x0060, 0xC420, 0xE542, 0xFD81, 0xFDA2, 181 | 0xFDA3, 0xF562, 0xEDE1, 0xEDE1, 0xF5E1, 0xEDC1, 182 | 0xF5C0, 0xF5C0, 0xEDC3, 0xFE24, // 0x0370 (880) pixels 183 | 0xFFBD, 0xFFDE, 0xEFFD, 0x8551, 0x0487, 0x04A7, 184 | 0x0488, 0x0488, 0x04A7, 0x04A7, 0x0487, 0x0487, 185 | 0x0BE7, 0x0345, 0x0040, 0xFFFE, // 0x0380 (896) pixels 186 | 0xFFDF, 0x0823, 0x3120, 0xACEC, 0xED83, 0xE542, 187 | 0xE582, 0xEDA3, 0xF564, 0xED64, 0xF561, 0xF561, 188 | 0xF561, 0xF561, 0xDDA7, 0xEE29, // 0x0390 (912) pixels 189 | 0xFF5C, 0xFFDF, 0xB7FB, 0x3C4B, 0x0448, 0x0489, 190 | 0x1429, 0x1429, 0x0C28, 0x0C69, 0x1408, 0x13E7, 191 | 0x3308, 0x0161, 0x0800, 0xFFFF, // 0x03A0 (928) pixels 192 | 0xFFDF, 0x0002, 0x1880, 0x3120, 0xC460, 0xDD22, 193 | 0xEDA3, 0xDD41, 0xED43, 0xE523, 0xED41, 0xED41, 194 | 0xED41, 0xED41, 0xDDA7, 0xEE29, // 0x03B0 (944) pixels 195 | 0xFF7D, 0xFF7D, 0x7E73, 0x23A9, 0x0428, 0x0448, 196 | 0x0BE8, 0x0BE8, 0x0428, 0x0408, 0x1407, 0x0345, 197 | 0x0100, 0x0080, 0x1020, 0xFFFF, // 0x03C0 (960) pixels 198 | 0xFFFE, 0x0020, 0x0802, 0x0802, 0x0040, 0x0080, 199 | 0x0020, 0x0840, 0x0840, 0x0820, 0x0801, 0x0801, 200 | 0x0020, 0x0020, 0x0040, 0x0060, // 0x03D0 (976) pixels 201 | 0x0000, 0x1062, 0x0040, 0x0060, 0x1820, 0x1000, 202 | 0x0020, 0x0040, 0x0040, 0x0060, 0x0060, 0x00A0, 203 | 0x0841, 0x0800, 0x0042, 0xF7FF, // 0x03E0 (992) pixels 204 | 0xFFFE, 0xFFFE, 0xFFDF, 0xFFBF, 0xF7FF, 0xF7FF, 205 | 0xFFFE, 0xFFFF, 0xFFFE, 0xFFFD, 0xFFFF, 0xFFFF, 206 | 0xFFFF, 0xFFFF, 0xFFFF, 0xF7FF, // 0x03F0 (1008) pixels 207 | 0xFFFF, 0xFFDF, 0xEFFF, 0xF7FF, 0xFFBE, 0xFFDF, 208 | 0xFFFF, 0xFFFF, 0xF7FF, 0xF7FE, 0xF7FF, 0xF7FE, 209 | 0xFFFF, 0xFFFF, 0xF7FF, 0xFFFF, // 0x0400 (1024) pixels 210 | }; 211 | -------------------------------------------------------------------------------- /examples/LCDGFXDemo/LCDGFXDemo.ino: -------------------------------------------------------------------------------- 1 | // GFX Demo for multiple backends 2 | // By Marc MERLIN 3 | // Contains code (c) Adafruit, license BSD 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define show endWrite 10 | #define clear() fillScreen(0) 11 | #define mw 96 12 | #define mh 64 13 | 14 | #include "smileytongue24.h" 15 | #define BM32 16 | #include "google32.h" 17 | 18 | /* 19 | SD1331 Pin Arduino ESP8266 rPi 20 | 1 GND 21 | 2 VCC 22 | 3 SCL/SCK/CLK/D0 13 GPIO14/D5 GPIO11/SPI0-SCLK 23 | 4 SDA/MOSI/D1 11 GPIO13/D7 GPIO10/SPI0-MOSI 24 | 5 RES/RST 9 GPIO15/D8 GPIO24 25 | 6 DC/A0 (data) 8 GPIO05/D1 GPIO23 26 | 7 CS 10 GPIO04/D2 GPIO08 27 | */ 28 | // You can use any (4 or) 5 pins 29 | // hwspi hardcodes those pins, no need to redefine them 30 | #define sclk 14 31 | #define mosi 13 32 | #define cs 5 33 | #define rst 9 34 | #define dc 6 35 | 36 | // Option 1: use any pins but a little slower 37 | //#pragma message "Using SWSPI" 38 | //Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst); 39 | 40 | // Option 2: must use the hardware SPI pins 41 | // (for UNO thats sclk = 13 and sid = 11) and pin 10 must be 42 | // an output. This is much faster - also required if you want 43 | // to use the microSD card (see the image drawing example) 44 | #pragma message "Using HWSPI" 45 | Adafruit_SSD1331 display = Adafruit_SSD1331(&SPI, cs, dc, rst); 46 | 47 | // This could also be defined as display.color(255,0,0) but those defines 48 | // are meant to work for adafruit_gfx backends that are lacking color() 49 | #define LED_BLACK 0 50 | 51 | #define LED_RED_VERYLOW (3 << 11) 52 | #define LED_RED_LOW (7 << 11) 53 | #define LED_RED_MEDIUM (15 << 11) 54 | #define LED_RED_HIGH (31 << 11) 55 | 56 | #define LED_GREEN_VERYLOW (1 << 5) 57 | #define LED_GREEN_LOW (15 << 5) 58 | #define LED_GREEN_MEDIUM (31 << 5) 59 | #define LED_GREEN_HIGH (63 << 5) 60 | 61 | #define LED_BLUE_VERYLOW 3 62 | #define LED_BLUE_LOW 7 63 | #define LED_BLUE_MEDIUM 15 64 | #define LED_BLUE_HIGH 31 65 | 66 | #define LED_ORANGE_VERYLOW (LED_RED_VERYLOW + LED_GREEN_VERYLOW) 67 | #define LED_ORANGE_LOW (LED_RED_LOW + LED_GREEN_LOW) 68 | #define LED_ORANGE_MEDIUM (LED_RED_MEDIUM + LED_GREEN_MEDIUM) 69 | #define LED_ORANGE_HIGH (LED_RED_HIGH + LED_GREEN_HIGH) 70 | 71 | #define LED_PURPLE_VERYLOW (LED_RED_VERYLOW + LED_BLUE_VERYLOW) 72 | #define LED_PURPLE_LOW (LED_RED_LOW + LED_BLUE_LOW) 73 | #define LED_PURPLE_MEDIUM (LED_RED_MEDIUM + LED_BLUE_MEDIUM) 74 | #define LED_PURPLE_HIGH (LED_RED_HIGH + LED_BLUE_HIGH) 75 | 76 | #define LED_CYAN_VERYLOW (LED_GREEN_VERYLOW + LED_BLUE_VERYLOW) 77 | #define LED_CYAN_LOW (LED_GREEN_LOW + LED_BLUE_LOW) 78 | #define LED_CYAN_MEDIUM (LED_GREEN_MEDIUM + LED_BLUE_MEDIUM) 79 | #define LED_CYAN_HIGH (LED_GREEN_HIGH + LED_BLUE_HIGH) 80 | 81 | #define LED_WHITE_VERYLOW (LED_RED_VERYLOW + LED_GREEN_VERYLOW + LED_BLUE_VERYLOW) 82 | #define LED_WHITE_LOW (LED_RED_LOW + LED_GREEN_LOW + LED_BLUE_LOW) 83 | #define LED_WHITE_MEDIUM (LED_RED_MEDIUM + LED_GREEN_MEDIUM + LED_BLUE_MEDIUM) 84 | #define LED_WHITE_HIGH (LED_RED_HIGH + LED_GREEN_HIGH + LED_BLUE_HIGH) 85 | 86 | static const uint8_t PROGMEM 87 | mono_bmp[][8] = 88 | { 89 | { // 0: checkered 1 90 | B10101010, 91 | B01010101, 92 | B10101010, 93 | B01010101, 94 | B10101010, 95 | B01010101, 96 | B10101010, 97 | B01010101, 98 | }, 99 | 100 | { // 1: checkered 2 101 | B01010101, 102 | B10101010, 103 | B01010101, 104 | B10101010, 105 | B01010101, 106 | B10101010, 107 | B01010101, 108 | B10101010, 109 | }, 110 | 111 | { // 2: smiley 112 | B00111100, 113 | B01000010, 114 | B10100101, 115 | B10000001, 116 | B10100101, 117 | B10011001, 118 | B01000010, 119 | B00111100 }, 120 | 121 | { // 3: neutral 122 | B00111100, 123 | B01000010, 124 | B10100101, 125 | B10000001, 126 | B10111101, 127 | B10000001, 128 | B01000010, 129 | B00111100 }, 130 | 131 | { // 4; frowny 132 | B00111100, 133 | B01000010, 134 | B10100101, 135 | B10000001, 136 | B10011001, 137 | B10100101, 138 | B01000010, 139 | B00111100 }, 140 | }; 141 | 142 | static const uint16_t PROGMEM 143 | // These bitmaps were written for a backend that only supported 144 | // 4 bits per color with Blue/Green/Red ordering while neomatrix 145 | // uses native 565 color mapping as RGB. 146 | // I'm leaving the arrays as is because it's easier to read 147 | // which color is what when separated on a 4bit boundary 148 | // The demo code will modify the arrays at runtime to be compatible 149 | // with the neomatrix color ordering and bit depth. 150 | RGB_bmp[][64] = { 151 | // 00: blue, blue/red, red, red/green, green, green/blue, blue, white 152 | { 0x100, 0x200, 0x300, 0x400, 0x600, 0x800, 0xA00, 0xF00, 153 | 0x101, 0x202, 0x303, 0x404, 0x606, 0x808, 0xA0A, 0xF0F, 154 | 0x001, 0x002, 0x003, 0x004, 0x006, 0x008, 0x00A, 0x00F, 155 | 0x011, 0x022, 0x033, 0x044, 0x066, 0x088, 0x0AA, 0x0FF, 156 | 0x010, 0x020, 0x030, 0x040, 0x060, 0x080, 0x0A0, 0x0F0, 157 | 0x110, 0x220, 0x330, 0x440, 0x660, 0x880, 0xAA0, 0xFF0, 158 | 0x100, 0x200, 0x300, 0x400, 0x600, 0x800, 0xA00, 0xF00, 159 | 0x111, 0x222, 0x333, 0x444, 0x666, 0x888, 0xAAA, 0xFFF, }, 160 | 161 | // 01: grey to white 162 | { 0x111, 0x222, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, 163 | 0x222, 0x222, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, 164 | 0x333, 0x333, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, 165 | 0x555, 0x555, 0x555, 0x555, 0x777, 0x999, 0xAAA, 0xFFF, 166 | 0x777, 0x777, 0x777, 0x777, 0x777, 0x999, 0xAAA, 0xFFF, 167 | 0x999, 0x999, 0x999, 0x999, 0x999, 0x999, 0xAAA, 0xFFF, 168 | 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xFFF, 169 | 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, }, 170 | 171 | // 02: low red to high red 172 | { 0x001, 0x002, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F, 173 | 0x002, 0x002, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F, 174 | 0x003, 0x003, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F, 175 | 0x005, 0x005, 0x005, 0x005, 0x007, 0x009, 0x00A, 0x00F, 176 | 0x007, 0x007, 0x007, 0x007, 0x007, 0x009, 0x00A, 0x00F, 177 | 0x009, 0x009, 0x009, 0x009, 0x009, 0x009, 0x00A, 0x00F, 178 | 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00F, 179 | 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, }, 180 | 181 | // 03: low green to high green 182 | { 0x010, 0x020, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, 183 | 0x020, 0x020, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, 184 | 0x030, 0x030, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, 185 | 0x050, 0x050, 0x050, 0x050, 0x070, 0x090, 0x0A0, 0x0F0, 186 | 0x070, 0x070, 0x070, 0x070, 0x070, 0x090, 0x0A0, 0x0F0, 187 | 0x090, 0x090, 0x090, 0x090, 0x090, 0x090, 0x0A0, 0x0F0, 188 | 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0F0, 189 | 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, }, 190 | 191 | // 04: low blue to high blue 192 | { 0x100, 0x200, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00, 193 | 0x200, 0x200, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00, 194 | 0x300, 0x300, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00, 195 | 0x500, 0x500, 0x500, 0x500, 0x700, 0x900, 0xA00, 0xF00, 196 | 0x700, 0x700, 0x700, 0x700, 0x700, 0x900, 0xA00, 0xF00, 197 | 0x900, 0x900, 0x900, 0x900, 0x900, 0x900, 0xA00, 0xF00, 198 | 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xF00, 199 | 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, }, 200 | 201 | // 05: 1 black, 2R, 2O, 2G, 1B with 4 blue lines rising right 202 | { 0x000, 0x200, 0x000, 0x400, 0x000, 0x800, 0x000, 0xF00, 203 | 0x000, 0x201, 0x002, 0x403, 0x004, 0x805, 0x006, 0xF07, 204 | 0x008, 0x209, 0x00A, 0x40B, 0x00C, 0x80D, 0x00E, 0xF0F, 205 | 0x000, 0x211, 0x022, 0x433, 0x044, 0x855, 0x066, 0xF77, 206 | 0x088, 0x299, 0x0AA, 0x4BB, 0x0CC, 0x8DD, 0x0EE, 0xFFF, 207 | 0x000, 0x210, 0x020, 0x430, 0x040, 0x850, 0x060, 0xF70, 208 | 0x080, 0x290, 0x0A0, 0x4B0, 0x0C0, 0x8D0, 0x0E0, 0xFF0, 209 | 0x000, 0x200, 0x000, 0x500, 0x000, 0x800, 0x000, 0xF00, }, 210 | 211 | // 06: 4 lines of increasing red and then green 212 | { 0x000, 0x000, 0x001, 0x001, 0x002, 0x002, 0x003, 0x003, 213 | 0x004, 0x004, 0x005, 0x005, 0x006, 0x006, 0x007, 0x007, 214 | 0x008, 0x008, 0x009, 0x009, 0x00A, 0x00A, 0x00B, 0x00B, 215 | 0x00C, 0x00C, 0x00D, 0x00D, 0x00E, 0x00E, 0x00F, 0x00F, 216 | 0x000, 0x000, 0x010, 0x010, 0x020, 0x020, 0x030, 0x030, 217 | 0x040, 0x040, 0x050, 0x050, 0x060, 0x060, 0x070, 0x070, 218 | 0x080, 0x080, 0x090, 0x090, 0x0A0, 0x0A0, 0x0B0, 0x0B0, 219 | 0x0C0, 0x0C0, 0x0D0, 0x0D0, 0x0E0, 0x0E0, 0x0F0, 0x0F0, }, 220 | 221 | // 07: 4 lines of increasing red and then blue 222 | { 0x000, 0x000, 0x001, 0x001, 0x002, 0x002, 0x003, 0x003, 223 | 0x004, 0x004, 0x005, 0x005, 0x006, 0x006, 0x007, 0x007, 224 | 0x008, 0x008, 0x009, 0x009, 0x00A, 0x00A, 0x00B, 0x00B, 225 | 0x00C, 0x00C, 0x00D, 0x00D, 0x00E, 0x00E, 0x00F, 0x00F, 226 | 0x000, 0x000, 0x100, 0x100, 0x200, 0x200, 0x300, 0x300, 227 | 0x400, 0x400, 0x500, 0x500, 0x600, 0x600, 0x700, 0x700, 228 | 0x800, 0x800, 0x900, 0x900, 0xA00, 0xA00, 0xB00, 0xB00, 229 | 0xC00, 0xC00, 0xD00, 0xD00, 0xE00, 0xE00, 0xF00, 0xF00, }, 230 | 231 | // 08: criss cross of green and red with diagonal blue. 232 | { 0xF00, 0x001, 0x003, 0x005, 0x007, 0x00A, 0x00F, 0x000, 233 | 0x020, 0xF21, 0x023, 0x025, 0x027, 0x02A, 0x02F, 0x020, 234 | 0x040, 0x041, 0xF43, 0x045, 0x047, 0x04A, 0x04F, 0x040, 235 | 0x060, 0x061, 0x063, 0xF65, 0x067, 0x06A, 0x06F, 0x060, 236 | 0x080, 0x081, 0x083, 0x085, 0xF87, 0x08A, 0x08F, 0x080, 237 | 0x0A0, 0x0A1, 0x0A3, 0x0A5, 0x0A7, 0xFAA, 0x0AF, 0x0A0, 238 | 0x0F0, 0x0F1, 0x0F3, 0x0F5, 0x0F7, 0x0FA, 0xFFF, 0x0F0, 239 | 0x000, 0x001, 0x003, 0x005, 0x007, 0x00A, 0x00F, 0xF00, }, 240 | 241 | // 09: 2 lines of green, 2 red, 2 orange, 2 green 242 | { 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, 243 | 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, 244 | 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, 245 | 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, 246 | 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, 247 | 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, 248 | 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, 249 | 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, }, 250 | 251 | // 10: multicolor smiley face 252 | { 0x000, 0x000, 0x00F, 0x00F, 0x00F, 0x00F, 0x000, 0x000, 253 | 0x000, 0x00F, 0x000, 0x000, 0x000, 0x000, 0x00F, 0x000, 254 | 0x00F, 0x000, 0xF00, 0x000, 0x000, 0xF00, 0x000, 0x00F, 255 | 0x00F, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x00F, 256 | 0x00F, 0x000, 0x0F0, 0x000, 0x000, 0x0F0, 0x000, 0x00F, 257 | 0x00F, 0x000, 0x000, 0x0F4, 0x0F3, 0x000, 0x000, 0x00F, 258 | 0x000, 0x00F, 0x000, 0x000, 0x000, 0x000, 0x00F, 0x000, 259 | 0x000, 0x000, 0x00F, 0x00F, 0x00F, 0x00F, 0x000, 0x000, }, 260 | }; 261 | 262 | 263 | // Convert a BGR 4/4/4 bitmap to RGB 5/6/5 used by Adafruit_GFX 264 | void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) { 265 | uint16_t RGB_bmp_fixed[w * h]; 266 | for (uint16_t pixel=0; pixel> 8; 272 | g = (color & 0x0F0) >> 4; 273 | r = color & 0x00F; 274 | //Serial.print(" "); 275 | //Serial.print(b); 276 | //Serial.print("/"); 277 | //Serial.print(g); 278 | //Serial.print("/"); 279 | //Serial.print(r); 280 | //Serial.print(" -> "); 281 | // expand from 4/4/4 bits per color to 5/6/5 282 | b = map(b, 0, 15, 0, 31); 283 | g = map(g, 0, 15, 0, 63); 284 | r = map(r, 0, 15, 0, 31); 285 | //Serial.print(r); 286 | //Serial.print("/"); 287 | //Serial.print(g); 288 | //Serial.print("/"); 289 | //Serial.print(b); 290 | RGB_bmp_fixed[pixel] = (r << 11) + (g << 5) + b; 291 | //Serial.print(" -> "); 292 | //Serial.println(RGB_bmp_fixed[pixel], HEX); 293 | } 294 | display.drawRGBBitmap(x, y, RGB_bmp_fixed, w, h); 295 | } 296 | 297 | // In a case of a tile of neomatrices, this test is helpful to make sure that the 298 | // pixels are all in sequence (to check your wiring order and the tile options you 299 | // gave to the constructor). 300 | void count_pixels() { 301 | display.clear(); 302 | for (uint16_t i=0; i= mw) bmx = 0; 347 | if (!bmx) bmy += 8; 348 | if (bmy >= mh) bmy = 0; 349 | display.show(); 350 | } 351 | 352 | void display_rgbBitmap(uint8_t bmp_num) { 353 | static uint16_t bmx,bmy; 354 | 355 | fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8); 356 | bmx += 8; 357 | if (bmx >= mw) bmx = 0; 358 | if (!bmx) bmy += 8; 359 | if (bmy >= mh) bmy = 0; 360 | display.show(); 361 | } 362 | 363 | void display_lines() { 364 | display.clear(); 365 | 366 | // 4 levels of crossing red lines. 367 | display.drawLine(0,mh/2-2, mw-1,2, LED_RED_VERYLOW); 368 | display.drawLine(0,mh/2-1, mw-1,3, LED_RED_LOW); 369 | display.drawLine(0,mh/2, mw-1,mh/2, LED_RED_MEDIUM); 370 | display.drawLine(0,mh/2+1, mw-1,mh/2+1, LED_RED_HIGH); 371 | 372 | // 4 levels of crossing green lines. 373 | display.drawLine(mw/2-2, 0, mw/2-2, mh-1, LED_GREEN_VERYLOW); 374 | display.drawLine(mw/2-1, 0, mw/2-1, mh-1, LED_GREEN_LOW); 375 | display.drawLine(mw/2+0, 0, mw/2+0, mh-1, LED_GREEN_MEDIUM); 376 | display.drawLine(mw/2+1, 0, mw/2+1, mh-1, LED_GREEN_HIGH); 377 | 378 | // Diagonal blue line. 379 | display.drawLine(0,0, mw-1,mh-1, LED_BLUE_HIGH); 380 | display.drawLine(0,mh-1, mw-1,0, LED_ORANGE_MEDIUM); 381 | display.show(); 382 | } 383 | 384 | void display_boxes() { 385 | display.clear(); 386 | display.drawRect(0,0, mw,mh, LED_BLUE_HIGH); 387 | display.drawRect(1,1, mw-2,mh-2, LED_GREEN_MEDIUM); 388 | display.fillRect(2,2, mw-4,mh-4, LED_RED_HIGH); 389 | display.fillRect(3,3, mw-6,mh-6, LED_ORANGE_MEDIUM); 390 | display.show(); 391 | } 392 | 393 | void display_circles() { 394 | display.clear(); 395 | display.drawCircle(mw/2,mh/2, 2, LED_RED_MEDIUM); 396 | display.drawCircle(mw/2-1-min(mw,mh)/8, mh/2-1-min(mw,mh)/8, min(mw,mh)/4, LED_BLUE_HIGH); 397 | display.drawCircle(mw/2+1+min(mw,mh)/8, mh/2+1+min(mw,mh)/8, min(mw,mh)/4-1, LED_ORANGE_MEDIUM); 398 | display.drawCircle(1,mh-2, 1, LED_GREEN_LOW); 399 | display.drawCircle(mw-2,1, 1, LED_GREEN_HIGH); 400 | if (min(mw,mh)>12) display.drawCircle(mw/2-1, mh/2-1, min(mh/2-1,mw/2-1), LED_CYAN_HIGH); 401 | display.show(); 402 | } 403 | 404 | void display_resolution() { 405 | display.setTextSize(1); 406 | // not wide enough; 407 | if (mw<16) return; 408 | display.clear(); 409 | // Font is 5x7, if display is too small 410 | // 8 can only display 1 char 411 | // 16 can almost display 3 chars 412 | // 24 can display 4 chars 413 | // 32 can display 5 chars 414 | display.setCursor(0, 0); 415 | display.setTextColor(LED_RED_HIGH); 416 | if (mw>10) display.print(mw/10); 417 | display.setTextColor(LED_ORANGE_HIGH); 418 | display.print(mw % 10); 419 | display.setTextColor(LED_GREEN_HIGH); 420 | display.print('x'); 421 | // not wide enough to print 5 chars, go to next line 422 | if (mw<25) { 423 | if (mh==13) display.setCursor(6, 7); 424 | else if (mh>=13) { 425 | display.setCursor(mw-11, 8); 426 | } else { 427 | // we're not tall enough either, so we wait and display 428 | // the 2nd value on top. 429 | display.show(); 430 | delay(2000); 431 | display.clear(); 432 | display.setCursor(mw-11, 0); 433 | } 434 | } 435 | display.setTextColor(LED_CYAN_HIGH); 436 | display.print(mh/10); 437 | display.setTextColor(LED_CYAN_MEDIUM); 438 | display.print(mh % 10); 439 | // enough room for a 2nd line 440 | if ((mw>25 && mh >14) || mh>16) { 441 | display.setCursor(0, mh-7); 442 | display.setTextColor(LED_CYAN_LOW); 443 | if (mw>16) display.print('*'); 444 | display.setTextColor(LED_RED_HIGH); 445 | display.print('R'); 446 | display.setTextColor(LED_GREEN_HIGH); 447 | display.print('G'); 448 | display.setTextColor(LED_BLUE_HIGH); 449 | display.print("B"); 450 | display.setTextColor(LED_PURPLE_HIGH); 451 | // this one could be displayed off screen, but we don't care :) 452 | display.print("*"); 453 | 454 | // We have a big array, great, let's assume 32x32 and add something in the middle 455 | if (mh>24 && mw>25) { 456 | for (uint16_t i=0; i=-42; x--) { 470 | display.clear(); 471 | display.setCursor(x,0); 472 | display.setTextColor(LED_GREEN_HIGH); 473 | display.print("Hello"); 474 | if (mh>11) { 475 | display.setCursor(-20-x,mh-7); 476 | display.setTextColor(LED_ORANGE_HIGH); 477 | display.print("World"); 478 | } 479 | display.show(); 480 | // delay(50); 481 | } 482 | 483 | display.setRotation(1); 484 | display.setTextSize(size); 485 | display.setTextColor(LED_BLUE_HIGH); 486 | for (int16_t x=8*size; x>=-6*8*size; x--) { 487 | display.clear(); 488 | display.setCursor(x,mw/2-size*4); 489 | display.print("Rotate"); 490 | display.show(); 491 | // note that on a big array the refresh rate from show() will be slow enough that 492 | // the delay become irrelevant. This is already true on a 32x32 array. 493 | // delay(50/size); 494 | } 495 | display.setRotation(0); 496 | display.setCursor(0,0); 497 | display.show(); 498 | } 499 | 500 | // Scroll within big bitmap so that all if it becomes visible or bounce a small one. 501 | // If the bitmap is bigger in one dimension and smaller in the other one, it will 502 | // be both panned and bounced in the appropriate dimensions. 503 | void display_panOrBounceBitmap (uint8_t bitmapSize, bool clear = true) { 504 | // keep integer math, deal with values 16 times too big 505 | // start by showing upper left of big bitmap or centering if the display is big 506 | int16_t xf = max(0, (mw-bitmapSize)/2) << 4; 507 | int16_t yf = max(0, (mh-bitmapSize)/2) << 4; 508 | // scroll speed in 1/16th 509 | int16_t xfc = 6; 510 | int16_t yfc = 3; 511 | // scroll down and right by moving upper left corner off screen 512 | // more up and left (which means negative numbers) 513 | int16_t xfdir = -1; 514 | int16_t yfdir = -1; 515 | 516 | uint16_t frames = 200; 517 | long time1 = millis(); 518 | 519 | for (uint16_t i=1; i> 4; 525 | int16_t y = yf >> 4; 526 | 527 | if (clear) display.clear(); 528 | // bounce 8x8 tri color smiley face around the screen 529 | if (bitmapSize == 8) fixdrawRGBBitmap(x, y, RGB_bmp[10], 8, 8); 530 | // pan 24x24 pixmap 531 | if (bitmapSize == 24) display.drawRGBBitmap(x, y, (const uint16_t *) bitmap24, bitmapSize, bitmapSize); 532 | #ifdef BM32 533 | if (bitmapSize == 32) display.drawRGBBitmap(x, y, (const uint16_t *) bitmap32, bitmapSize, bitmapSize); 534 | #endif 535 | display.show(); 536 | 537 | // Only pan if the display size is smaller than the pixmap 538 | // but not if the difference is too small or it'll look bad. 539 | if (bitmapSize-mw>2) { 540 | xf += xfc*xfdir; 541 | if (xf >= 0) { xfdir = -1; updDir = true ; }; 542 | // we don't go negative past right corner, go back positive 543 | if (xf <= ((mw-bitmapSize) << 4)) { xfdir = 1; updDir = true ; }; 544 | } 545 | if (bitmapSize-mh>2) { 546 | yf += yfc*yfdir; 547 | // we shouldn't display past left corner, reverse direction. 548 | if (yf >= 0) { yfdir = -1; updDir = true ; }; 549 | if (yf <= ((mh-bitmapSize) << 4)) { yfdir = 1; updDir = true ; }; 550 | } 551 | // only bounce a pixmap if it's smaller than the display size 552 | if (mw>bitmapSize) { 553 | xf += xfc*xfdir; 554 | // Deal with bouncing off the 'walls' 555 | if (xf >= (mw-bitmapSize) << 4) { xfdir = -1; updDir = true ; }; 556 | if (xf <= 0) { xfdir = 1; updDir = true ; }; 557 | } 558 | if (mh>bitmapSize) { 559 | yf += yfc*yfdir; 560 | if (yf >= (mh-bitmapSize) << 4) { yfdir = -1; updDir = true ; }; 561 | if (yf <= 0) { yfdir = 1; updDir = true ; }; 562 | } 563 | 564 | if (updDir) { 565 | // Add -1, 0 or 1 but bind result to 1 to 1. 566 | // Let's take 3 is a minimum speed, otherwise it's too slow. 567 | xfc = constrain(xfc + random(-1, 2), 3, 16); 568 | yfc = constrain(xfc + random(-1, 2), 3, 16); 569 | } 570 | //delay(10); 571 | } 572 | 573 | uint16_t elapsed = millis() - time1; 574 | uint16_t fps = 1000 * frames / elapsed; 575 | Serial.print("Scroll test number of ms: "); 576 | Serial.println(elapsed); 577 | Serial.print("FPS: "); 578 | Serial.println(fps); 579 | } 580 | 581 | 582 | void loop() { 583 | // clear the screen after X bitmaps have been displayed and we 584 | // loop back to the top left corner 585 | // 8x8 => 1, 16x8 => 2, 17x9 => 6 586 | static uint8_t pixmap_count = ((mw+7)/8) * ((mh+7)/8); 587 | 588 | 589 | // ESP8266 HWSPI: 34 fps, SWSPI: 6 fps 590 | // If you change SPI frequency to 80Mhz in display.begin, you can get 64fps 591 | uint16_t frames = 20; 592 | long time1 = millis(); 593 | for (uint8_t i=0; i8?500:1500); 704 | } 705 | // If we have multiple pixmaps displayed at once, wait a bit longer on the last. 706 | delay(mw>8?1000:500); 707 | 708 | Serial.println("Display lines, boxes and circles"); 709 | display_lines(); 710 | delay(3000); 711 | 712 | display_boxes(); 713 | delay(3000); 714 | 715 | display_circles(); 716 | delay(3000); 717 | display.clear(); 718 | 719 | Serial.println("Display RGB bitmaps"); 720 | for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) 721 | { 722 | display_rgbBitmap(i); 723 | delay(mw>8?500:1500); 724 | } 725 | // If we have multiple pixmaps displayed at once, wait a bit longer on the last. 726 | delay(mw>8?1000:500); 727 | 728 | Serial.println("Scrolltext"); 729 | display_scrollText(); 730 | 731 | Serial.println("Demo loop done, starting over"); 732 | } 733 | 734 | void setup() { 735 | delay(1000); 736 | Serial.begin(115200); 737 | // Default is 40Mhz 738 | display.begin(); 739 | Serial.println("For extra speed, try 80Mhz, may be less stable"); 740 | //display.begin(80000000); 741 | display.setTextWrap(false); 742 | display.setAddrWindow(0, 0, mw, mh); 743 | // Test full bright of all LEDs. If brightness is too high 744 | // for your current limit (i.e. USB), decrease it. 745 | display.fillScreen(LED_WHITE_HIGH); 746 | display.show(); 747 | delay(3000); 748 | display.clear(); 749 | } 750 | 751 | // vim:sts=4:sw=4 752 | --------------------------------------------------------------------------------