├── _config.yml ├── SPFD5408 ├── bitmaps │ ├── test.bmp │ ├── woof.bmp │ └── miniwoof.bmp ├── adafruit_docs │ ├── README_ADAFRUIT_TOUCHSCREEN.txt │ ├── README_ADAFRUIT_TFTLCD.txt │ ├── license.txt │ └── README_ADAFRUIT_GFX.txt ├── gfx.library.properties ├── SPFD5408_TouchScreen.h ├── LICENSE ├── license.txt ├── SPFD5408_Adafruit_TFTLCD.h ├── SPFD5408_Adafruit_GFX.h ├── registers.h ├── README.md ├── examples │ ├── adafruit_originals │ │ ├── tftpaint_shield │ │ │ ├── tftpaint_shield.ino │ │ │ ├── tftpaint_shield.pde │ │ │ └── glcdfont.c │ │ ├── tftpaint │ │ │ ├── tftpaint.pde │ │ │ └── tftpaint.ino │ │ ├── rotationtest │ │ │ └── rotationtest.pde │ │ ├── tftbmp_shield │ │ │ └── tftbmp_shield.pde │ │ ├── tftbmp │ │ │ └── tftbmp.pde │ │ └── graphicstest │ │ │ └── graphicstest.pde │ ├── spfd5408_rotationtest │ │ └── spfd5408_rotationtest.ino │ ├── spfd5408_tftpaint │ │ └── spfd5408_tftpaint.ino │ ├── spfd5408_tftbmp │ │ └── spfd5408_tftbmp.ino │ ├── spfd5408_calibrate │ │ └── spfd5408_calibrate.ino │ └── spfd5408_graphicstest │ │ └── spfd5408_graphicstest.ino ├── SPFD5408_TouchScreen.cpp ├── glcdfont.c └── SPFD5408_Adafruit_GFX.cpp ├── Working_Pictures ├── tft.jpg ├── 3ax_accel.jpg ├── mega2560.jpg ├── accel_connec.jpg ├── set rate to 8.jpg ├── IMG_20190303_192400.jpg ├── working_ungrounded.jpg └── picking analog signal.jpg ├── .gitignore ├── CONTRIBUTING.md ├── CODE_OF_CONDUCT.md ├── port log.txt └── README.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /SPFD5408/bitmaps/test.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/SPFD5408/bitmaps/test.bmp -------------------------------------------------------------------------------- /SPFD5408/bitmaps/woof.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/SPFD5408/bitmaps/woof.bmp -------------------------------------------------------------------------------- /Working_Pictures/tft.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/tft.jpg -------------------------------------------------------------------------------- /SPFD5408/bitmaps/miniwoof.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/SPFD5408/bitmaps/miniwoof.bmp -------------------------------------------------------------------------------- /Working_Pictures/3ax_accel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/3ax_accel.jpg -------------------------------------------------------------------------------- /Working_Pictures/mega2560.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/mega2560.jpg -------------------------------------------------------------------------------- /Working_Pictures/accel_connec.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/accel_connec.jpg -------------------------------------------------------------------------------- /Working_Pictures/set rate to 8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/set rate to 8.jpg -------------------------------------------------------------------------------- /Working_Pictures/IMG_20190303_192400.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/IMG_20190303_192400.jpg -------------------------------------------------------------------------------- /Working_Pictures/working_ungrounded.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/working_ungrounded.jpg -------------------------------------------------------------------------------- /Working_Pictures/picking analog signal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/HEAD/Working_Pictures/picking analog signal.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | applet 3 | application.linux32 4 | application.linux64 5 | application.windows32 6 | application.windows64 7 | application.macosx 8 | -------------------------------------------------------------------------------- /SPFD5408/adafruit_docs/README_ADAFRUIT_TOUCHSCREEN.txt: -------------------------------------------------------------------------------- 1 | This is the 4-wire resistive touch screen firmware for Arduino. Works with all Arduinos and the Mega 2 | 3 | 4 | To install, click DOWNLOAD SOURCE in the top right corner, and rename the uncompressed folder "TouchScreen". See our tutorial at http://www.ladyada.net/library/arduino/libraries.html on Arduino Library installation -------------------------------------------------------------------------------- /SPFD5408/gfx.library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit GFX Library 2 | version=1.0.2 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from. 6 | paragraph=Install this library in addition to the display library for your hardware. 7 | category=Display 8 | url=https://github.com/adafruit/Adafruit-GFX-Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /SPFD5408/SPFD5408_TouchScreen.h: -------------------------------------------------------------------------------- 1 | // Touch screen library with X Y and Z (pressure) readings as well 2 | // as oversampling to avoid 'bouncing' 3 | // (c) ladyada / adafruit 4 | // Code under MIT License 5 | 6 | #ifndef _ADAFRUIT_TOUCHSCREEN_H_ 7 | #define _ADAFRUIT_TOUCHSCREEN_H_ 8 | #include 9 | 10 | class TSPoint { 11 | public: 12 | TSPoint(void); 13 | TSPoint(int16_t x, int16_t y, int16_t z); 14 | 15 | bool operator==(TSPoint); 16 | bool operator!=(TSPoint); 17 | 18 | int16_t x, y, z; 19 | }; 20 | 21 | class TouchScreen { 22 | public: 23 | TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym); 24 | TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx); 25 | 26 | bool isTouching(void); 27 | uint16_t pressure(void); 28 | int readTouchY(); 29 | int readTouchX(); 30 | TSPoint getPoint(); 31 | int16_t pressureThreshhold; 32 | 33 | private: 34 | uint8_t _yp, _ym, _xm, _xp; 35 | uint16_t _rxplate; 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /SPFD5408/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 JoaoLopesF 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /SPFD5408/adafruit_docs/README_ADAFRUIT_TFTLCD.txt: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit 2.8" TFT display. 2 | This library works with the Adafruit 2.8" TFT Breakout w/SD card 3 | ----> http://www.adafruit.com/products/335 4 | as well as Adafruit TFT Touch Shield 5 | ----> http://www.adafruit.com/products/376 6 | 7 | Check out the links above for our tutorials and wiring diagrams. 8 | These displays use 8-bit parallel to communicate, 12 or 13 pins are required 9 | to interface (RST is optional). 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 | MIT license, all text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_TFTLCD. Check that the Adafruit_TFTLCD folder contains Adafruit_TFTLCD.cpp and Adafruit_TFTLCD. 18 | 19 | Place the Adafruit_TFT library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE 20 | 21 | Also requires the Adafruit_GFX library for Arduino. https://github.com/adafruit/Adafruit-GFX-Library 22 | -------------------------------------------------------------------------------- /SPFD5408/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) Joao Lopes. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | - Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /SPFD5408/adafruit_docs/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012 Adafruit Industries. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | - Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /SPFD5408/adafruit_docs/README_ADAFRUIT_GFX.txt: -------------------------------------------------------------------------------- 1 | This is the core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.). It needs to be paired with a hardware-specific library for each display device we carry (to handle the lower-level functions). 2 | 3 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 4 | 5 | Written by Limor Fried/Ladyada for Adafruit Industries. 6 | BSD license, check license.txt for more information. 7 | All text above must be included in any redistribution. 8 | 9 | To download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_GFX. Confirm that the Adafruit_GFX folder contains Adafruit_GFX.cpp and Adafruit_GFX.h 10 | 11 | Place the Adafruit_GFX library folder your /Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE. 12 | 13 | Useful Resources 14 | ================ 15 | 16 | - Image2Code 17 | This is a handy Java GUI utility to convert a BMP file into the array code necessary to display the image with the drawBitmap function. Check out the code at ehubin's GitHub repository: 18 | https://github.com/ehubin/Adafruit-GFX-Library/tree/master/Img2Code 19 | 20 | - drawXBitmap function 21 | You can use the GIMP photo editor to save a .xbm file and use the array saved in the file to draw a bitmap with the drawXBitmap function. See the pull request here for more details: 22 | https://github.com/adafruit/Adafruit-GFX-Library/pull/31 23 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | First and foremost (beyi saarvi khuate guadniyath) I welcome, all the good-hearted, open-soucerers, and bright minded people to Osciduino-Project. Thank you for your time and dedication towards Osciduino Project!. 3 | 4 | Ahem! Well the greetings done so, let me put it simple for you guys; 5 | 6 | ### What is this? 7 | This is the Contributig guidelines document, I prescribe before heading into the wonderland of contributing. Stay safe in your 8 | journey :-) 9 | 10 | # Contributing to "Osciduino" 11 | 12 | Osciduino Project is an educational project to show the inner workings of an Oscilloscope (I know you have read it a thousand 13 | times by now, but still!). 14 | 15 | This project is still in it's toddler steps and I would really like some help to stand right up and walk straight. 16 | 17 | ## How can I help? 18 | 19 | You can help in a lot of ways, let me list some for youl 20 | 21 | ### Reporting 'Good Bugs' 22 | 23 | Bugs are one thing, I am sure no one likes. So if you happen to spot one in the code or while running. Create a 'New Issue' in 24 | the Osciduino repository 25 | 26 | ### Expanding scope 27 | 28 | I am limited in both resources and time as an individaul. So you guys can help by making the "Osciduino-Environment" more 29 | adaptable. Like by adding support for the original Adafruit TFT display, or the OLED display. or by using more powerful and 30 | Efficient hardware, like Arduino Due (and adding support for it). You can even add ecternal peripheries to increase the 31 | functionality and practicality of the setup, like by adding external ADC's with better resolution, by adding level shifters 32 | to add support for Alternating signals (the ones with negative and positive halfs). 33 | 34 | It's not just hardware, if you think the code can be improved and increased in efficiency that counts too. 35 | 36 | ### Wiki 37 | 38 | I am trying to document this project and make it helpful to everyone, interested enough in it. So improving the wiki, by 39 | contributing content, like 'examples', Setup with different hardware and how to do it and how you did it! 40 | 41 | 42 | 43 | ### If my change is too big, what should I do? 44 | 45 | If the change in code is something big, I suggest you create a fork of this project 46 | 47 | ### How do I contribute code? 48 | 49 | If you want to add some piece of code or improve upon it, Create a pull request 50 | 51 | ### If your's is a harware addition! 52 | > good job 53 | 54 | I recommend you create a fork of this project and then alter it's charachteristics. If it is too radical for modifying the 55 | code. It is better to create a seperate repository. 56 | Create an issue and tag me using @wayri so that I can link to your project 57 | 58 | 59 | 60 | 61 | > I will update this doc as time goes, so keep an eye out for it :). 62 | 63 | #### Happy Sourcering! 64 | #### Yawar Badri (wayri) 65 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /SPFD5408/SPFD5408_Adafruit_TFTLCD.h: -------------------------------------------------------------------------------- 1 | // IMPORTANT: SEE COMMENTS @ LINE 15 REGARDING SHIELD VS BREAKOUT BOARD USAGE. 2 | 3 | // Graphics library by ladyada/adafruit with init code from Rossum 4 | // MIT license 5 | 6 | // Modified for SPFD5408 by Joao Lopes 7 | 8 | #ifndef _ADAFRUIT_TFTLCD_H_ 9 | #define _ADAFRUIT_TFTLCD_H_ 10 | 11 | #if ARDUINO >= 100 12 | #include "Arduino.h" 13 | #else 14 | #include "WProgram.h" 15 | #endif 16 | 17 | // *** SPFD5408 change -- Begin 18 | #include 19 | // -- End 20 | 21 | // **** IF USING THE LCD BREAKOUT BOARD, COMMENT OUT THIS NEXT LINE. **** 22 | // **** IF USING THE LCD SHIELD, LEAVE THE LINE ENABLED: **** 23 | 24 | // *** SPFD5408 change -- Begin 25 | //#define USE_ADAFRUIT_SHIELD_PINOUT 1 26 | // -- End 27 | 28 | class Adafruit_TFTLCD : public Adafruit_GFX { 29 | 30 | public: 31 | 32 | Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst); 33 | Adafruit_TFTLCD(void); 34 | 35 | void begin(uint16_t id = 0x9325); 36 | void drawPixel(int16_t x, int16_t y, uint16_t color); 37 | void drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color); 38 | void drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color); 39 | void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c); 40 | void fillScreen(uint16_t color); 41 | void reset(void); 42 | void setRegisters8(uint8_t *ptr, uint8_t n); 43 | void setRegisters16(uint16_t *ptr, uint8_t n); 44 | void setRotation(uint8_t x); 45 | // These methods are public in order for BMP examples to work: 46 | void setAddrWindow(int x1, int y1, int x2, int y2); 47 | void pushColors(uint16_t *data, uint8_t len, boolean first); 48 | 49 | uint16_t color565(uint8_t r, uint8_t g, uint8_t b), 50 | readPixel(int16_t x, int16_t y), 51 | readID(void); 52 | uint32_t readReg(uint8_t r); 53 | 54 | private: 55 | 56 | void init(), 57 | // These items may have previously been defined as macros 58 | // in pin_magic.h. If not, function versions are declared: 59 | #ifndef write8 60 | write8(uint8_t value), 61 | #endif 62 | #ifndef setWriteDir 63 | setWriteDir(void), 64 | #endif 65 | #ifndef setReadDir 66 | setReadDir(void), 67 | #endif 68 | #ifndef writeRegister8 69 | writeRegister8(uint8_t a, uint8_t d), 70 | #endif 71 | #ifndef writeRegister16 72 | writeRegister16(uint16_t a, uint16_t d), 73 | #endif 74 | writeRegister24(uint8_t a, uint32_t d), 75 | writeRegister32(uint8_t a, uint32_t d), 76 | #ifndef writeRegisterPair 77 | writeRegisterPair(uint8_t aH, uint8_t aL, uint16_t d), 78 | #endif 79 | setLR(void), 80 | flood(uint16_t color, uint32_t len); 81 | uint8_t driver; 82 | 83 | #ifndef read8 84 | uint8_t read8fn(void); 85 | #define read8isFunctionalized 86 | #endif 87 | 88 | #ifndef USE_ADAFRUIT_SHIELD_PINOUT 89 | 90 | #ifdef __AVR__ 91 | volatile uint8_t *csPort , *cdPort , *wrPort , *rdPort; 92 | uint8_t csPinSet , cdPinSet , wrPinSet , rdPinSet , 93 | csPinUnset, cdPinUnset, wrPinUnset, rdPinUnset, 94 | _reset; 95 | #endif 96 | #if defined(__SAM3X8E__) 97 | Pio *csPort , *cdPort , *wrPort , *rdPort; 98 | uint32_t csPinSet , cdPinSet , wrPinSet , rdPinSet , 99 | csPinUnset, cdPinUnset, wrPinUnset, rdPinUnset, 100 | _reset; 101 | #endif 102 | 103 | #endif 104 | }; 105 | 106 | // For compatibility with sketches written for older versions of library. 107 | // Color function name was changed to 'color565' for parity with 2.2" LCD 108 | // library. 109 | #define Color565 color565 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /SPFD5408/SPFD5408_Adafruit_GFX.h: -------------------------------------------------------------------------------- 1 | #ifndef _ADAFRUIT_GFX_H 2 | #define _ADAFRUIT_GFX_H 3 | 4 | #if ARDUINO >= 100 5 | #include "Arduino.h" 6 | #include "Print.h" 7 | #else 8 | #include "WProgram.h" 9 | #endif 10 | 11 | #define swap(a, b) { int16_t t = a; a = b; b = t; } 12 | 13 | class Adafruit_GFX : public Print { 14 | 15 | public: 16 | 17 | Adafruit_GFX(int16_t w, int16_t h); // Constructor 18 | 19 | // This MUST be defined by the subclass: 20 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 21 | 22 | // These MAY be overridden by the subclass to provide device-specific 23 | // optimized code. Otherwise 'generic' versions are used. 24 | virtual void 25 | drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color), 26 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 27 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 28 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 29 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 30 | fillScreen(uint16_t color), 31 | invertDisplay(boolean i); 32 | 33 | // These exist only with Adafruit_GFX (no subclass overrides) 34 | void 35 | drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 36 | drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 37 | uint16_t color), 38 | fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 39 | fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 40 | int16_t delta, uint16_t color), 41 | drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 42 | int16_t x2, int16_t y2, uint16_t color), 43 | fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 44 | int16_t x2, int16_t y2, uint16_t color), 45 | drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 46 | int16_t radius, uint16_t color), 47 | fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 48 | int16_t radius, uint16_t color), 49 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 50 | int16_t w, int16_t h, uint16_t color), 51 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 52 | int16_t w, int16_t h, uint16_t color, uint16_t bg), 53 | drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 54 | int16_t w, int16_t h, uint16_t color), 55 | drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, 56 | uint16_t bg, uint8_t size), 57 | setCursor(int16_t x, int16_t y), 58 | setTextColor(uint16_t c), 59 | setTextColor(uint16_t c, uint16_t bg), 60 | setTextSize(uint8_t s), 61 | setTextWrap(boolean w), 62 | setRotation(uint8_t r), 63 | cp437(boolean x=true); 64 | 65 | #if ARDUINO >= 100 66 | virtual size_t write(uint8_t); 67 | #else 68 | virtual void write(uint8_t); 69 | #endif 70 | 71 | int16_t height(void) const; 72 | int16_t width(void) const; 73 | 74 | uint8_t getRotation(void) const; 75 | 76 | // get current cursor position (get rotation safe maximum values, using: width() for x, height() for y) 77 | int16_t getCursorX(void) const; 78 | int16_t getCursorY(void) const; 79 | 80 | protected: 81 | const int16_t 82 | WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes 83 | int16_t 84 | _width, _height, // Display w/h as modified by current rotation 85 | cursor_x, cursor_y; 86 | uint16_t 87 | textcolor, textbgcolor; 88 | uint8_t 89 | textsize, 90 | rotation; 91 | boolean 92 | wrap, // If set, 'wrap' text at right edge of display 93 | _cp437; // If set, use correct CP437 charset (default is off) 94 | }; 95 | 96 | class Adafruit_GFX_Button { 97 | 98 | public: 99 | Adafruit_GFX_Button(void); 100 | void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y, 101 | uint8_t w, uint8_t h, 102 | uint16_t outline, uint16_t fill, uint16_t textcolor, 103 | char *label, uint8_t textsize); 104 | void drawButton(boolean inverted = false); 105 | boolean contains(int16_t x, int16_t y); 106 | 107 | void press(boolean p); 108 | boolean isPressed(); 109 | boolean justPressed(); 110 | boolean justReleased(); 111 | 112 | private: 113 | Adafruit_GFX *_gfx; 114 | int16_t _x, _y; 115 | uint16_t _w, _h; 116 | uint8_t _textsize; 117 | uint16_t _outlinecolor, _fillcolor, _textcolor; 118 | char _label[10]; 119 | 120 | boolean currstate, laststate; 121 | }; 122 | 123 | #endif // _ADAFRUIT_GFX_H 124 | -------------------------------------------------------------------------------- /port log.txt: -------------------------------------------------------------------------------- 1 | 2 | PORT LOG 3 | 4 | ------------------------------------------------------------------------------------------------------------------------------ 5 | //24/07/2016 - 2100 6 | 7 | 8 | POrt was successfully compiled 9 | 10 | //replaced define tags with hex code in color - and applied designated changes| required| 11 | 12 | //included the correct tft library 13 | 14 | //corrected the tft.begin(X) tag in setup, where X - is the driver hex code identifier 15 | 16 | 17 | 18 | 19 | ------------------------------------------------------------------------------------------------------------------------------ 20 | //25/07/2016 - 1506 21 | 22 | 23 | Port was succesfully compiled and run 24 | 25 | //replaced the pin for ch1 | from pin 5 to pin 8 in Analog read enabling easy access to the pin 26 | 27 | 28 | 29 | 30 | ------------------------------------------------------------------------------------------------------------------------------- 31 | //14/09/2016 - 2219 32 | 33 | 34 | Port was Succesfully compiled and run, /I\ - the voltage text was overwriting itself and not refreshed. GIC(get it correct) 35 | STATUS - CORRECTED 36 | 37 | //added ability to display voltage approximated on screen. by calculation using ratios and proportions. 38 | 39 | ! - for 5 volts as maximum value giving 1023 as sensor reading. and 0v = 0 sensor read. 40 | --> 5 = 1023 41 | --- ----- , X is the RT sensor read. and V is the corresponding voltage. 42 | V X 43 | 44 | 45 | -------------------------------------------------------------------------------------------------------------------------------- 46 | //3/11/2016 2036 47 | 48 | 49 | Port was Succesfully compiled and run 50 | 51 | // removed grid to increase efficiency in processing time /!\ - commented all grid function calls 52 | ! - add option to toggle grid 53 | 54 | //at line 88 55 | 56 | --> increased rate of sampling from '3' to '6' --| it seemingly increases buffer hold time and thus allows to see live variation in frequency unlike earlier at '3' 57 | 58 | --------------------------------------------------------------------------------------------------------------------------------- 59 | //26/11/2016 2110 60 | 61 | used || 'map' function to make it usable for negative voltages as well as positive 62 | but the code is commented out as of now ___line 28 and 32 for map and hold variable respectively. 63 | 64 | //at line 72 in array lengths reset the first block to 4 instead of 6 65 | 66 | 67 | //at line 88 68 | // --> decreased rate of sampling from '6' to '3' 69 | 70 | BELOW ------------------ BELOW ----------------------- BELOW----------------------------------------------- 71 | Port was NOT successful /!\ - but has some inherent defect 72 | STATUS - CORRECTED 73 | //Created custom resistor configuration ! - refer notes 74 | 75 | //at line 160 76 | // fed the values in the array 77 | --> verified by Serial printing of values 78 | // all good till now 79 | 80 | PROBLEM - the for loop || Serial.prinln(sw); || doesn't give any value i.e, blank Serial at given baud rate 9600 81 | =>~~ seemingly the for loop isn't entered during execution 82 | 83 | sOLUTION, THERE wAS a Stray 'return;' in the "CheckSW()" FUNCTION. rEMOVED iT. 84 | 85 | 86 | ------------------------------------------------------------------------------------------------------------------------------------- 87 | 6/04/2017 2140 88 | Ported the new switch arrray || refer notes --> ARR2 89 | corrected the value display 90 | 91 | 92 | /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ 93 | the next part is to display which menu we are in. 94 | display frequency 95 | \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ 96 | Stage One is Complete 97 | 98 | 99 | _____________________________________________________________________________________________________________________________________ 100 | ___________________________________________/\______________________________________________/\________________________________________ 101 | 102 | 103 | Stage TWO >> Port the resistor array to touch screen 104 | >> Ability To visualise BiPolar signals 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino Oscilloscope 2 | 3 | ![arduino_oscillo](https://raw.githubusercontent.com/wayri/Arduino-Oscilloscope/master/Working_Pictures/working_ungrounded.jpg) 4 | 5 | Arduino based Oscilloscope with advanced features and two channels. It is a DIY **Oscilloscope** based on popular Arduino platform. 6 | 7 | 8 | Arduino-Oscilloscope(here-after reffered to as Osciduino| *There is another project with the same name that is why the title name is changed here, after I saw the another project with the same name ie OsciDuino*) is an arduino based oscilloscope (tried and tested on arduino uno r3 and mega 2560). Though I would recommend using mega if you can. 9 | 10 | ### Why and what can it do 11 | it is an educational project to get the insight into the internal workings of a buffered digital oscilloscope (DSO). 12 | this version includes advanced functionality to the setup, by including features like dual channel, offset, trigger, time/div, volts/div, and like wise. 13 | 14 | ### Inputs and few things to consider 15 | The inputs are taken from 2 analog input pins on arduino. the pins however support only voltage range of 0 to +5 volts. so ths oscilloscope works well only if the signal being viewed is +5 volts peak to peak maximum and doesn't have any negative halfs. to view negative halfs, the oscilloscope has to be operated in a +2.5 volts peak mode. this is accomplished externally by scaling the voltage and then offsetting it by +2.5 volts. 16 | 17 | ### What should I know 18 | An additional display library is included in the master for SPFD5408, if required. 19 | Also the schematics for the setup are included in the "arduino files" folder 20 | 21 | > Currently the code works best with the provided library and thus a specific display driver SPDF5408. 22 | This however does not mean that it will not work with other drivers. It's just that behaviour might be different 23 | as I have not tested it with any other display. You are welcome to add support for your display driver. 24 | if you want to add support to your display. You can either contribute or create a pull-request. An example is adding 25 | support for [Adafruit 2.5 inch Resistive touch screen display](https://github.com/wayri/Osciduino/issues/1) 26 | 27 | ## Installation - Quick start 28 | 29 | This is really simple to do just follow the following steps and you are up-and-running. 30 | 31 | First and foremost plug in the *Display to Arduino*. For this see [How to assemble the hardware](https://wayri.github.io/Osciduino/wiki) 32 | 33 | - Plug in your arduino (uno or mega) to the computer using the usb-2.0 34 | - Open the **arduino-oscilloscope-high-freq_v1_5_HW.ino** in arduino IDE 35 | - Select your board from "Tools" menu 36 | - Click upload 37 | - You are up and running 38 | 39 | /!\ Make sure that 'CH1' and or 'CH2' is set to 'ON' 40 | 41 | ### Hello World 42 | 43 | The following is a "hello world" example for the Osciduino 44 | 45 | observing charging and Discharging of a capacitor 46 | 47 | ##### Setup 48 | Power up the Osciduino, as mentioned above in the Quick start. 49 | Now on a breadboard connect an electrolytic capacitor in series with a resistor to a square wave generator. 50 | Place the probe on the resistor capacitor node. Add a common reference ground between Osciduino and the RC circuit 51 | 52 | 53 | And you should start seeing the charachteristic rise and fall slopes 54 | associated with charging and discharging of the capacitor. 55 | 56 | See 57 | - [Examples - Simple RC circuit](https://github.com/wayri/Osciduino/wiki/examples) for more details 58 | - [In Use - ADXL335](https://github.com/wayri/Arduino-Oscilloscope/wiki/General-Outline#use) for more details 59 | 60 | [![ADXL335 with Mega video](https://i.ytimg.com/vi/DczcwX6qwa0/hqdefault.jpg)](https://www.youtube.com/embed/DczcwX6qwa0) 61 | 62 | ### Current problems 63 | 64 | The setup requires an external resistive control interface. Which requires callibration on every boot. As resistance changes easily with temperature and long durations of running. This can be mitigated in a lot of ways, for example by replacing the resistive divider switch 65 | configuration by a touch based scheme or a push button scheme encoded into the free GPIO pins on the arduino mega. 66 | 67 | ### Updates and Latest Releases 68 | Starting version 1.5, the hardware extension support will be addedto the project - [release v1.5.0](https://github.com/wayri/Arduino-Oscilloscope/releases/tag/v1.5.0) 69 | ### Further Links and references 70 | 71 | The code is originally based on the one by Mr. Noriaki Mitsunaga http://n.mtng.org/ele/index.html 72 | 73 | 74 | - [Osciduino quick setup] 75 | - [Osciduino wiki](https://github.com/wayri/Arduino-Oscilloscope/wiki) 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /SPFD5408/registers.h: -------------------------------------------------------------------------------- 1 | // Register names from Peter Barrett's Microtouch code 2 | #define ILI932X_START_OSC 0x00 3 | #define ILI932X_DRIV_OUT_CTRL 0x01 4 | #define ILI932X_DRIV_WAV_CTRL 0x02 5 | #define ILI932X_ENTRY_MOD 0x03 6 | #define ILI932X_RESIZE_CTRL 0x04 7 | #define ILI932X_DISP_CTRL1 0x07 8 | #define ILI932X_DISP_CTRL2 0x08 9 | #define ILI932X_DISP_CTRL3 0x09 10 | #define ILI932X_DISP_CTRL4 0x0A 11 | #define ILI932X_RGB_DISP_IF_CTRL1 0x0C 12 | #define ILI932X_FRM_MARKER_POS 0x0D 13 | #define ILI932X_RGB_DISP_IF_CTRL2 0x0F 14 | #define ILI932X_POW_CTRL1 0x10 15 | #define ILI932X_POW_CTRL2 0x11 16 | #define ILI932X_POW_CTRL3 0x12 17 | #define ILI932X_POW_CTRL4 0x13 18 | #define ILI932X_GRAM_HOR_AD 0x20 19 | #define ILI932X_GRAM_VER_AD 0x21 20 | #define ILI932X_RW_GRAM 0x22 21 | #define ILI932X_POW_CTRL7 0x29 22 | #define ILI932X_FRM_RATE_COL_CTRL 0x2B 23 | #define ILI932X_GAMMA_CTRL1 0x30 24 | #define ILI932X_GAMMA_CTRL2 0x31 25 | #define ILI932X_GAMMA_CTRL3 0x32 26 | #define ILI932X_GAMMA_CTRL4 0x35 27 | #define ILI932X_GAMMA_CTRL5 0x36 28 | #define ILI932X_GAMMA_CTRL6 0x37 29 | #define ILI932X_GAMMA_CTRL7 0x38 30 | #define ILI932X_GAMMA_CTRL8 0x39 31 | #define ILI932X_GAMMA_CTRL9 0x3C 32 | #define ILI932X_GAMMA_CTRL10 0x3D 33 | #define ILI932X_HOR_START_AD 0x50 34 | #define ILI932X_HOR_END_AD 0x51 35 | #define ILI932X_VER_START_AD 0x52 36 | #define ILI932X_VER_END_AD 0x53 37 | #define ILI932X_GATE_SCAN_CTRL1 0x60 38 | #define ILI932X_GATE_SCAN_CTRL2 0x61 39 | #define ILI932X_GATE_SCAN_CTRL3 0x6A 40 | #define ILI932X_PART_IMG1_DISP_POS 0x80 41 | #define ILI932X_PART_IMG1_START_AD 0x81 42 | #define ILI932X_PART_IMG1_END_AD 0x82 43 | #define ILI932X_PART_IMG2_DISP_POS 0x83 44 | #define ILI932X_PART_IMG2_START_AD 0x84 45 | #define ILI932X_PART_IMG2_END_AD 0x85 46 | #define ILI932X_PANEL_IF_CTRL1 0x90 47 | #define ILI932X_PANEL_IF_CTRL2 0x92 48 | #define ILI932X_PANEL_IF_CTRL3 0x93 49 | #define ILI932X_PANEL_IF_CTRL4 0x95 50 | #define ILI932X_PANEL_IF_CTRL5 0x97 51 | #define ILI932X_PANEL_IF_CTRL6 0x98 52 | 53 | #define HX8347G_COLADDRSTART_HI 0x02 54 | #define HX8347G_COLADDRSTART_LO 0x03 55 | #define HX8347G_COLADDREND_HI 0x04 56 | #define HX8347G_COLADDREND_LO 0x05 57 | #define HX8347G_ROWADDRSTART_HI 0x06 58 | #define HX8347G_ROWADDRSTART_LO 0x07 59 | #define HX8347G_ROWADDREND_HI 0x08 60 | #define HX8347G_ROWADDREND_LO 0x09 61 | #define HX8347G_MEMACCESS 0x16 62 | 63 | 64 | 65 | #define ILI9341_SOFTRESET 0x01 66 | #define ILI9341_SLEEPIN 0x10 67 | #define ILI9341_SLEEPOUT 0x11 68 | #define ILI9341_NORMALDISP 0x13 69 | #define ILI9341_INVERTOFF 0x20 70 | #define ILI9341_INVERTON 0x21 71 | #define ILI9341_GAMMASET 0x26 72 | #define ILI9341_DISPLAYOFF 0x28 73 | #define ILI9341_DISPLAYON 0x29 74 | #define ILI9341_COLADDRSET 0x2A 75 | #define ILI9341_PAGEADDRSET 0x2B 76 | #define ILI9341_MEMORYWRITE 0x2C 77 | #define ILI9341_PIXELFORMAT 0x3A 78 | #define ILI9341_FRAMECONTROL 0xB1 79 | #define ILI9341_DISPLAYFUNC 0xB6 80 | #define ILI9341_ENTRYMODE 0xB7 81 | #define ILI9341_POWERCONTROL1 0xC0 82 | #define ILI9341_POWERCONTROL2 0xC1 83 | #define ILI9341_VCOMCONTROL1 0xC5 84 | #define ILI9341_VCOMCONTROL2 0xC7 85 | #define ILI9341_MEMCONTROL 0x36 86 | #define ILI9341_MADCTL 0x36 87 | 88 | #define ILI9341_MADCTL_MY 0x80 89 | #define ILI9341_MADCTL_MX 0x40 90 | #define ILI9341_MADCTL_MV 0x20 91 | #define ILI9341_MADCTL_ML 0x10 92 | #define ILI9341_MADCTL_RGB 0x00 93 | #define ILI9341_MADCTL_BGR 0x08 94 | #define ILI9341_MADCTL_MH 0x04 95 | 96 | 97 | 98 | #define HX8357_NOP 0x00 99 | #define HX8357_SWRESET 0x01 100 | #define HX8357_RDDID 0x04 101 | #define HX8357_RDDST 0x09 102 | 103 | #define HX8357B_RDPOWMODE 0x0A 104 | #define HX8357B_RDMADCTL 0x0B 105 | #define HX8357B_RDCOLMOD 0x0C 106 | #define HX8357B_RDDIM 0x0D 107 | #define HX8357B_RDDSDR 0x0F 108 | 109 | #define HX8357_SLPIN 0x10 110 | #define HX8357_SLPOUT 0x11 111 | #define HX8357B_PTLON 0x12 112 | #define HX8357B_NORON 0x13 113 | 114 | #define HX8357_INVOFF 0x20 115 | #define HX8357_INVON 0x21 116 | #define HX8357_DISPOFF 0x28 117 | #define HX8357_DISPON 0x29 118 | 119 | #define HX8357_CASET 0x2A 120 | #define HX8357_PASET 0x2B 121 | #define HX8357_RAMWR 0x2C 122 | #define HX8357_RAMRD 0x2E 123 | 124 | #define HX8357B_PTLAR 0x30 125 | #define HX8357_TEON 0x35 126 | #define HX8357_TEARLINE 0x44 127 | #define HX8357_MADCTL 0x36 128 | #define HX8357_COLMOD 0x3A 129 | 130 | #define HX8357_SETOSC 0xB0 131 | #define HX8357_SETPWR1 0xB1 132 | #define HX8357B_SETDISPLAY 0xB2 133 | #define HX8357_SETRGB 0xB3 134 | #define HX8357D_SETCOM 0xB6 135 | 136 | #define HX8357B_SETDISPMODE 0xB4 137 | #define HX8357D_SETCYC 0xB4 138 | #define HX8357B_SETOTP 0xB7 139 | #define HX8357D_SETC 0xB9 140 | 141 | #define HX8357B_SET_PANEL_DRIVING 0xC0 142 | #define HX8357D_SETSTBA 0xC0 143 | #define HX8357B_SETDGC 0xC1 144 | #define HX8357B_SETID 0xC3 145 | #define HX8357B_SETDDB 0xC4 146 | #define HX8357B_SETDISPLAYFRAME 0xC5 147 | #define HX8357B_GAMMASET 0xC8 148 | #define HX8357B_SETCABC 0xC9 149 | #define HX8357_SETPANEL 0xCC 150 | 151 | 152 | #define HX8357B_SETPOWER 0xD0 153 | #define HX8357B_SETVCOM 0xD1 154 | #define HX8357B_SETPWRNORMAL 0xD2 155 | 156 | #define HX8357B_RDID1 0xDA 157 | #define HX8357B_RDID2 0xDB 158 | #define HX8357B_RDID3 0xDC 159 | #define HX8357B_RDID4 0xDD 160 | 161 | #define HX8357D_SETGAMMA 0xE0 162 | 163 | #define HX8357B_SETGAMMA 0xC8 164 | #define HX8357B_SETPANELRELATED 0xE9 165 | 166 | #define HX8357B_MADCTL_MY 0x80 167 | #define HX8357B_MADCTL_MX 0x40 168 | #define HX8357B_MADCTL_MV 0x20 169 | #define HX8357B_MADCTL_ML 0x10 170 | #define HX8357B_MADCTL_RGB 0x00 171 | #define HX8357B_MADCTL_BGR 0x08 172 | #define HX8357B_MADCTL_MH 0x04 173 | -------------------------------------------------------------------------------- /SPFD5408/README.md: -------------------------------------------------------------------------------- 1 | #SPFD5408 Library 2 | Author: Joao Lopes 3 | Versions: 4 | 0.9.0 - Beta 1: First public beta - 18/07/15 5 | 0.9.1 - Beta 2: Now works on Mega boards - 19/07/15 6 | 0.9.2 - Beta 3: Now works no Leornardo too - 29/07/15 7 | 8 | This library is the Adafruit TFT Libraries changed to works in TFT 2.4 shields with the SPFD5408 controller. 9 | Tested on Arduino Uno, Leonardo and Mega. See it on action in: https://www.youtube.com/watch?v=Q8WvEjXvAws 10 | 11 | It is based in the last version of Adafruit, inclusive with buttons features. 12 | 13 | The TFT 2.4 is cheap TFT, that generally is from China, 14 | without documentation or libraries for it. 15 | 16 | When we try to use the TFT 2.4 with SPFD5408 controller in sketches with Adafruit TFT libraries, 17 | several things can happen : 18 | 19 | - White Screen 20 | - All screen with noise 21 | - Touch not works or is inverted (coordinate Y) 22 | - The colors are inverted 23 | - And other things 24 | 25 | After trying for several days trying the solutions I found on the web, and none works 100%. 26 | So I decided to do an library specific to this controller. 27 | 28 | I changed the Adafruit libraries for TFT: GFX , TFTLCD and TouchScreen. 29 | I join all in this one library, the library SPFD5408, to avoid problems with duplicate libraries 30 | and enables also have the original library Adafruit ready for use in other projects with another TFT hardware. 31 | 32 | 33 | DISCLAIMER: 34 | 35 | This Library is NOT provided by AdaFruit and they have not 36 | endorsed it. This library is just a lot of modifications in the Adafruit Library, 37 | to works in TFT with SPFD5408 controller (cheap shields) 38 | 39 | ATTENTION: 40 | 41 | Due to variations in Chinese shields with some controller, 42 | there is no guarantee that will work for everyone. 43 | 44 | I test with success in my www.mcufriend.com TFTs, plugged in Uno, Leonardo and Mega Arduino boards. 45 | 46 | I’ll try a more suppliers in aliexpress to test more variations. 47 | 48 | Please let me know if this happens. 49 | 50 | Also please send me feedback, problems or suggestions. 51 | 52 | INSTALATION: 53 | 54 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder to SPFD5408. 55 | 56 | Place the SPFD5408 library folder your /libraries/ folder. 57 | You may need to create the libraries subfolder if its your first library. 58 | 59 | Or more simple, you access the Arduinos’s IDE menu : sketch/add library 60 | 61 | Restart the IDE 62 | 63 | If you download any code that uses Adafruit Libraries, please verify it: 64 | 65 | —- Pinout XM XP, must be: 66 | 67 | #define YP A1 // must be an analog pin, use "An" notation! 68 | #define XM A2 // must be an analog pin, use "An" notation! 69 | #define YM 7 // can be a digital pin 70 | #define XP 6 // can be a digital pin 71 | 72 | (please verify it, if only a blank screen or noise is showed or touch doesnt works) 73 | 74 | —- readID: comment the original blok: 75 | 76 | // uint16_t identifier = tft.readID(); 77 | // 78 | // if(identifier == 0x9325) { 79 | // Serial.println(F("Found ILI9325 LCD driver")); 80 | // } else if(identifier == 0x9328) { 81 | // Serial.println(F("Found ILI9328 LCD driver")); 82 | // } else if(identifier == 0x7575) { 83 | // Serial.println(F("Found HX8347G LCD driver")); 84 | // } else if(identifier == 0x9341) { 85 | // Serial.println(F("Found ILI9341 LCD driver")); 86 | // } else if(identifier == 0x8357) { 87 | // Serial.println(F("Found HX8357D LCD driver")); 88 | // } else { 89 | // Serial.print(F("Unknown LCD driver chip: ")); 90 | // Serial.println(identifier, HEX); 91 | // Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 92 | // Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 93 | // Serial.println(F("should appear in the library header (Adafruit_TFT.h).")); 94 | // Serial.println(F("If using the breakout board, it should NOT be #defined!")); 95 | // Serial.println(F("Also if using the breakout, double-check that all wiring")); 96 | // Serial.println(F("matches the tutorial.")); 97 | // return; 98 | // } 99 | // 100 | // tft.begin(identifier); 101 | 102 | —- tft.begin: insert after block commented 103 | 104 | tft.begin(0x9341); // SDFP5408 105 | 106 | —- tft.rotation: Need for Mega (else screen is showed mirrored) 107 | 108 | tft.setRotation(0); // Need for the Mega, please changed for your choice of rotation initial 109 | 110 | —- Calibrate before run 111 | 112 | Exists one sketch written for my, to help in calibration of touch 113 | See it in examples folder 114 | Run it and change this parameters: 115 | 116 | #define TS_MINX 150 117 | #define TS_MINY 120 118 | #define TS_MAXX 920 119 | #define TS_MAXY 940 120 | 121 | (please verify it if the point of touch is not accurate) 122 | 123 | ———————— 124 | 125 | All changes in Adafruit code is marked with: 126 | 127 | 128 | // ### SPFD5408 change -- Begin 129 | 130 | (change) 131 | 132 | // ### SPFD5408 change -- End 133 | 134 | This is useful if You see the points that be workeds for any touble 135 | 136 | —————— 137 | 138 | Examples: 139 | 140 | adafruit_originals 141 | 142 | From Adafruit Libraries — Not works with the SPFD5408 143 | 144 | 145 | spfd5408_calibrate 146 | 147 | Help the calibration of touch (resistive) 148 | 149 | spfd5408_tftpaint 150 | 151 | example of Adafruit changed to work with the SPFD5408 152 | 153 | spfd5408_graphictest 154 | 155 | example of Adafruit changed to work with the SPFD5408 156 | 157 | spfd5408_rotationtest 158 | 159 | example of Adafruit changed to work with the SPFD5408 160 | 161 | Acknowledgements: 162 | 163 | - First to Adafruit for excellent library 164 | - To Andrologiciels blog (https://andrologiciels.wordpress.com/arduino/lcd/tft-display/) 165 | As the first library could to show the graphics (before only blank or noise screen) 166 | and be the basis for any adjustments that I made in this library 167 | - To Berni_ (https://forum.arduino.cc/index.php?topic=223769.15) 168 | By the logic of TFT calibration for be the basis for my program 169 | 170 | 171 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/tftpaint_shield/tftpaint_shield.ino: -------------------------------------------------------------------------------- 1 | // Paint example specifically for the TFTLCD Arduino shield. 2 | // If using the breakout board, use the tftpaint.pde sketch instead! 3 | 4 | #include // Core graphics library 5 | #include // Hardware-specific library 6 | #include 7 | 8 | #if defined(__SAM3X8E__) 9 | #undef __FlashStringHelper::F(string_literal) 10 | #define F(string_literal) string_literal 11 | #endif 12 | 13 | #ifndef USE_ADAFRUIT_SHIELD_PINOUT 14 | #error "This sketch is intended for use with the TFT LCD Shield. Make sure that USE_ADAFRUIT_SHIELD_PINOUT is #defined in the Adafruit_TFTLCD.h library file." 15 | #endif 16 | 17 | // These are the pins for the shield! 18 | #define YP A1 // must be an analog pin, use "An" notation! 19 | #define XM A2 // must be an analog pin, use "An" notation! 20 | #define YM 7 // can be a digital pin 21 | #define XP 6 // can be a digital pin 22 | 23 | #ifdef __SAM3X8E__ 24 | #define TS_MINX 125 25 | #define TS_MINY 170 26 | #define TS_MAXX 880 27 | #define TS_MAXY 940 28 | #else 29 | #define TS_MINX 150 30 | #define TS_MINY 120 31 | #define TS_MAXX 920 32 | #define TS_MAXY 940 33 | #endif 34 | 35 | // For better pressure precision, we need to know the resistance 36 | // between X+ and X- Use any multimeter to read it 37 | // For the one we're using, its 300 ohms across the X plate 38 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 39 | 40 | #define LCD_CS A3 41 | #define LCD_CD A2 42 | #define LCD_WR A1 43 | #define LCD_RD A0 44 | 45 | // Assign human-readable names to some common 16-bit color values: 46 | #define BLACK 0x0000 47 | #define BLUE 0x001F 48 | #define RED 0xF800 49 | #define GREEN 0x07E0 50 | #define CYAN 0x07FF 51 | #define MAGENTA 0xF81F 52 | #define YELLOW 0xFFE0 53 | #define WHITE 0xFFFF 54 | 55 | 56 | Adafruit_TFTLCD tft; 57 | 58 | #define BOXSIZE 40 59 | #define PENRADIUS 4 60 | int oldcolor, currentcolor; 61 | 62 | void setup(void) { 63 | Serial.begin(9600); 64 | Serial.println(F("Paint!")); 65 | 66 | tft.reset(); 67 | 68 | uint16_t identifier = tft.readID(); 69 | 70 | if(identifier == 0x9325) { 71 | Serial.println(F("Found ILI9325 LCD driver")); 72 | } else if(identifier == 0x9328) { 73 | Serial.println(F("Found ILI9328 LCD driver")); 74 | } else if(identifier == 0x7575) { 75 | Serial.println(F("Found HX8347G LCD driver")); 76 | } else { 77 | Serial.print(F("Unknown LCD driver chip: ")); 78 | Serial.println(identifier, HEX); 79 | return; 80 | } 81 | 82 | tft.begin(identifier); 83 | 84 | tft.fillScreen(BLACK); 85 | 86 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 87 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 88 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 89 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 90 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 91 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 92 | // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE); 93 | 94 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 95 | currentcolor = RED; 96 | 97 | pinMode(13, OUTPUT); 98 | } 99 | 100 | #define MINPRESSURE 10 101 | #define MAXPRESSURE 1000 102 | 103 | void loop() 104 | { 105 | digitalWrite(13, HIGH); 106 | TSPoint p = ts.getPoint(); 107 | digitalWrite(13, LOW); 108 | 109 | // if sharing pins, you'll need to fix the directions of the touchscreen pins 110 | //pinMode(XP, OUTPUT); 111 | pinMode(XM, OUTPUT); 112 | pinMode(YP, OUTPUT); 113 | //pinMode(YM, OUTPUT); 114 | 115 | // we have some minimum pressure we consider 'valid' 116 | // pressure of 0 means no pressing! 117 | 118 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { 119 | /* 120 | Serial.print("X = "); Serial.print(p.x); 121 | Serial.print("\tY = "); Serial.print(p.y); 122 | Serial.print("\tPressure = "); Serial.println(p.z); 123 | */ 124 | 125 | if (p.y < (TS_MINY-5)) { 126 | Serial.println("erase"); 127 | // press the bottom of the screen to erase 128 | tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK); 129 | } 130 | // scale from 0->1023 to tft.width 131 | p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); 132 | p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0); 133 | /* 134 | Serial.print("("); Serial.print(p.x); 135 | Serial.print(", "); Serial.print(p.y); 136 | Serial.println(")"); 137 | */ 138 | if (p.y < BOXSIZE) { 139 | oldcolor = currentcolor; 140 | 141 | if (p.x < BOXSIZE) { 142 | currentcolor = RED; 143 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 144 | } else if (p.x < BOXSIZE*2) { 145 | currentcolor = YELLOW; 146 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); 147 | } else if (p.x < BOXSIZE*3) { 148 | currentcolor = GREEN; 149 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE); 150 | } else if (p.x < BOXSIZE*4) { 151 | currentcolor = CYAN; 152 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE); 153 | } else if (p.x < BOXSIZE*5) { 154 | currentcolor = BLUE; 155 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE); 156 | } else if (p.x < BOXSIZE*6) { 157 | currentcolor = MAGENTA; 158 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE); 159 | } 160 | 161 | if (oldcolor != currentcolor) { 162 | if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 163 | if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 164 | if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 165 | if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 166 | if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 167 | if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 168 | } 169 | } 170 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 171 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 172 | } 173 | } 174 | } 175 | 176 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/tftpaint_shield/tftpaint_shield.pde: -------------------------------------------------------------------------------- 1 | // Paint example specifically for the TFTLCD Arduino shield. 2 | // If using the breakout board, use the tftpaint.pde sketch instead! 3 | 4 | #include // Core graphics library 5 | #include // Hardware-specific library 6 | #include 7 | 8 | #ifndef USE_ADAFRUIT_SHIELD_PINOUT 9 | #error "This sketch is intended for use with the TFT LCD Shield. Make sure that USE_ADAFRUIT_SHIELD_PINOUT is #defined in the Adafruit_TFTLCD.h library file." 10 | #endif 11 | 12 | // These are the pins for the shield! 13 | #define YP A1 // must be an analog pin, use "An" notation! 14 | #define XM A2 // must be an analog pin, use "An" notation! 15 | #define YM 7 // can be a digital pin 16 | #define XP 6 // can be a digital pin 17 | 18 | #define TS_MINX 150 19 | #define TS_MINY 120 20 | #define TS_MAXX 920 21 | #define TS_MAXY 940 22 | 23 | // For better pressure precision, we need to know the resistance 24 | // between X+ and X- Use any multimeter to read it 25 | // For the one we're using, its 300 ohms across the X plate 26 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 27 | 28 | #define LCD_CS A3 29 | #define LCD_CD A2 30 | #define LCD_WR A1 31 | #define LCD_RD A0 32 | 33 | // Assign human-readable names to some common 16-bit color values: 34 | #define BLACK 0x0000 35 | #define BLUE 0x001F 36 | #define RED 0xF800 37 | #define GREEN 0x07E0 38 | #define CYAN 0x07FF 39 | #define MAGENTA 0xF81F 40 | #define YELLOW 0xFFE0 41 | #define WHITE 0xFFFF 42 | 43 | 44 | Adafruit_TFTLCD tft; 45 | 46 | #define BOXSIZE 40 47 | #define PENRADIUS 4 48 | int oldcolor, currentcolor; 49 | 50 | void setup(void) { 51 | Serial.begin(9600); 52 | progmemPrintln(PSTR("Paint!")); 53 | 54 | tft.reset(); 55 | 56 | uint16_t identifier = tft.readID(); 57 | 58 | if(identifier == 0x9325) { 59 | progmemPrintln(PSTR("Found ILI9325 LCD driver")); 60 | } else if(identifier == 0x9328) { 61 | progmemPrintln(PSTR("Found ILI9328 LCD driver")); 62 | } else if(identifier == 0x7575) { 63 | progmemPrintln(PSTR("Found HX8347G LCD driver")); 64 | } else { 65 | progmemPrint(PSTR("Unknown LCD driver chip: ")); 66 | Serial.println(identifier, HEX); 67 | return; 68 | } 69 | 70 | tft.begin(identifier); 71 | 72 | tft.fillScreen(BLACK); 73 | 74 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 75 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 76 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 77 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 78 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 79 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 80 | // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE); 81 | 82 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 83 | currentcolor = RED; 84 | 85 | pinMode(13, OUTPUT); 86 | } 87 | 88 | #define MINPRESSURE 10 89 | #define MAXPRESSURE 1000 90 | 91 | void loop() 92 | { 93 | digitalWrite(13, HIGH); 94 | Point p = ts.getPoint(); 95 | digitalWrite(13, LOW); 96 | 97 | // if sharing pins, you'll need to fix the directions of the touchscreen pins 98 | //pinMode(XP, OUTPUT); 99 | pinMode(XM, OUTPUT); 100 | pinMode(YP, OUTPUT); 101 | //pinMode(YM, OUTPUT); 102 | 103 | // we have some minimum pressure we consider 'valid' 104 | // pressure of 0 means no pressing! 105 | 106 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { 107 | /* 108 | Serial.print("X = "); Serial.print(p.x); 109 | Serial.print("\tY = "); Serial.print(p.y); 110 | Serial.print("\tPressure = "); Serial.println(p.z); 111 | */ 112 | 113 | if (p.y < (TS_MINY-5)) { 114 | Serial.println("erase"); 115 | // press the bottom of the screen to erase 116 | tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK); 117 | } 118 | // scale from 0->1023 to tft.width 119 | p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); 120 | p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0); 121 | /* 122 | Serial.print("("); Serial.print(p.x); 123 | Serial.print(", "); Serial.print(p.y); 124 | Serial.println(")"); 125 | */ 126 | if (p.y < BOXSIZE) { 127 | oldcolor = currentcolor; 128 | 129 | if (p.x < BOXSIZE) { 130 | currentcolor = RED; 131 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 132 | } else if (p.x < BOXSIZE*2) { 133 | currentcolor = YELLOW; 134 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); 135 | } else if (p.x < BOXSIZE*3) { 136 | currentcolor = GREEN; 137 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE); 138 | } else if (p.x < BOXSIZE*4) { 139 | currentcolor = CYAN; 140 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE); 141 | } else if (p.x < BOXSIZE*5) { 142 | currentcolor = BLUE; 143 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE); 144 | } else if (p.x < BOXSIZE*6) { 145 | currentcolor = MAGENTA; 146 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE); 147 | } 148 | 149 | if (oldcolor != currentcolor) { 150 | if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 151 | if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 152 | if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 153 | if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 154 | if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 155 | if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 156 | } 157 | } 158 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 159 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 160 | } 161 | } 162 | } 163 | 164 | // Copy string from flash to serial port 165 | // Source string MUST be inside a PSTR() declaration! 166 | void progmemPrint(const char *str) { 167 | char c; 168 | while(c = pgm_read_byte(str++)) Serial.print(c); 169 | } 170 | 171 | // Same as above, with trailing newline 172 | void progmemPrintln(const char *str) { 173 | progmemPrint(str); 174 | Serial.println(); 175 | } 176 | 177 | -------------------------------------------------------------------------------- /SPFD5408/SPFD5408_TouchScreen.cpp: -------------------------------------------------------------------------------- 1 | // Touch screen library with X Y and Z (pressure) readings as well 2 | // as oversampling to avoid 'bouncing' 3 | // (c) ladyada / adafruit 4 | // Code under MIT License 5 | 6 | #include "pins_arduino.h" 7 | #include "wiring_private.h" 8 | #ifdef __AVR 9 | #include 10 | #elif defined(ESP8266) 11 | #include 12 | #endif 13 | #include "SPFD5408_TouchScreen.h" 14 | 15 | // increase or decrease the touchscreen oversampling. This is a little different than you make think: 16 | // 1 is no oversampling, whatever data we get is immediately returned 17 | // 2 is double-sampling and we only return valid data if both points are the same 18 | // 3+ uses insert sort to get the median value. 19 | // We found 2 is precise yet not too slow so we suggest sticking with it! 20 | 21 | #define NUMSAMPLES 2 22 | 23 | TSPoint::TSPoint(void) { 24 | x = y = 0; 25 | } 26 | 27 | TSPoint::TSPoint(int16_t x0, int16_t y0, int16_t z0) { 28 | x = x0; 29 | y = y0; 30 | z = z0; 31 | } 32 | 33 | bool TSPoint::operator==(TSPoint p1) { 34 | return ((p1.x == x) && (p1.y == y) && (p1.z == z)); 35 | } 36 | 37 | bool TSPoint::operator!=(TSPoint p1) { 38 | return ((p1.x != x) || (p1.y != y) || (p1.z != z)); 39 | } 40 | 41 | #if (NUMSAMPLES > 2) 42 | static void insert_sort(int array[], uint8_t size) { 43 | uint8_t j; 44 | int save; 45 | 46 | for (int i = 1; i < size; i++) { 47 | save = array[i]; 48 | for (j = i; j >= 1 && save < array[j - 1]; j--) 49 | array[j] = array[j - 1]; 50 | array[j] = save; 51 | } 52 | } 53 | #endif 54 | 55 | TSPoint TouchScreen::getPoint(void) { 56 | int x, y, z; 57 | int samples[NUMSAMPLES]; 58 | uint8_t i, valid; 59 | 60 | 61 | uint8_t xp_port = digitalPinToPort(_xp); 62 | uint8_t yp_port = digitalPinToPort(_yp); 63 | uint8_t xm_port = digitalPinToPort(_xm); 64 | uint8_t ym_port = digitalPinToPort(_ym); 65 | 66 | uint8_t xp_pin = digitalPinToBitMask(_xp); 67 | uint8_t yp_pin = digitalPinToBitMask(_yp); 68 | uint8_t xm_pin = digitalPinToBitMask(_xm); 69 | uint8_t ym_pin = digitalPinToBitMask(_ym); 70 | 71 | 72 | valid = 1; 73 | 74 | pinMode(_yp, INPUT); 75 | pinMode(_ym, INPUT); 76 | 77 | *portOutputRegister(yp_port) &= ~yp_pin; 78 | *portOutputRegister(ym_port) &= ~ym_pin; 79 | //digitalWrite(_yp, LOW); 80 | //digitalWrite(_ym, LOW); 81 | 82 | pinMode(_xp, OUTPUT); 83 | pinMode(_xm, OUTPUT); 84 | //digitalWrite(_xp, HIGH); 85 | //digitalWrite(_xm, LOW); 86 | *portOutputRegister(xp_port) |= xp_pin; 87 | *portOutputRegister(xm_port) &= ~xm_pin; 88 | 89 | for (i=0; i 2 93 | insert_sort(samples, NUMSAMPLES); 94 | #endif 95 | #if NUMSAMPLES == 2 96 | if (samples[0] != samples[1]) { valid = 0; } 97 | #endif 98 | x = (1023-samples[NUMSAMPLES/2]); 99 | 100 | pinMode(_xp, INPUT); 101 | pinMode(_xm, INPUT); 102 | *portOutputRegister(xp_port) &= ~xp_pin; 103 | //digitalWrite(_xp, LOW); 104 | 105 | pinMode(_yp, OUTPUT); 106 | *portOutputRegister(yp_port) |= yp_pin; 107 | //digitalWrite(_yp, HIGH); 108 | pinMode(_ym, OUTPUT); 109 | 110 | for (i=0; i 2 115 | insert_sort(samples, NUMSAMPLES); 116 | #endif 117 | #if NUMSAMPLES == 2 118 | if (samples[0] != samples[1]) { valid = 0; } 119 | #endif 120 | 121 | y = (1023-samples[NUMSAMPLES/2]); 122 | 123 | // Set X+ to ground 124 | pinMode(_xp, OUTPUT); 125 | *portOutputRegister(xp_port) &= ~xp_pin; 126 | //digitalWrite(_xp, LOW); 127 | 128 | // Set Y- to VCC 129 | *portOutputRegister(ym_port) |= ym_pin; 130 | //digitalWrite(_ym, HIGH); 131 | 132 | // Hi-Z X- and Y+ 133 | *portOutputRegister(yp_port) &= ~yp_pin; 134 | //digitalWrite(_yp, LOW); 135 | pinMode(_yp, INPUT); 136 | 137 | int z1 = analogRead(_xm); 138 | int z2 = analogRead(_yp); 139 | 140 | if (_rxplate != 0) { 141 | // now read the x 142 | float rtouch; 143 | rtouch = z2; 144 | rtouch /= z1; 145 | rtouch -= 1; 146 | rtouch *= x; 147 | rtouch *= _rxplate; 148 | rtouch /= 1024; 149 | 150 | z = rtouch; 151 | } else { 152 | z = (1023-(z2-z1)); 153 | } 154 | 155 | if (! valid) { 156 | z = 0; 157 | } 158 | 159 | //return TSPoint(x, y, z); 160 | 161 | // *** SPFD5408 change -- Begin 162 | // SPFD5408 change, because Y coordinate is inverted in this controller 163 | return TSPoint(x, 1023 - y, z); 164 | // -- End 165 | } 166 | 167 | TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym) { 168 | _yp = yp; 169 | _xm = xm; 170 | _ym = ym; 171 | _xp = xp; 172 | _rxplate = 0; 173 | pressureThreshhold = 10; 174 | } 175 | 176 | 177 | TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, 178 | uint16_t rxplate) { 179 | _yp = yp; 180 | _xm = xm; 181 | _ym = ym; 182 | _xp = xp; 183 | _rxplate = rxplate; 184 | 185 | pressureThreshhold = 10; 186 | } 187 | 188 | int TouchScreen::readTouchX(void) { 189 | pinMode(_yp, INPUT); 190 | pinMode(_ym, INPUT); 191 | digitalWrite(_yp, LOW); 192 | digitalWrite(_ym, LOW); 193 | 194 | pinMode(_xp, OUTPUT); 195 | digitalWrite(_xp, HIGH); 196 | pinMode(_xm, OUTPUT); 197 | digitalWrite(_xm, LOW); 198 | 199 | return (1023-analogRead(_yp)); 200 | } 201 | 202 | 203 | int TouchScreen::readTouchY(void) { 204 | pinMode(_xp, INPUT); 205 | pinMode(_xm, INPUT); 206 | digitalWrite(_xp, LOW); 207 | digitalWrite(_xm, LOW); 208 | 209 | pinMode(_yp, OUTPUT); 210 | digitalWrite(_yp, HIGH); 211 | pinMode(_ym, OUTPUT); 212 | digitalWrite(_ym, LOW); 213 | 214 | return (1023-analogRead(_xm)); 215 | } 216 | 217 | 218 | uint16_t TouchScreen::pressure(void) { 219 | // Set X+ to ground 220 | pinMode(_xp, OUTPUT); 221 | digitalWrite(_xp, LOW); 222 | 223 | // Set Y- to VCC 224 | pinMode(_ym, OUTPUT); 225 | digitalWrite(_ym, HIGH); 226 | 227 | // Hi-Z X- and Y+ 228 | digitalWrite(_xm, LOW); 229 | pinMode(_xm, INPUT); 230 | digitalWrite(_yp, LOW); 231 | pinMode(_yp, INPUT); 232 | 233 | int z1 = analogRead(_xm); 234 | int z2 = analogRead(_yp); 235 | 236 | if (_rxplate != 0) { 237 | // now read the x 238 | float rtouch; 239 | rtouch = z2; 240 | rtouch /= z1; 241 | rtouch -= 1; 242 | rtouch *= readTouchX(); 243 | rtouch *= _rxplate; 244 | rtouch /= 1024; 245 | 246 | return rtouch; 247 | } else { 248 | return (1023-(z2-z1)); 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/tftpaint/tftpaint.pde: -------------------------------------------------------------------------------- 1 | // Paint example specifically for the TFTLCD breakout board. 2 | // If using the Arduino shield, use the tftpaint_shield.pde sketch instead! 3 | // DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO 4 | 5 | #include // Core graphics library 6 | #include // Hardware-specific library 7 | #include 8 | 9 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 10 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 11 | // D0 connects to digital pin 8 (Notice these are 12 | // D1 connects to digital pin 9 NOT in order!) 13 | // D2 connects to digital pin 2 14 | // D3 connects to digital pin 3 15 | // D4 connects to digital pin 4 16 | // D5 connects to digital pin 5 17 | // D6 connects to digital pin 6 18 | // D7 connects to digital pin 7 19 | // For the Arduino Mega, use digital pins 22 through 29 20 | // (on the 2-row header at the end of the board). 21 | 22 | #define YP A3 // must be an analog pin, use "An" notation! 23 | #define XM A2 // must be an analog pin, use "An" notation! 24 | #define YM 23 // can be a digital pin (9 uno)(pin 23 Mega) 25 | #define XP 22 // can be a digital pin (8 uno)(pin 22 Mega) 26 | 27 | #define TS_MINX 150 28 | #define TS_MINY 120 29 | #define TS_MAXX 920 30 | #define TS_MAXY 940 31 | 32 | // For better pressure precision, we need to know the resistance 33 | // between X+ and X- Use any multimeter to read it 34 | // For the one we're using, its 300 ohms across the X plate 35 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 36 | 37 | #define LCD_CS A3 38 | #define LCD_CD A2 39 | #define LCD_WR A1 40 | #define LCD_RD A0 41 | // optional 42 | #define LCD_RESET A4 43 | 44 | // Assign human-readable names to some common 16-bit color values: 45 | #define BLACK 0x0000 46 | #define BLUE 0x001F 47 | #define RED 0xF800 48 | #define GREEN 0x07E0 49 | #define CYAN 0x07FF 50 | #define MAGENTA 0xF81F 51 | #define YELLOW 0xFFE0 52 | #define WHITE 0xFFFF 53 | 54 | 55 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 56 | 57 | #define BOXSIZE 40 58 | #define PENRADIUS 3 59 | int oldcolor, currentcolor; 60 | 61 | void setup(void) { 62 | Serial.begin(9600); 63 | progmemPrintln(PSTR("Paint!")); 64 | digitalWrite(35, HIGH); //I use this on mega for LCD Backlight 65 | tft.reset(); 66 | 67 | uint16_t identifier = tft.readID(); 68 | 69 | if(identifier == 0x9325) { 70 | progmemPrintln(PSTR("Found ILI9325 LCD driver")); 71 | } else if(identifier == 0x9328) { 72 | progmemPrintln(PSTR("Found ILI9328 LCD driver")); 73 | } else if(identifier == 0x7575) { 74 | progmemPrintln(PSTR("Found HX8347G LCD driver")); 75 | } else { 76 | progmemPrint(PSTR("Unknown LCD driver chip: ")); 77 | Serial.println(identifier, HEX); 78 | return; 79 | } 80 | 81 | tft.begin(identifier); 82 | 83 | tft.fillScreen(BLACK); 84 | 85 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 86 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 87 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 88 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 89 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 90 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 91 | // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE); 92 | 93 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 94 | currentcolor = RED; 95 | 96 | pinMode(13, OUTPUT); 97 | } 98 | 99 | #define MINPRESSURE 10 100 | #define MAXPRESSURE 1000 101 | 102 | void loop() 103 | { 104 | digitalWrite(13, HIGH); 105 | Point p = ts.getPoint(); 106 | digitalWrite(13, LOW); 107 | 108 | // if sharing pins, you'll need to fix the directions of the touchscreen pins 109 | //pinMode(XP, OUTPUT); 110 | pinMode(XM, OUTPUT); 111 | pinMode(YP, OUTPUT); 112 | //pinMode(YM, OUTPUT); 113 | 114 | // we have some minimum pressure we consider 'valid' 115 | // pressure of 0 means no pressing! 116 | 117 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { 118 | /* 119 | Serial.print("X = "); Serial.print(p.x); 120 | Serial.print("\tY = "); Serial.print(p.y); 121 | Serial.print("\tPressure = "); Serial.println(p.z); 122 | */ 123 | 124 | if (p.y < (TS_MINY-5)) { 125 | Serial.println("erase"); 126 | // press the bottom of the screen to erase 127 | tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK); 128 | } 129 | // scale from 0->1023 to tft.width 130 | p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); 131 | p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0); 132 | /* 133 | Serial.print("("); Serial.print(p.x); 134 | Serial.print(", "); Serial.print(p.y); 135 | Serial.println(")"); 136 | */ 137 | if (p.y < BOXSIZE) { 138 | oldcolor = currentcolor; 139 | 140 | if (p.x < BOXSIZE) { 141 | currentcolor = RED; 142 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 143 | } else if (p.x < BOXSIZE*2) { 144 | currentcolor = YELLOW; 145 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); 146 | } else if (p.x < BOXSIZE*3) { 147 | currentcolor = GREEN; 148 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE); 149 | } else if (p.x < BOXSIZE*4) { 150 | currentcolor = CYAN; 151 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE); 152 | } else if (p.x < BOXSIZE*5) { 153 | currentcolor = BLUE; 154 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE); 155 | } else if (p.x < BOXSIZE*6) { 156 | currentcolor = MAGENTA; 157 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE); 158 | } 159 | 160 | if (oldcolor != currentcolor) { 161 | if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 162 | if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 163 | if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 164 | if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 165 | if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 166 | if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 167 | } 168 | } 169 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 170 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 171 | } 172 | } 173 | } 174 | 175 | // Copy string from flash to serial port 176 | // Source string MUST be inside a PSTR() declaration! 177 | void progmemPrint(const char *str) { 178 | char c; 179 | while(c = pgm_read_byte(str++)) Serial.print(c); 180 | } 181 | 182 | // Same as above, with trailing newline 183 | void progmemPrintln(const char *str) { 184 | progmemPrint(str); 185 | Serial.println(); 186 | } 187 | 188 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/rotationtest/rotationtest.pde: -------------------------------------------------------------------------------- 1 | // IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY 2 | // CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. 3 | // SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. 4 | 5 | #include // Core graphics library 6 | #include // Hardware-specific library 7 | 8 | // The control pins for the LCD can be assigned to any digital or 9 | // analog pins...but we'll use the analog pins as this allows us to 10 | // double up the pins with the touch screen (see the TFT paint example). 11 | #define LCD_CS A3 // Chip Select goes to Analog 3 12 | #define LCD_CD A2 // Command/Data goes to Analog 2 13 | #define LCD_WR A1 // LCD Write goes to Analog 1 14 | #define LCD_RD A0 // LCD Read goes to Analog 0 15 | 16 | #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin 17 | 18 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 19 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 20 | // D0 connects to digital pin 8 (Notice these are 21 | // D1 connects to digital pin 9 NOT in order!) 22 | // D2 connects to digital pin 2 23 | // D3 connects to digital pin 3 24 | // D4 connects to digital pin 4 25 | // D5 connects to digital pin 5 26 | // D6 connects to digital pin 6 27 | // D7 connects to digital pin 7 28 | // For the Arduino Mega, use digital pins 22 through 29 29 | // (on the 2-row header at the end of the board). 30 | 31 | // Assign human-readable names to some common 16-bit color values: 32 | #define BLACK 0x0000 33 | #define BLUE 0x001F 34 | #define RED 0xF800 35 | #define GREEN 0x07E0 36 | #define CYAN 0x07FF 37 | #define MAGENTA 0xF81F 38 | #define YELLOW 0xFFE0 39 | #define WHITE 0xFFFF 40 | 41 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 42 | // If using the shield, all control and data lines are fixed, and 43 | // a simpler declaration can optionally be used: 44 | // Adafruit_TFTLCD tft; 45 | 46 | void setup(void) { 47 | Serial.begin(9600); 48 | digitalWrite(35, HIGH); //I use this on mega for LCD Backlight 49 | progmemPrintln(PSTR("TFT LCD test")); 50 | 51 | #ifdef USE_ADAFRUIT_SHIELD_PINOUT 52 | progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout")); 53 | #else 54 | progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout")); 55 | #endif 56 | 57 | tft.reset(); 58 | 59 | uint16_t identifier = tft.readID(); 60 | 61 | if(identifier == 0x9325) { 62 | progmemPrintln(PSTR("Found ILI9325 LCD driver")); 63 | } else if(identifier == 0x9328) { 64 | progmemPrintln(PSTR("Found ILI9328 LCD driver")); 65 | } else if(identifier == 0x7575) { 66 | progmemPrintln(PSTR("Found HX8347G LCD driver")); 67 | } else { 68 | progmemPrint(PSTR("Unknown LCD driver chip: ")); 69 | Serial.println(identifier, HEX); 70 | progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 71 | progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 72 | progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h).")); 73 | progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!")); 74 | progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring")); 75 | progmemPrintln(PSTR("matches the tutorial.")); 76 | return; 77 | } 78 | 79 | tft.begin(identifier); 80 | 81 | tft.fillScreen(BLACK); 82 | 83 | progmemPrintln(PSTR("This is a test of the rotation capabilities of the TFT library!")); 84 | progmemPrintln(PSTR("Press (or type a character) to advance")); 85 | } 86 | 87 | void loop(void) { 88 | rotatePixel(); 89 | rotateLine(); 90 | rotateFastline(); 91 | rotateDrawrect(); 92 | rotateFillrect(); 93 | rotateDrawcircle(); 94 | rotateFillcircle(); 95 | rotateText(); 96 | } 97 | 98 | void rotateText() { 99 | for (uint8_t i=0; i<4; i++) { 100 | tft.fillScreen(BLACK); 101 | Serial.println(tft.getRotation(), DEC); 102 | 103 | tft.setCursor(0, 30); 104 | tft.setTextColor(RED); 105 | tft.setTextSize(1); 106 | tft.println("Hello World!"); 107 | tft.setTextColor(YELLOW); 108 | tft.setTextSize(2); 109 | tft.println("Hello World!"); 110 | tft.setTextColor(GREEN); 111 | tft.setTextSize(3); 112 | tft.println("Hello World!"); 113 | tft.setTextColor(BLUE); 114 | tft.setTextSize(4); 115 | tft.print(1234.567); 116 | 117 | while (!Serial.available()); 118 | Serial.read(); Serial.read(); Serial.read(); 119 | 120 | tft.setRotation(tft.getRotation()+1); 121 | } 122 | } 123 | 124 | void rotateFillcircle(void) { 125 | for (uint8_t i=0; i<4; i++) { 126 | tft.fillScreen(BLACK); 127 | Serial.println(tft.getRotation(), DEC); 128 | 129 | tft.fillCircle(10, 30, 10, YELLOW); 130 | 131 | while (!Serial.available()); 132 | Serial.read(); Serial.read(); Serial.read(); 133 | 134 | tft.setRotation(tft.getRotation()+1); 135 | } 136 | } 137 | 138 | void rotateDrawcircle(void) { 139 | for (uint8_t i=0; i<4; i++) { 140 | tft.fillScreen(BLACK); 141 | Serial.println(tft.getRotation(), DEC); 142 | 143 | tft.drawCircle(10, 30, 10, YELLOW); 144 | 145 | while (!Serial.available()); 146 | Serial.read(); Serial.read(); Serial.read(); 147 | 148 | tft.setRotation(tft.getRotation()+1); 149 | } 150 | } 151 | 152 | void rotateFillrect(void) { 153 | for (uint8_t i=0; i<4; i++) { 154 | tft.fillScreen(BLACK); 155 | Serial.println(tft.getRotation(), DEC); 156 | 157 | tft.fillRect(10, 20, 10, 20, GREEN); 158 | 159 | while (!Serial.available()); 160 | Serial.read(); Serial.read(); Serial.read(); 161 | 162 | tft.setRotation(tft.getRotation()+1); 163 | } 164 | } 165 | 166 | void rotateDrawrect(void) { 167 | for (uint8_t i=0; i<4; i++) { 168 | tft.fillScreen(BLACK); 169 | Serial.println(tft.getRotation(), DEC); 170 | 171 | tft.drawRect(10, 20, 10, 20, GREEN); 172 | 173 | while (!Serial.available()); 174 | Serial.read(); Serial.read(); Serial.read(); 175 | 176 | tft.setRotation(tft.getRotation()+1); 177 | } 178 | } 179 | 180 | void rotateFastline(void) { 181 | for (uint8_t i=0; i<4; i++) { 182 | tft.fillScreen(BLACK); 183 | Serial.println(tft.getRotation(), DEC); 184 | 185 | tft.drawFastHLine(0, 20, tft.width(), RED); 186 | tft.drawFastVLine(20, 0, tft.height(), BLUE); 187 | 188 | while (!Serial.available()); 189 | Serial.read(); Serial.read(); Serial.read(); 190 | 191 | tft.setRotation(tft.getRotation()+1); 192 | } 193 | } 194 | 195 | void rotateLine(void) { 196 | for (uint8_t i=0; i<4; i++) { 197 | tft.fillScreen(BLACK); 198 | Serial.println(tft.getRotation(), DEC); 199 | 200 | tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, RED); 201 | while (!Serial.available()); 202 | Serial.read(); Serial.read(); Serial.read(); 203 | 204 | tft.setRotation(tft.getRotation()+1); 205 | } 206 | } 207 | 208 | void rotatePixel(void) { 209 | for (uint8_t i=0; i<4; i++) { 210 | tft.fillScreen(BLACK); 211 | Serial.println(tft.getRotation(), DEC); 212 | 213 | tft.drawPixel(10,20, RED); 214 | while (!Serial.available()); 215 | Serial.read(); Serial.read(); Serial.read(); 216 | 217 | tft.setRotation(tft.getRotation()+1); 218 | } 219 | } 220 | 221 | // Copy string from flash to serial port 222 | // Source string MUST be inside a PSTR() declaration! 223 | void progmemPrint(const char *str) { 224 | char c; 225 | while(c = pgm_read_byte(str++)) Serial.print(c); 226 | } 227 | 228 | // Same as above, with trailing newline 229 | void progmemPrintln(const char *str) { 230 | progmemPrint(str); 231 | Serial.println(); 232 | } 233 | 234 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/tftpaint/tftpaint.ino: -------------------------------------------------------------------------------- 1 | // Paint example specifically for the TFTLCD breakout board. 2 | // If using the Arduino shield, use the tftpaint_shield.pde sketch instead! 3 | // DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO 4 | 5 | #include // Core graphics library 6 | #include // Hardware-specific library 7 | #include 8 | 9 | #if defined(__SAM3X8E__) 10 | #undef __FlashStringHelper::F(string_literal) 11 | #define F(string_literal) string_literal 12 | #endif 13 | 14 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 15 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 16 | // D0 connects to digital pin 8 (Notice these are 17 | // D1 connects to digital pin 9 NOT in order!) 18 | // D2 connects to digital pin 2 19 | // D3 connects to digital pin 3 20 | // D4 connects to digital pin 4 21 | // D5 connects to digital pin 5 22 | // D6 connects to digital pin 6 23 | // D7 connects to digital pin 7 24 | 25 | // For the Arduino Mega, use digital pins 22 through 29 26 | // (on the 2-row header at the end of the board). 27 | // D0 connects to digital pin 22 28 | // D1 connects to digital pin 23 29 | // D2 connects to digital pin 24 30 | // D3 connects to digital pin 25 31 | // D4 connects to digital pin 26 32 | // D5 connects to digital pin 27 33 | // D6 connects to digital pin 28 34 | // D7 connects to digital pin 29 35 | 36 | // For the Arduino Due, use digital pins 33 through 40 37 | // (on the 2-row header at the end of the board). 38 | // D0 connects to digital pin 33 39 | // D1 connects to digital pin 34 40 | // D2 connects to digital pin 35 41 | // D3 connects to digital pin 36 42 | // D4 connects to digital pin 37 43 | // D5 connects to digital pin 38 44 | // D6 connects to digital pin 39 45 | // D7 connects to digital pin 40 46 | 47 | #define YP A3 // must be an analog pin, use "An" notation! 48 | #define XM A2 // must be an analog pin, use "An" notation! 49 | #define YM 9 // can be a digital pin 50 | #define XP 8 // can be a digital pin 51 | 52 | #define TS_MINX 150 53 | #define TS_MINY 120 54 | #define TS_MAXX 920 55 | #define TS_MAXY 940 56 | 57 | // For better pressure precision, we need to know the resistance 58 | // between X+ and X- Use any multimeter to read it 59 | // For the one we're using, its 300 ohms across the X plate 60 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 61 | 62 | #define LCD_CS A3 63 | #define LCD_CD A2 64 | #define LCD_WR A1 65 | #define LCD_RD A0 66 | // optional 67 | #define LCD_RESET A4 68 | 69 | // Assign human-readable names to some common 16-bit color values: 70 | #define BLACK 0x0000 71 | #define BLUE 0x001F 72 | #define RED 0xF800 73 | #define GREEN 0x07E0 74 | #define CYAN 0x07FF 75 | #define MAGENTA 0xF81F 76 | #define YELLOW 0xFFE0 77 | #define WHITE 0xFFFF 78 | 79 | 80 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 81 | 82 | #define BOXSIZE 40 83 | #define PENRADIUS 3 84 | int oldcolor, currentcolor; 85 | 86 | void setup(void) { 87 | Serial.begin(9600); 88 | Serial.println(F("Paint!")); 89 | 90 | tft.reset(); 91 | 92 | uint16_t identifier = tft.readID(); 93 | 94 | if(identifier == 0x9325) { 95 | Serial.println(F("Found ILI9325 LCD driver")); 96 | } else if(identifier == 0x9328) { 97 | Serial.println(F("Found ILI9328 LCD driver")); 98 | } else if(identifier == 0x7575) { 99 | Serial.println(F("Found HX8347G LCD driver")); 100 | } else if(identifier == 0x9341) { 101 | Serial.println(F("Found ILI9341 LCD driver")); 102 | } else if(identifier == 0x8357) { 103 | Serial.println(F("Found HX8357D LCD driver")); 104 | } else { 105 | Serial.print(F("Unknown LCD driver chip: ")); 106 | Serial.println(identifier, HEX); 107 | Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 108 | Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 109 | Serial.println(F("should appear in the library header (Adafruit_TFT.h).")); 110 | Serial.println(F("If using the breakout board, it should NOT be #defined!")); 111 | Serial.println(F("Also if using the breakout, double-check that all wiring")); 112 | Serial.println(F("matches the tutorial.")); 113 | return; 114 | } 115 | 116 | tft.begin(identifier); 117 | 118 | tft.fillScreen(BLACK); 119 | 120 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 121 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 122 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 123 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 124 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 125 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 126 | // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE); 127 | 128 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 129 | currentcolor = RED; 130 | 131 | pinMode(13, OUTPUT); 132 | } 133 | 134 | #define MINPRESSURE 10 135 | #define MAXPRESSURE 1000 136 | 137 | void loop() 138 | { 139 | digitalWrite(13, HIGH); 140 | TSPoint p = ts.getPoint(); 141 | digitalWrite(13, LOW); 142 | 143 | // if sharing pins, you'll need to fix the directions of the touchscreen pins 144 | //pinMode(XP, OUTPUT); 145 | pinMode(XM, OUTPUT); 146 | pinMode(YP, OUTPUT); 147 | //pinMode(YM, OUTPUT); 148 | 149 | // we have some minimum pressure we consider 'valid' 150 | // pressure of 0 means no pressing! 151 | 152 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { 153 | /* 154 | Serial.print("X = "); Serial.print(p.x); 155 | Serial.print("\tY = "); Serial.print(p.y); 156 | Serial.print("\tPressure = "); Serial.println(p.z); 157 | */ 158 | 159 | if (p.y < (TS_MINY-5)) { 160 | Serial.println("erase"); 161 | // press the bottom of the screen to erase 162 | tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK); 163 | } 164 | // scale from 0->1023 to tft.width 165 | p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); 166 | p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0); 167 | /* 168 | Serial.print("("); Serial.print(p.x); 169 | Serial.print(", "); Serial.print(p.y); 170 | Serial.println(")"); 171 | */ 172 | if (p.y < BOXSIZE) { 173 | oldcolor = currentcolor; 174 | 175 | if (p.x < BOXSIZE) { 176 | currentcolor = RED; 177 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 178 | } else if (p.x < BOXSIZE*2) { 179 | currentcolor = YELLOW; 180 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); 181 | } else if (p.x < BOXSIZE*3) { 182 | currentcolor = GREEN; 183 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE); 184 | } else if (p.x < BOXSIZE*4) { 185 | currentcolor = CYAN; 186 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE); 187 | } else if (p.x < BOXSIZE*5) { 188 | currentcolor = BLUE; 189 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE); 190 | } else if (p.x < BOXSIZE*6) { 191 | currentcolor = MAGENTA; 192 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE); 193 | } 194 | 195 | if (oldcolor != currentcolor) { 196 | if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 197 | if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 198 | if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 199 | if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 200 | if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 201 | if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 202 | } 203 | } 204 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 205 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 206 | } 207 | } 208 | } 209 | 210 | -------------------------------------------------------------------------------- /SPFD5408/examples/spfd5408_rotationtest/spfd5408_rotationtest.ino: -------------------------------------------------------------------------------- 1 | // IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY 2 | // CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. 3 | // SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. 4 | 5 | // Modified for SPFD5408 Library by Joao Lopes 6 | // and touch instead serial !!!! 7 | // Too much modifications, so not: begins e ends 8 | // Version 0.9.2 - Rotation for Mega and screen initial 9 | 10 | #include // Core graphics library 11 | #include // Hardware-specific library 12 | #include // Touch library 13 | 14 | // The control pins for the LCD can be assigned to any digital or 15 | // analog pins...but we'll use the analog pins as this allows us to 16 | // double up the pins with the touch screen (see the TFT paint example). 17 | #define LCD_CS A3 // Chip Select goes to Analog 3 18 | #define LCD_CD A2 // Command/Data goes to Analog 2 19 | #define LCD_WR A1 // LCD Write goes to Analog 1 20 | #define LCD_RD A0 // LCD Read goes to Analog 0 21 | 22 | #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin 23 | 24 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 25 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 26 | // D0 connects to digital pin 8 (Notice these are 27 | // D1 connects to digital pin 9 NOT in order!) 28 | // D2 connects to digital pin 2 29 | // D3 connects to digital pin 3 30 | // D4 connects to digital pin 4 31 | // D5 connects to digital pin 5 32 | // D6 connects to digital pin 6 33 | // D7 connects to digital pin 7 34 | // For the Arduino Mega, use digital pins 22 through 29 35 | // (on the 2-row header at the end of the board). 36 | 37 | // Assign human-readable names to some common 16-bit color values: 38 | #define BLACK 0x0000 39 | #define BLUE 0x001F 40 | #define RED 0xF800 41 | #define GREEN 0x07E0 42 | #define CYAN 0x07FF 43 | #define MAGENTA 0xF81F 44 | #define YELLOW 0xFFE0 45 | #define WHITE 0xFFFF 46 | 47 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 48 | // If using the shield, all control and data lines are fixed, and 49 | // a simpler declaration can optionally be used: 50 | // Adafruit_TFTLCD tft; 51 | 52 | // Calibrates value 53 | 54 | #define SENSIBILITY 300 55 | #define MINPRESSURE 10 56 | #define MAXPRESSURE 1000 57 | 58 | //These are the pins for the shield! 59 | #define YP A1 60 | #define XM A2 61 | #define YM 7 62 | #define XP 6 63 | 64 | // Calibrate values 65 | 66 | #define TS_MINX 125 67 | #define TS_MINY 85 68 | #define TS_MAXX 965 69 | #define TS_MAXY 905 70 | 71 | // Init TouchScreen: 72 | 73 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, SENSIBILITY); 74 | 75 | void setup(void) { 76 | 77 | tft.reset(); 78 | tft.begin(0x9341); // SDFP5408 79 | 80 | tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial 81 | 82 | // Border 83 | 84 | drawBorder(); 85 | 86 | // Initial screen 87 | 88 | tft.setCursor (55, 50); 89 | tft.setTextSize (3); 90 | tft.setTextColor(RED); 91 | tft.println("SPFD5408"); 92 | tft.setCursor (65, 85); 93 | tft.println("Library"); 94 | tft.setCursor (25, 150); 95 | tft.setTextSize (2); 96 | tft.setTextColor(BLACK); 97 | tft.println("Test of rotation"); 98 | 99 | // Wait touch 100 | 101 | waitOneTouch(true); 102 | 103 | // Draw border 104 | 105 | drawBorder(); 106 | 107 | tft.setTextSize (1); 108 | tft.setTextColor(BLACK); 109 | tft.setCursor (20, 80); 110 | tft.println("This is a test of the rotation"); 111 | tft.setCursor (20, 100); 112 | tft.println("capabilities of the TFT library!"); 113 | tft.setCursor (20, 160); 114 | tft.println("Touch to advance each test"); 115 | 116 | // Wait touch 117 | 118 | waitOneTouch(true); 119 | 120 | } 121 | 122 | void loop(void) { 123 | 124 | // Tests 125 | 126 | //rotatePixel(); 127 | rotateLine(); 128 | rotateFastline(); 129 | rotateDrawrect(); 130 | rotateFillrect(); 131 | rotateDrawcircle(); 132 | rotateFillcircle(); 133 | rotateText(); 134 | 135 | // Complete 136 | 137 | drawBorder(); 138 | 139 | tft.setCursor (35, 50); 140 | tft.setTextSize (3); 141 | tft.setTextColor(RED); 142 | tft.println("Completed"); 143 | 144 | waitOneTouch(true); 145 | 146 | } 147 | 148 | void rotateText() { 149 | for (uint8_t i=0; i<4; i++) { 150 | tft.fillScreen(WHITE); 151 | 152 | tft.setCursor(0, 30); 153 | tft.setTextColor(RED); 154 | tft.setTextSize(1); 155 | tft.println("Hello World!"); 156 | tft.setTextColor(YELLOW); 157 | tft.setTextSize(2); 158 | tft.println("Hello World!"); 159 | tft.setTextColor(GREEN); 160 | tft.setTextSize(3); 161 | tft.println("Hello World!"); 162 | tft.setTextColor(BLUE); 163 | tft.setTextSize(4); 164 | tft.print(1234.567); 165 | 166 | waitOneTouch(true); // Wait touch 167 | 168 | tft.setRotation(tft.getRotation()+1); 169 | } 170 | } 171 | 172 | void rotateFillcircle(void) { 173 | for (uint8_t i=0; i<4; i++) { 174 | tft.fillScreen(WHITE); 175 | 176 | tft.fillCircle(10, 30, 10, YELLOW); 177 | 178 | tft.setRotation(tft.getRotation()+1); 179 | 180 | waitOneTouch(true); // Wait touch 181 | 182 | } 183 | } 184 | 185 | void rotateDrawcircle(void) { 186 | for (uint8_t i=0; i<4; i++) { 187 | tft.fillScreen(WHITE); 188 | 189 | tft.drawCircle(10, 30, 10, YELLOW); 190 | 191 | waitOneTouch(true); // Wait touch 192 | 193 | tft.setRotation(tft.getRotation()+1); 194 | } 195 | } 196 | 197 | void rotateFillrect(void) { 198 | for (uint8_t i=0; i<4; i++) { 199 | tft.fillScreen(WHITE); 200 | 201 | tft.fillRect(10, 20, 10, 20, GREEN); 202 | 203 | waitOneTouch(true); // Wait touch 204 | 205 | tft.setRotation(tft.getRotation()+1); 206 | } 207 | } 208 | 209 | void rotateDrawrect(void) { 210 | for (uint8_t i=0; i<4; i++) { 211 | tft.fillScreen(WHITE); 212 | 213 | tft.drawRect(10, 20, 10, 20, GREEN); 214 | 215 | waitOneTouch(true); // Wait touch 216 | 217 | tft.setRotation(tft.getRotation()+1); 218 | } 219 | } 220 | 221 | void rotateFastline(void) { 222 | for (uint8_t i=0; i<4; i++) { 223 | tft.fillScreen(WHITE); 224 | tft.drawFastHLine(0, 20, tft.width(), RED); 225 | tft.drawFastVLine(20, 0, tft.height(), BLUE); 226 | 227 | waitOneTouch(true); // Wait touch 228 | 229 | tft.setRotation(tft.getRotation()+1); 230 | } 231 | } 232 | 233 | void rotateLine(void) { 234 | for (uint8_t i=0; i<4; i++) { 235 | tft.fillScreen(WHITE); 236 | 237 | tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, RED); 238 | 239 | waitOneTouch(true); // Wait touch 240 | 241 | tft.setRotation(tft.getRotation()+1); 242 | } 243 | } 244 | 245 | void rotatePixel(void) { 246 | for (uint8_t i=0; i<4; i++) { 247 | tft.fillScreen(WHITE); 248 | 249 | tft.drawPixel(10,20, RED); 250 | 251 | waitOneTouch(true); // Wait touch 252 | 253 | tft.setRotation(tft.getRotation()+1); 254 | } 255 | } 256 | 257 | TSPoint waitOneTouch(boolean showMessage) { 258 | 259 | // wait 1 touch to exit function 260 | 261 | uint8_t save = 0; 262 | 263 | if (showMessage) { 264 | 265 | save = tft.getRotation(); // Save it 266 | tft.setRotation(0); // Show in normal 267 | 268 | tft.setCursor (80, 250); 269 | tft.setTextSize (1); 270 | tft.setTextColor(BLACK); 271 | tft.println("Touch to proceed"); 272 | 273 | } 274 | 275 | // Wait a touch 276 | 277 | TSPoint p; 278 | 279 | do { 280 | p= ts.getPoint(); 281 | 282 | pinMode(XM, OUTPUT); //Pins configures again for TFT control 283 | pinMode(YP, OUTPUT); 284 | 285 | } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE)); 286 | 287 | if (showMessage) { 288 | tft.setRotation(save); 289 | } 290 | 291 | return p; 292 | } 293 | 294 | void drawBorder () { 295 | 296 | // Draw a border 297 | 298 | uint16_t width = tft.width() - 1; 299 | uint16_t height = tft.height() - 1; 300 | uint8_t border = 10; 301 | 302 | tft.fillScreen(RED); 303 | tft.fillRect(border, border, (width - border * 2), (height - border * 2), WHITE); 304 | 305 | } 306 | 307 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/tftbmp_shield/tftbmp_shield.pde: -------------------------------------------------------------------------------- 1 | // BMP-loading example specifically for the TFTLCD Arduino shield. 2 | // If using the breakout board, use the tftbmp.pde sketch instead! 3 | // If using an Arduino Mega, make sure the SD library is configured for 4 | // 'soft' SPI in the file Sd2Card.h. 5 | 6 | #include // Core graphics library 7 | #include // Hardware-specific library 8 | #include 9 | 10 | // In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) 11 | // There are examples in the sketch folder 12 | 13 | #define SD_CS 5 // Card select for shield use 14 | 15 | Adafruit_TFTLCD tft; 16 | uint8_t spi_save; 17 | 18 | void setup() 19 | { 20 | Serial.begin(9600); 21 | 22 | tft.reset(); 23 | 24 | uint16_t identifier = tft.readID(); 25 | 26 | if(identifier == 0x9325) { 27 | progmemPrintln(PSTR("Found ILI9325 LCD driver")); 28 | } else if(identifier == 0x9328) { 29 | progmemPrintln(PSTR("Found ILI9328 LCD driver")); 30 | } else if(identifier == 0x7575) { 31 | progmemPrintln(PSTR("Found HX8347G LCD driver")); 32 | } else { 33 | progmemPrint(PSTR("Unknown LCD driver chip: ")); 34 | Serial.println(identifier, HEX); 35 | progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 36 | progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 37 | progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h).")); 38 | progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!")); 39 | progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring")); 40 | progmemPrintln(PSTR("matches the tutorial.")); 41 | return; 42 | } 43 | 44 | tft.begin(identifier); 45 | 46 | progmemPrint(PSTR("Initializing SD card...")); 47 | if (!SD.begin(SD_CS)) { 48 | progmemPrintln(PSTR("failed!")); 49 | return; 50 | } 51 | progmemPrintln(PSTR("OK!")); 52 | spi_save = SPCR; 53 | 54 | bmpDraw("woof.bmp", 0, 0); 55 | delay(1000); 56 | } 57 | 58 | void loop() 59 | { 60 | for(int i = 0; i<4; i++) { 61 | tft.setRotation(i); 62 | tft.fillScreen(0); 63 | for(int j=0; j <= 200; j += 50) { 64 | bmpDraw("miniwoof.bmp", j, j); 65 | } 66 | delay(1000); 67 | } 68 | } 69 | 70 | // This function opens a Windows Bitmap (BMP) file and 71 | // displays it at the given coordinates. It's sped up 72 | // by reading many pixels worth of data at a time 73 | // (rather than pixel by pixel). Increasing the buffer 74 | // size takes more of the Arduino's precious RAM but 75 | // makes loading a little faster. 20 pixels seems a 76 | // good balance. 77 | 78 | #define BUFFPIXEL 20 79 | 80 | void bmpDraw(char *filename, int x, int y) { 81 | File bmpFile; 82 | int bmpWidth, bmpHeight; // W+H in pixels 83 | uint8_t bmpDepth; // Bit depth (currently must be 24) 84 | uint32_t bmpImageoffset; // Start of image data in file 85 | uint32_t rowSize; // Not always = bmpWidth; may have padding 86 | uint8_t sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel) 87 | uint16_t lcdbuffer[BUFFPIXEL]; // pixel out buffer (16-bit per pixel) 88 | uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer 89 | boolean goodBmp = false; // Set to true on valid header parse 90 | boolean flip = true; // BMP is stored bottom-to-top 91 | int w, h, row, col; 92 | uint8_t r, g, b; 93 | uint32_t pos = 0, startTime = millis(); 94 | uint8_t lcdidx = 0; 95 | boolean first = true; 96 | 97 | if((x >= tft.width()) || (y >= tft.height())) return; 98 | 99 | Serial.println(); 100 | Serial.print("Loading image '"); 101 | Serial.print(filename); 102 | Serial.println('\''); 103 | // Open requested file on SD card 104 | SPCR = spi_save; 105 | if ((bmpFile = SD.open(filename)) == NULL) { 106 | Serial.print("File not found"); 107 | return; 108 | } 109 | 110 | // Parse BMP header 111 | if(read16(bmpFile) == 0x4D42) { // BMP signature 112 | progmemPrint(PSTR("File size: ")); Serial.println(read32(bmpFile)); 113 | (void)read32(bmpFile); // Read & ignore creator bytes 114 | bmpImageoffset = read32(bmpFile); // Start of image data 115 | progmemPrint(PSTR("Image Offset: ")); Serial.println(bmpImageoffset, DEC); 116 | // Read DIB header 117 | progmemPrint(PSTR("Header size: ")); Serial.println(read32(bmpFile)); 118 | bmpWidth = read32(bmpFile); 119 | bmpHeight = read32(bmpFile); 120 | if(read16(bmpFile) == 1) { // # planes -- must be '1' 121 | bmpDepth = read16(bmpFile); // bits per pixel 122 | progmemPrint(PSTR("Bit Depth: ")); Serial.println(bmpDepth); 123 | if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed 124 | 125 | goodBmp = true; // Supported BMP format -- proceed! 126 | progmemPrint(PSTR("Image size: ")); 127 | Serial.print(bmpWidth); 128 | Serial.print('x'); 129 | Serial.println(bmpHeight); 130 | 131 | // BMP rows are padded (if needed) to 4-byte boundary 132 | rowSize = (bmpWidth * 3 + 3) & ~3; 133 | 134 | // If bmpHeight is negative, image is in top-down order. 135 | // This is not canon but has been observed in the wild. 136 | if(bmpHeight < 0) { 137 | bmpHeight = -bmpHeight; 138 | flip = false; 139 | } 140 | 141 | // Crop area to be loaded 142 | w = bmpWidth; 143 | h = bmpHeight; 144 | if((x+w-1) >= tft.width()) w = tft.width() - x; 145 | if((y+h-1) >= tft.height()) h = tft.height() - y; 146 | 147 | // Set TFT address window to clipped image bounds 148 | SPCR = 0; 149 | tft.setAddrWindow(x, y, x+w-1, y+h-1); 150 | 151 | for (row=0; row= sizeof(sdbuffer)) { // Indeed 171 | // Push LCD buffer to the display first 172 | if(lcdidx > 0) { 173 | SPCR = 0; 174 | tft.pushColors(lcdbuffer, lcdidx, first); 175 | lcdidx = 0; 176 | first = false; 177 | } 178 | SPCR = spi_save; 179 | bmpFile.read(sdbuffer, sizeof(sdbuffer)); 180 | buffidx = 0; // Set index to beginning 181 | } 182 | 183 | // Convert pixel from BMP to TFT format 184 | b = sdbuffer[buffidx++]; 185 | g = sdbuffer[buffidx++]; 186 | r = sdbuffer[buffidx++]; 187 | lcdbuffer[lcdidx++] = tft.color565(r,g,b); 188 | } // end pixel 189 | } // end scanline 190 | // Write any remaining data to LCD 191 | if(lcdidx > 0) { 192 | SPCR = 0; 193 | tft.pushColors(lcdbuffer, lcdidx, first); 194 | } 195 | progmemPrint(PSTR("Loaded in ")); 196 | Serial.print(millis() - startTime); 197 | Serial.println(" ms"); 198 | } // end goodBmp 199 | } 200 | } 201 | 202 | bmpFile.close(); 203 | if(!goodBmp) Serial.println("BMP format not recognized."); 204 | } 205 | 206 | // These read 16- and 32-bit types from the SD card file. 207 | // BMP data is stored little-endian, Arduino is little-endian too. 208 | // May need to reverse subscript order if porting elsewhere. 209 | 210 | uint16_t read16(File f) { 211 | uint16_t result; 212 | ((uint8_t *)&result)[0] = f.read(); // LSB 213 | ((uint8_t *)&result)[1] = f.read(); // MSB 214 | return result; 215 | } 216 | 217 | uint32_t read32(File f) { 218 | uint32_t result; 219 | ((uint8_t *)&result)[0] = f.read(); // LSB 220 | ((uint8_t *)&result)[1] = f.read(); 221 | ((uint8_t *)&result)[2] = f.read(); 222 | ((uint8_t *)&result)[3] = f.read(); // MSB 223 | return result; 224 | } 225 | 226 | // Copy string from flash to serial port 227 | // Source string MUST be inside a PSTR() declaration! 228 | void progmemPrint(const char *str) { 229 | char c; 230 | while(c = pgm_read_byte(str++)) Serial.print(c); 231 | } 232 | 233 | // Same as above, with trailing newline 234 | void progmemPrintln(const char *str) { 235 | progmemPrint(str); 236 | Serial.println(); 237 | } 238 | 239 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/tftpaint_shield/glcdfont.c: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FONT5X7_H 3 | #define FONT5X7_H 4 | 5 | // standard ascii 5x7 font 6 | 7 | static unsigned char font[] = { 8 | 0x00, 0x00, 0x00, 0x00, 0x00, 9 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 10 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 11 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 12 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 13 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 14 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 15 | 0x00, 0x18, 0x3C, 0x18, 0x00, 16 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 17 | 0x00, 0x18, 0x24, 0x18, 0x00, 18 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 19 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 20 | 0x26, 0x29, 0x79, 0x29, 0x26, 21 | 0x40, 0x7F, 0x05, 0x05, 0x07, 22 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 23 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 24 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 25 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 26 | 0x14, 0x22, 0x7F, 0x22, 0x14, 27 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 28 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 29 | 0x00, 0x66, 0x89, 0x95, 0x6A, 30 | 0x60, 0x60, 0x60, 0x60, 0x60, 31 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 32 | 0x08, 0x04, 0x7E, 0x04, 0x08, 33 | 0x10, 0x20, 0x7E, 0x20, 0x10, 34 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 35 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 36 | 0x1E, 0x10, 0x10, 0x10, 0x10, 37 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 38 | 0x30, 0x38, 0x3E, 0x38, 0x30, 39 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x5F, 0x00, 0x00, 42 | 0x00, 0x07, 0x00, 0x07, 0x00, 43 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 44 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 45 | 0x23, 0x13, 0x08, 0x64, 0x62, 46 | 0x36, 0x49, 0x56, 0x20, 0x50, 47 | 0x00, 0x08, 0x07, 0x03, 0x00, 48 | 0x00, 0x1C, 0x22, 0x41, 0x00, 49 | 0x00, 0x41, 0x22, 0x1C, 0x00, 50 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 51 | 0x08, 0x08, 0x3E, 0x08, 0x08, 52 | 0x00, 0x80, 0x70, 0x30, 0x00, 53 | 0x08, 0x08, 0x08, 0x08, 0x08, 54 | 0x00, 0x00, 0x60, 0x60, 0x00, 55 | 0x20, 0x10, 0x08, 0x04, 0x02, 56 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 57 | 0x00, 0x42, 0x7F, 0x40, 0x00, 58 | 0x72, 0x49, 0x49, 0x49, 0x46, 59 | 0x21, 0x41, 0x49, 0x4D, 0x33, 60 | 0x18, 0x14, 0x12, 0x7F, 0x10, 61 | 0x27, 0x45, 0x45, 0x45, 0x39, 62 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 63 | 0x41, 0x21, 0x11, 0x09, 0x07, 64 | 0x36, 0x49, 0x49, 0x49, 0x36, 65 | 0x46, 0x49, 0x49, 0x29, 0x1E, 66 | 0x00, 0x00, 0x14, 0x00, 0x00, 67 | 0x00, 0x40, 0x34, 0x00, 0x00, 68 | 0x00, 0x08, 0x14, 0x22, 0x41, 69 | 0x14, 0x14, 0x14, 0x14, 0x14, 70 | 0x00, 0x41, 0x22, 0x14, 0x08, 71 | 0x02, 0x01, 0x59, 0x09, 0x06, 72 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 73 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 74 | 0x7F, 0x49, 0x49, 0x49, 0x36, 75 | 0x3E, 0x41, 0x41, 0x41, 0x22, 76 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 77 | 0x7F, 0x49, 0x49, 0x49, 0x41, 78 | 0x7F, 0x09, 0x09, 0x09, 0x01, 79 | 0x3E, 0x41, 0x41, 0x51, 0x73, 80 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 81 | 0x00, 0x41, 0x7F, 0x41, 0x00, 82 | 0x20, 0x40, 0x41, 0x3F, 0x01, 83 | 0x7F, 0x08, 0x14, 0x22, 0x41, 84 | 0x7F, 0x40, 0x40, 0x40, 0x40, 85 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 86 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 87 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 88 | 0x7F, 0x09, 0x09, 0x09, 0x06, 89 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 90 | 0x7F, 0x09, 0x19, 0x29, 0x46, 91 | 0x26, 0x49, 0x49, 0x49, 0x32, 92 | 0x03, 0x01, 0x7F, 0x01, 0x03, 93 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 94 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 95 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 96 | 0x63, 0x14, 0x08, 0x14, 0x63, 97 | 0x03, 0x04, 0x78, 0x04, 0x03, 98 | 0x61, 0x59, 0x49, 0x4D, 0x43, 99 | 0x00, 0x7F, 0x41, 0x41, 0x41, 100 | 0x02, 0x04, 0x08, 0x10, 0x20, 101 | 0x00, 0x41, 0x41, 0x41, 0x7F, 102 | 0x04, 0x02, 0x01, 0x02, 0x04, 103 | 0x40, 0x40, 0x40, 0x40, 0x40, 104 | 0x00, 0x03, 0x07, 0x08, 0x00, 105 | 0x20, 0x54, 0x54, 0x78, 0x40, 106 | 0x7F, 0x28, 0x44, 0x44, 0x38, 107 | 0x38, 0x44, 0x44, 0x44, 0x28, 108 | 0x38, 0x44, 0x44, 0x28, 0x7F, 109 | 0x38, 0x54, 0x54, 0x54, 0x18, 110 | 0x00, 0x08, 0x7E, 0x09, 0x02, 111 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 112 | 0x7F, 0x08, 0x04, 0x04, 0x78, 113 | 0x00, 0x44, 0x7D, 0x40, 0x00, 114 | 0x20, 0x40, 0x40, 0x3D, 0x00, 115 | 0x7F, 0x10, 0x28, 0x44, 0x00, 116 | 0x00, 0x41, 0x7F, 0x40, 0x00, 117 | 0x7C, 0x04, 0x78, 0x04, 0x78, 118 | 0x7C, 0x08, 0x04, 0x04, 0x78, 119 | 0x38, 0x44, 0x44, 0x44, 0x38, 120 | 0xFC, 0x18, 0x24, 0x24, 0x18, 121 | 0x18, 0x24, 0x24, 0x18, 0xFC, 122 | 0x7C, 0x08, 0x04, 0x04, 0x08, 123 | 0x48, 0x54, 0x54, 0x54, 0x24, 124 | 0x04, 0x04, 0x3F, 0x44, 0x24, 125 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 126 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 127 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 128 | 0x44, 0x28, 0x10, 0x28, 0x44, 129 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 130 | 0x44, 0x64, 0x54, 0x4C, 0x44, 131 | 0x00, 0x08, 0x36, 0x41, 0x00, 132 | 0x00, 0x00, 0x77, 0x00, 0x00, 133 | 0x00, 0x41, 0x36, 0x08, 0x00, 134 | 0x02, 0x01, 0x02, 0x04, 0x02, 135 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 136 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 137 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 138 | 0x38, 0x54, 0x54, 0x55, 0x59, 139 | 0x21, 0x55, 0x55, 0x79, 0x41, 140 | 0x21, 0x54, 0x54, 0x78, 0x41, 141 | 0x21, 0x55, 0x54, 0x78, 0x40, 142 | 0x20, 0x54, 0x55, 0x79, 0x40, 143 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 144 | 0x39, 0x55, 0x55, 0x55, 0x59, 145 | 0x39, 0x54, 0x54, 0x54, 0x59, 146 | 0x39, 0x55, 0x54, 0x54, 0x58, 147 | 0x00, 0x00, 0x45, 0x7C, 0x41, 148 | 0x00, 0x02, 0x45, 0x7D, 0x42, 149 | 0x00, 0x01, 0x45, 0x7C, 0x40, 150 | 0xF0, 0x29, 0x24, 0x29, 0xF0, 151 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 152 | 0x7C, 0x54, 0x55, 0x45, 0x00, 153 | 0x20, 0x54, 0x54, 0x7C, 0x54, 154 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 155 | 0x32, 0x49, 0x49, 0x49, 0x32, 156 | 0x32, 0x48, 0x48, 0x48, 0x32, 157 | 0x32, 0x4A, 0x48, 0x48, 0x30, 158 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 159 | 0x3A, 0x42, 0x40, 0x20, 0x78, 160 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 161 | 0x39, 0x44, 0x44, 0x44, 0x39, 162 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 163 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 164 | 0x48, 0x7E, 0x49, 0x43, 0x66, 165 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 166 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 167 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 168 | 0x20, 0x54, 0x54, 0x79, 0x41, 169 | 0x00, 0x00, 0x44, 0x7D, 0x41, 170 | 0x30, 0x48, 0x48, 0x4A, 0x32, 171 | 0x38, 0x40, 0x40, 0x22, 0x7A, 172 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 173 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 174 | 0x26, 0x29, 0x29, 0x2F, 0x28, 175 | 0x26, 0x29, 0x29, 0x29, 0x26, 176 | 0x30, 0x48, 0x4D, 0x40, 0x20, 177 | 0x38, 0x08, 0x08, 0x08, 0x08, 178 | 0x08, 0x08, 0x08, 0x08, 0x38, 179 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 180 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 181 | 0x00, 0x00, 0x7B, 0x00, 0x00, 182 | 0x08, 0x14, 0x2A, 0x14, 0x22, 183 | 0x22, 0x14, 0x2A, 0x14, 0x08, 184 | 0xAA, 0x00, 0x55, 0x00, 0xAA, 185 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, 186 | 0x00, 0x00, 0x00, 0xFF, 0x00, 187 | 0x10, 0x10, 0x10, 0xFF, 0x00, 188 | 0x14, 0x14, 0x14, 0xFF, 0x00, 189 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 190 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 191 | 0x14, 0x14, 0x14, 0xFC, 0x00, 192 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 193 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 194 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 195 | 0x14, 0x14, 0x17, 0x10, 0x1F, 196 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 197 | 0x14, 0x14, 0x14, 0x1F, 0x00, 198 | 0x10, 0x10, 0x10, 0xF0, 0x00, 199 | 0x00, 0x00, 0x00, 0x1F, 0x10, 200 | 0x10, 0x10, 0x10, 0x1F, 0x10, 201 | 0x10, 0x10, 0x10, 0xF0, 0x10, 202 | 0x00, 0x00, 0x00, 0xFF, 0x10, 203 | 0x10, 0x10, 0x10, 0x10, 0x10, 204 | 0x10, 0x10, 0x10, 0xFF, 0x10, 205 | 0x00, 0x00, 0x00, 0xFF, 0x14, 206 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 207 | 0x00, 0x00, 0x1F, 0x10, 0x17, 208 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 209 | 0x14, 0x14, 0x17, 0x10, 0x17, 210 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 211 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 212 | 0x14, 0x14, 0x14, 0x14, 0x14, 213 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 214 | 0x14, 0x14, 0x14, 0x17, 0x14, 215 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 216 | 0x14, 0x14, 0x14, 0xF4, 0x14, 217 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 218 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 219 | 0x00, 0x00, 0x00, 0x1F, 0x14, 220 | 0x00, 0x00, 0x00, 0xFC, 0x14, 221 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 222 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 223 | 0x14, 0x14, 0x14, 0xFF, 0x14, 224 | 0x10, 0x10, 0x10, 0x1F, 0x00, 225 | 0x00, 0x00, 0x00, 0xF0, 0x10, 226 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 227 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 228 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 229 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 230 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 231 | 0x38, 0x44, 0x44, 0x38, 0x44, 232 | 0x7C, 0x2A, 0x2A, 0x3E, 0x14, 233 | 0x7E, 0x02, 0x02, 0x06, 0x06, 234 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 235 | 0x63, 0x55, 0x49, 0x41, 0x63, 236 | 0x38, 0x44, 0x44, 0x3C, 0x04, 237 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 238 | 0x06, 0x02, 0x7E, 0x02, 0x02, 239 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 240 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 241 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 242 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 243 | 0x30, 0x48, 0x78, 0x48, 0x30, 244 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 245 | 0x3E, 0x49, 0x49, 0x49, 0x00, 246 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 247 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 248 | 0x44, 0x44, 0x5F, 0x44, 0x44, 249 | 0x40, 0x51, 0x4A, 0x44, 0x40, 250 | 0x40, 0x44, 0x4A, 0x51, 0x40, 251 | 0x00, 0x00, 0xFF, 0x01, 0x03, 252 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 253 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 254 | 0x36, 0x12, 0x36, 0x24, 0x36, 255 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 256 | 0x00, 0x00, 0x18, 0x18, 0x00, 257 | 0x00, 0x00, 0x10, 0x10, 0x00, 258 | 0x30, 0x40, 0xFF, 0x01, 0x01, 259 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 260 | 0x00, 0x19, 0x1D, 0x17, 0x12, 261 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 262 | 0x00, 0x00, 0x00, 0x00, 0x00, 263 | }; 264 | #endif 265 | -------------------------------------------------------------------------------- /SPFD5408/glcdfont.c: -------------------------------------------------------------------------------- 1 | #ifndef FONT5X7_H 2 | #define FONT5X7_H 3 | 4 | #ifdef __AVR__ 5 | #include 6 | #include 7 | #elif defined(ESP8266) 8 | #include 9 | #else 10 | #define PROGMEM 11 | #endif 12 | 13 | // Standard ASCII 5x7 font 14 | 15 | static const unsigned char font[] PROGMEM = { 16 | 0x00, 0x00, 0x00, 0x00, 0x00, 17 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 18 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 19 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 20 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 21 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 22 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 23 | 0x00, 0x18, 0x3C, 0x18, 0x00, 24 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 25 | 0x00, 0x18, 0x24, 0x18, 0x00, 26 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 27 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 28 | 0x26, 0x29, 0x79, 0x29, 0x26, 29 | 0x40, 0x7F, 0x05, 0x05, 0x07, 30 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 31 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 32 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 33 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 34 | 0x14, 0x22, 0x7F, 0x22, 0x14, 35 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 36 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 37 | 0x00, 0x66, 0x89, 0x95, 0x6A, 38 | 0x60, 0x60, 0x60, 0x60, 0x60, 39 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 40 | 0x08, 0x04, 0x7E, 0x04, 0x08, 41 | 0x10, 0x20, 0x7E, 0x20, 0x10, 42 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 43 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 44 | 0x1E, 0x10, 0x10, 0x10, 0x10, 45 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 46 | 0x30, 0x38, 0x3E, 0x38, 0x30, 47 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x5F, 0x00, 0x00, 50 | 0x00, 0x07, 0x00, 0x07, 0x00, 51 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 52 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 53 | 0x23, 0x13, 0x08, 0x64, 0x62, 54 | 0x36, 0x49, 0x56, 0x20, 0x50, 55 | 0x00, 0x08, 0x07, 0x03, 0x00, 56 | 0x00, 0x1C, 0x22, 0x41, 0x00, 57 | 0x00, 0x41, 0x22, 0x1C, 0x00, 58 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 59 | 0x08, 0x08, 0x3E, 0x08, 0x08, 60 | 0x00, 0x80, 0x70, 0x30, 0x00, 61 | 0x08, 0x08, 0x08, 0x08, 0x08, 62 | 0x00, 0x00, 0x60, 0x60, 0x00, 63 | 0x20, 0x10, 0x08, 0x04, 0x02, 64 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 65 | 0x00, 0x42, 0x7F, 0x40, 0x00, 66 | 0x72, 0x49, 0x49, 0x49, 0x46, 67 | 0x21, 0x41, 0x49, 0x4D, 0x33, 68 | 0x18, 0x14, 0x12, 0x7F, 0x10, 69 | 0x27, 0x45, 0x45, 0x45, 0x39, 70 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 71 | 0x41, 0x21, 0x11, 0x09, 0x07, 72 | 0x36, 0x49, 0x49, 0x49, 0x36, 73 | 0x46, 0x49, 0x49, 0x29, 0x1E, 74 | 0x00, 0x00, 0x14, 0x00, 0x00, 75 | 0x00, 0x40, 0x34, 0x00, 0x00, 76 | 0x00, 0x08, 0x14, 0x22, 0x41, 77 | 0x14, 0x14, 0x14, 0x14, 0x14, 78 | 0x00, 0x41, 0x22, 0x14, 0x08, 79 | 0x02, 0x01, 0x59, 0x09, 0x06, 80 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 81 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 82 | 0x7F, 0x49, 0x49, 0x49, 0x36, 83 | 0x3E, 0x41, 0x41, 0x41, 0x22, 84 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 85 | 0x7F, 0x49, 0x49, 0x49, 0x41, 86 | 0x7F, 0x09, 0x09, 0x09, 0x01, 87 | 0x3E, 0x41, 0x41, 0x51, 0x73, 88 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 89 | 0x00, 0x41, 0x7F, 0x41, 0x00, 90 | 0x20, 0x40, 0x41, 0x3F, 0x01, 91 | 0x7F, 0x08, 0x14, 0x22, 0x41, 92 | 0x7F, 0x40, 0x40, 0x40, 0x40, 93 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 94 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 95 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 96 | 0x7F, 0x09, 0x09, 0x09, 0x06, 97 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 98 | 0x7F, 0x09, 0x19, 0x29, 0x46, 99 | 0x26, 0x49, 0x49, 0x49, 0x32, 100 | 0x03, 0x01, 0x7F, 0x01, 0x03, 101 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 102 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 103 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 104 | 0x63, 0x14, 0x08, 0x14, 0x63, 105 | 0x03, 0x04, 0x78, 0x04, 0x03, 106 | 0x61, 0x59, 0x49, 0x4D, 0x43, 107 | 0x00, 0x7F, 0x41, 0x41, 0x41, 108 | 0x02, 0x04, 0x08, 0x10, 0x20, 109 | 0x00, 0x41, 0x41, 0x41, 0x7F, 110 | 0x04, 0x02, 0x01, 0x02, 0x04, 111 | 0x40, 0x40, 0x40, 0x40, 0x40, 112 | 0x00, 0x03, 0x07, 0x08, 0x00, 113 | 0x20, 0x54, 0x54, 0x78, 0x40, 114 | 0x7F, 0x28, 0x44, 0x44, 0x38, 115 | 0x38, 0x44, 0x44, 0x44, 0x28, 116 | 0x38, 0x44, 0x44, 0x28, 0x7F, 117 | 0x38, 0x54, 0x54, 0x54, 0x18, 118 | 0x00, 0x08, 0x7E, 0x09, 0x02, 119 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 120 | 0x7F, 0x08, 0x04, 0x04, 0x78, 121 | 0x00, 0x44, 0x7D, 0x40, 0x00, 122 | 0x20, 0x40, 0x40, 0x3D, 0x00, 123 | 0x7F, 0x10, 0x28, 0x44, 0x00, 124 | 0x00, 0x41, 0x7F, 0x40, 0x00, 125 | 0x7C, 0x04, 0x78, 0x04, 0x78, 126 | 0x7C, 0x08, 0x04, 0x04, 0x78, 127 | 0x38, 0x44, 0x44, 0x44, 0x38, 128 | 0xFC, 0x18, 0x24, 0x24, 0x18, 129 | 0x18, 0x24, 0x24, 0x18, 0xFC, 130 | 0x7C, 0x08, 0x04, 0x04, 0x08, 131 | 0x48, 0x54, 0x54, 0x54, 0x24, 132 | 0x04, 0x04, 0x3F, 0x44, 0x24, 133 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 134 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 135 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 136 | 0x44, 0x28, 0x10, 0x28, 0x44, 137 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 138 | 0x44, 0x64, 0x54, 0x4C, 0x44, 139 | 0x00, 0x08, 0x36, 0x41, 0x00, 140 | 0x00, 0x00, 0x77, 0x00, 0x00, 141 | 0x00, 0x41, 0x36, 0x08, 0x00, 142 | 0x02, 0x01, 0x02, 0x04, 0x02, 143 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 144 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 145 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 146 | 0x38, 0x54, 0x54, 0x55, 0x59, 147 | 0x21, 0x55, 0x55, 0x79, 0x41, 148 | 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut 149 | 0x21, 0x55, 0x54, 0x78, 0x40, 150 | 0x20, 0x54, 0x55, 0x79, 0x40, 151 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 152 | 0x39, 0x55, 0x55, 0x55, 0x59, 153 | 0x39, 0x54, 0x54, 0x54, 0x59, 154 | 0x39, 0x55, 0x54, 0x54, 0x58, 155 | 0x00, 0x00, 0x45, 0x7C, 0x41, 156 | 0x00, 0x02, 0x45, 0x7D, 0x42, 157 | 0x00, 0x01, 0x45, 0x7C, 0x40, 158 | 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut 159 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 160 | 0x7C, 0x54, 0x55, 0x45, 0x00, 161 | 0x20, 0x54, 0x54, 0x7C, 0x54, 162 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 163 | 0x32, 0x49, 0x49, 0x49, 0x32, 164 | 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut 165 | 0x32, 0x4A, 0x48, 0x48, 0x30, 166 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 167 | 0x3A, 0x42, 0x40, 0x20, 0x78, 168 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 169 | 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut 170 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 171 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 172 | 0x48, 0x7E, 0x49, 0x43, 0x66, 173 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 174 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 175 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 176 | 0x20, 0x54, 0x54, 0x79, 0x41, 177 | 0x00, 0x00, 0x44, 0x7D, 0x41, 178 | 0x30, 0x48, 0x48, 0x4A, 0x32, 179 | 0x38, 0x40, 0x40, 0x22, 0x7A, 180 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 181 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 182 | 0x26, 0x29, 0x29, 0x2F, 0x28, 183 | 0x26, 0x29, 0x29, 0x29, 0x26, 184 | 0x30, 0x48, 0x4D, 0x40, 0x20, 185 | 0x38, 0x08, 0x08, 0x08, 0x08, 186 | 0x08, 0x08, 0x08, 0x08, 0x38, 187 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 188 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 189 | 0x00, 0x00, 0x7B, 0x00, 0x00, 190 | 0x08, 0x14, 0x2A, 0x14, 0x22, 191 | 0x22, 0x14, 0x2A, 0x14, 0x08, 192 | 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code 193 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block 194 | 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block 195 | 0x00, 0x00, 0x00, 0xFF, 0x00, 196 | 0x10, 0x10, 0x10, 0xFF, 0x00, 197 | 0x14, 0x14, 0x14, 0xFF, 0x00, 198 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 199 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 200 | 0x14, 0x14, 0x14, 0xFC, 0x00, 201 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 202 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 203 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 204 | 0x14, 0x14, 0x17, 0x10, 0x1F, 205 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 206 | 0x14, 0x14, 0x14, 0x1F, 0x00, 207 | 0x10, 0x10, 0x10, 0xF0, 0x00, 208 | 0x00, 0x00, 0x00, 0x1F, 0x10, 209 | 0x10, 0x10, 0x10, 0x1F, 0x10, 210 | 0x10, 0x10, 0x10, 0xF0, 0x10, 211 | 0x00, 0x00, 0x00, 0xFF, 0x10, 212 | 0x10, 0x10, 0x10, 0x10, 0x10, 213 | 0x10, 0x10, 0x10, 0xFF, 0x10, 214 | 0x00, 0x00, 0x00, 0xFF, 0x14, 215 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 216 | 0x00, 0x00, 0x1F, 0x10, 0x17, 217 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 218 | 0x14, 0x14, 0x17, 0x10, 0x17, 219 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 220 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 221 | 0x14, 0x14, 0x14, 0x14, 0x14, 222 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 223 | 0x14, 0x14, 0x14, 0x17, 0x14, 224 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 225 | 0x14, 0x14, 0x14, 0xF4, 0x14, 226 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 227 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 228 | 0x00, 0x00, 0x00, 0x1F, 0x14, 229 | 0x00, 0x00, 0x00, 0xFC, 0x14, 230 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 231 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 232 | 0x14, 0x14, 0x14, 0xFF, 0x14, 233 | 0x10, 0x10, 0x10, 0x1F, 0x00, 234 | 0x00, 0x00, 0x00, 0xF0, 0x10, 235 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 236 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 237 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 238 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 239 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 240 | 0x38, 0x44, 0x44, 0x38, 0x44, 241 | 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta 242 | 0x7E, 0x02, 0x02, 0x06, 0x06, 243 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 244 | 0x63, 0x55, 0x49, 0x41, 0x63, 245 | 0x38, 0x44, 0x44, 0x3C, 0x04, 246 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 247 | 0x06, 0x02, 0x7E, 0x02, 0x02, 248 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 249 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 250 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 251 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 252 | 0x30, 0x48, 0x78, 0x48, 0x30, 253 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 254 | 0x3E, 0x49, 0x49, 0x49, 0x00, 255 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 256 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 257 | 0x44, 0x44, 0x5F, 0x44, 0x44, 258 | 0x40, 0x51, 0x4A, 0x44, 0x40, 259 | 0x40, 0x44, 0x4A, 0x51, 0x40, 260 | 0x00, 0x00, 0xFF, 0x01, 0x03, 261 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 262 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 263 | 0x36, 0x12, 0x36, 0x24, 0x36, 264 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 265 | 0x00, 0x00, 0x18, 0x18, 0x00, 266 | 0x00, 0x00, 0x10, 0x10, 0x00, 267 | 0x30, 0x40, 0xFF, 0x01, 0x01, 268 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 269 | 0x00, 0x19, 0x1D, 0x17, 0x12, 270 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 271 | 0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP 272 | }; 273 | #endif // FONT5X7_H 274 | -------------------------------------------------------------------------------- /SPFD5408/examples/spfd5408_tftpaint/spfd5408_tftpaint.ino: -------------------------------------------------------------------------------- 1 | // Paint example specifically for the TFTLCD breakout board. 2 | // If using the Arduino shield, use the tftpaint_shield.pde sketch instead! 3 | // DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO 4 | 5 | // Modified for SPFD5408 Library by Joao Lopes 6 | // Version 0.9.2 - Rotation for Mega 7 | 8 | // *** SPFD5408 change -- Begin 9 | #include // Core graphics library 10 | #include // Hardware-specific library 11 | #include 12 | // *** SPFD5408 change -- End 13 | 14 | #if defined(__SAM3X8E__) 15 | #undef __FlashStringHelper::F(string_literal) 16 | #define F(string_literal) string_literal 17 | #endif 18 | 19 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 20 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 21 | // D0 connects to digital pin 8 (Notice these are 22 | // D1 connects to digital pin 9 NOT in order!) 23 | // D2 connects to digital pin 2 24 | // D3 connects to digital pin 3 25 | // D4 connects to digital pin 4 26 | // D5 connects to digital pin 5 27 | // D6 connects to digital pin 6 28 | // D7 connects to digital pin 7 29 | 30 | // For the Arduino Mega, use digital pins 22 through 29 31 | // (on the 2-row header at the end of the board). 32 | // D0 connects to digital pin 22 33 | // D1 connects to digital pin 23 34 | // D2 connects to digital pin 24 35 | // D3 connects to digital pin 25 36 | // D4 connects to digital pin 26 37 | // D5 connects to digital pin 27 38 | // D6 connects to digital pin 28 39 | // D7 connects to digital pin 29 40 | 41 | // For the Arduino Due, use digital pins 33 through 40 42 | // (on the 2-row header at the end of the board). 43 | // D0 connects to digital pin 33 44 | // D1 connects to digital pin 34 45 | // D2 connects to digital pin 35 46 | // D3 connects to digital pin 36 47 | // D4 connects to digital pin 37 48 | // D5 connects to digital pin 38 49 | // D6 connects to digital pin 39 50 | // D7 connects to digital pin 40 51 | 52 | #define YP A1 // must be an analog pin, use "An" notation! 53 | #define XM A2 // must be an analog pin, use "An" notation! 54 | #define YM 7 // can be a digital pin 55 | #define XP 6 // can be a digital pin 56 | 57 | // Original values 58 | //#define TS_MINX 150 59 | //#define TS_MINY 120 60 | //#define TS_MAXX 920 61 | //#define TS_MAXY 940 62 | 63 | // Calibrate values 64 | #define TS_MINX 125 65 | #define TS_MINY 85 66 | #define TS_MAXX 965 67 | #define TS_MAXY 905 68 | 69 | // For better pressure precision, we need to know the resistance 70 | // between X+ and X- Use any multimeter to read it 71 | // For the one we're using, its 300 ohms across the X plate 72 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); 73 | 74 | #define LCD_CS A3 75 | #define LCD_CD A2 76 | #define LCD_WR A1 77 | #define LCD_RD A0 78 | // optional 79 | #define LCD_RESET A4 80 | 81 | // Assign human-readable names to some common 16-bit color values: 82 | #define BLACK 0x0000 83 | #define BLUE 0x001F 84 | #define RED 0xF800 85 | #define GREEN 0x07E0 86 | #define CYAN 0x07FF 87 | #define MAGENTA 0xF81F 88 | #define YELLOW 0xFFE0 89 | #define WHITE 0xFFFF 90 | 91 | 92 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 93 | 94 | #define BOXSIZE 40 95 | #define PENRADIUS 3 96 | int oldcolor, currentcolor; 97 | 98 | void setup(void) { 99 | Serial.begin(9600); 100 | Serial.println(F("Paint!")); 101 | 102 | tft.reset(); 103 | 104 | // *** SPFD5408 change -- Begin 105 | // uint16_t identifier = tft.readID(); 106 | // 107 | // if(identifier == 0x9325) { 108 | // Serial.println(F("Found ILI9325 LCD driver")); 109 | // } else if(identifier == 0x9328) { 110 | // Serial.println(F("Found ILI9328 LCD driver")); 111 | // } else if(identifier == 0x7575) { 112 | // Serial.println(F("Found HX8347G LCD driver")); 113 | // } else if(identifier == 0x9341) { 114 | // Serial.println(F("Found ILI9341 LCD driver")); 115 | // } else if(identifier == 0x8357) { 116 | // Serial.println(F("Found HX8357D LCD driver")); 117 | // } else { 118 | // Serial.print(F("Unknown LCD driver chip: ")); 119 | // Serial.println(identifier, HEX); 120 | // Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 121 | // Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 122 | // Serial.println(F("should appear in the library header (Adafruit_TFT.h).")); 123 | // Serial.println(F("If using the breakout board, it should NOT be #defined!")); 124 | // Serial.println(F("Also if using the breakout, double-check that all wiring")); 125 | // Serial.println(F("matches the tutorial.")); 126 | // return; 127 | // } 128 | // 129 | // tft.begin(identifier); 130 | 131 | tft.begin(0x9341); // SDFP5408 132 | 133 | tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial 134 | 135 | // Border 136 | 137 | drawBorder(); 138 | 139 | // Initial screen 140 | 141 | tft.setCursor (55, 50); 142 | tft.setTextSize (3); 143 | tft.setTextColor(RED); 144 | tft.println("SPFD5408"); 145 | tft.setCursor (65, 85); 146 | tft.println("Library"); 147 | tft.setCursor (55, 150); 148 | tft.setTextSize (2); 149 | tft.setTextColor(BLACK); 150 | tft.println("TFT Paint"); 151 | 152 | tft.setCursor (80, 250); 153 | tft.setTextSize (1); 154 | tft.setTextColor(BLACK); 155 | tft.println("Touch to proceed"); 156 | 157 | // Wait touch 158 | 159 | waitOneTouch(); 160 | 161 | // *** SPFD5408 change -- End 162 | 163 | // -- End 164 | 165 | // Paint 166 | 167 | tft.fillScreen(BLACK); 168 | 169 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 170 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 171 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 172 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 173 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 174 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 175 | // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE); 176 | 177 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 178 | currentcolor = RED; 179 | 180 | pinMode(13, OUTPUT); 181 | } 182 | 183 | #define MINPRESSURE 10 184 | #define MAXPRESSURE 1000 185 | 186 | void loop() 187 | { 188 | digitalWrite(13, HIGH); 189 | TSPoint p = ts.getPoint(); 190 | digitalWrite(13, LOW); 191 | 192 | // if sharing pins, you'll need to fix the directions of the touchscreen pins 193 | //pinMode(XP, OUTPUT); 194 | pinMode(XM, OUTPUT); 195 | pinMode(YP, OUTPUT); 196 | //pinMode(YM, OUTPUT); 197 | 198 | // we have some minimum pressure we consider 'valid' 199 | // pressure of 0 means no pressing! 200 | 201 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { 202 | /* 203 | Serial.print("X = "); Serial.print(p.x); 204 | Serial.print("\tY = "); Serial.print(p.y); 205 | Serial.print("\tPressure = "); Serial.println(p.z); 206 | */ 207 | 208 | if (p.y < (TS_MINY-5)) { 209 | Serial.println("erase"); 210 | // press the bottom of the screen to erase 211 | tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK); 212 | } 213 | // scale from 0->1023 to tft.width 214 | 215 | // *** SPFD5408 change -- Begin 216 | // Bug in in original code 217 | //p.x = map(p.y, TS_MINY, TS_MAXY, 0, tft.height()); 218 | p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width()); 219 | // *** SPFD5408 change -- End 220 | p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());; 221 | 222 | /* 223 | Serial.print("("); Serial.print(p.x); 224 | Serial.print(", "); Serial.print(p.y); 225 | Serial.println(")"); 226 | */ 227 | if (p.y < BOXSIZE) { 228 | oldcolor = currentcolor; 229 | 230 | if (p.x < BOXSIZE) { 231 | currentcolor = RED; 232 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); 233 | } else if (p.x < BOXSIZE*2) { 234 | currentcolor = YELLOW; 235 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); 236 | } else if (p.x < BOXSIZE*3) { 237 | currentcolor = GREEN; 238 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE); 239 | } else if (p.x < BOXSIZE*4) { 240 | currentcolor = CYAN; 241 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE); 242 | } else if (p.x < BOXSIZE*5) { 243 | currentcolor = BLUE; 244 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE); 245 | } else if (p.x < BOXSIZE*6) { 246 | currentcolor = MAGENTA; 247 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE); 248 | } 249 | 250 | if (oldcolor != currentcolor) { 251 | if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); 252 | if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); 253 | if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN); 254 | if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN); 255 | if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE); 256 | if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA); 257 | } 258 | } 259 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) { 260 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); 261 | } 262 | } 263 | } 264 | 265 | // Wait one touch 266 | 267 | TSPoint waitOneTouch() { 268 | 269 | // wait 1 touch to exit function 270 | 271 | TSPoint p; 272 | 273 | do { 274 | p= ts.getPoint(); 275 | 276 | pinMode(XM, OUTPUT); //Pins configures again for TFT control 277 | pinMode(YP, OUTPUT); 278 | 279 | } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE)); 280 | 281 | return p; 282 | } 283 | 284 | 285 | void drawBorder () { 286 | 287 | // Draw a border 288 | 289 | uint16_t width = tft.width() - 1; 290 | uint16_t height = tft.height() - 1; 291 | uint8_t border = 10; 292 | 293 | tft.fillScreen(RED); 294 | tft.fillRect(border, border, (width - border * 2), (height - border * 2), WHITE); 295 | 296 | } 297 | 298 | 299 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/tftbmp/tftbmp.pde: -------------------------------------------------------------------------------- 1 | // BMP-loading example specifically for the TFTLCD breakout board. 2 | // If using the Arduino shield, use the tftbmp_shield.pde sketch instead! 3 | // If using an Arduino Mega, make sure the SD library is configured for 4 | // 'soft' SPI in the file Sd2Card.h. 5 | 6 | #include // Core graphics library 7 | #include // Hardware-specific library 8 | #include 9 | 10 | // The control pins for the LCD can be assigned to any digital or 11 | // analog pins...but we'll use the analog pins as this allows us to 12 | // double up the pins with the touch screen (see the TFT paint example). 13 | #define LCD_CS A3 // Chip Select goes to Analog 3 14 | #define LCD_CD A2 // Command/Data goes to Analog 2 15 | #define LCD_WR A1 // LCD Write goes to Analog 1 16 | #define LCD_RD A0 // LCD Read goes to Analog 0 17 | 18 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 19 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 20 | // D0 connects to digital pin 8 (Notice these are 21 | // D1 connects to digital pin 9 NOT in order!) 22 | // D2 connects to digital pin 2 23 | // D3 connects to digital pin 3 24 | // D4 connects to digital pin 4 25 | // D5 connects to digital pin 5 26 | // D6 connects to digital pin 6 27 | // D7 connects to digital pin 7 28 | // For the Arduino Mega, use digital pins 22 through 29 29 | // (on the 2-row header at the end of the board). 30 | 31 | // For Arduino Uno/Duemilanove, etc 32 | // connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard) 33 | // Then pin 10 goes to CS (or whatever you have set up) 34 | #define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library) 35 | 36 | // In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) 37 | // There are examples in the sketch folder 38 | 39 | // our TFT wiring 40 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4); 41 | 42 | void setup() 43 | { 44 | Serial.begin(9600); 45 | digitalWrite(35, HIGH); //I use this on mega for LCD Backlight 46 | tft.reset(); 47 | 48 | uint16_t identifier = tft.readID(); 49 | 50 | if(identifier == 0x9325) { 51 | progmemPrintln(PSTR("Found ILI9325 LCD driver")); 52 | } else if(identifier == 0x9328) { 53 | progmemPrintln(PSTR("Found ILI9328 LCD driver")); 54 | } else if(identifier == 0x7575) { 55 | progmemPrintln(PSTR("Found HX8347G LCD driver")); 56 | } else { 57 | progmemPrint(PSTR("Unknown LCD driver chip: ")); 58 | Serial.println(identifier, HEX); 59 | progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 60 | progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 61 | progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h).")); 62 | progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!")); 63 | progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring")); 64 | progmemPrintln(PSTR("matches the tutorial.")); 65 | return; 66 | } 67 | 68 | tft.begin(identifier); 69 | 70 | progmemPrint(PSTR("Initializing SD card...")); 71 | if (!SD.begin(SD_CS)) { 72 | progmemPrintln(PSTR("failed!")); 73 | return; 74 | } 75 | progmemPrintln(PSTR("OK!")); 76 | 77 | bmpDraw("woof.bmp", 0, 0); 78 | delay(1000); 79 | } 80 | 81 | void loop() 82 | { 83 | for(int i = 0; i<4; i++) { 84 | tft.setRotation(i); 85 | tft.fillScreen(0); 86 | for(int j=0; j <= 200; j += 50) { 87 | bmpDraw("miniwoof.bmp", j, j); 88 | } 89 | delay(1000); 90 | } 91 | } 92 | 93 | // This function opens a Windows Bitmap (BMP) file and 94 | // displays it at the given coordinates. It's sped up 95 | // by reading many pixels worth of data at a time 96 | // (rather than pixel by pixel). Increasing the buffer 97 | // size takes more of the Arduino's precious RAM but 98 | // makes loading a little faster. 20 pixels seems a 99 | // good balance. 100 | 101 | #define BUFFPIXEL 20 102 | 103 | void bmpDraw(char *filename, int x, int y) { 104 | 105 | File bmpFile; 106 | int bmpWidth, bmpHeight; // W+H in pixels 107 | uint8_t bmpDepth; // Bit depth (currently must be 24) 108 | uint32_t bmpImageoffset; // Start of image data in file 109 | uint32_t rowSize; // Not always = bmpWidth; may have padding 110 | uint8_t sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel) 111 | uint16_t lcdbuffer[BUFFPIXEL]; // pixel out buffer (16-bit per pixel) 112 | uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer 113 | boolean goodBmp = false; // Set to true on valid header parse 114 | boolean flip = true; // BMP is stored bottom-to-top 115 | int w, h, row, col; 116 | uint8_t r, g, b; 117 | uint32_t pos = 0, startTime = millis(); 118 | uint8_t lcdidx = 0; 119 | boolean first = true; 120 | 121 | if((x >= tft.width()) || (y >= tft.height())) return; 122 | 123 | Serial.println(); 124 | progmemPrint(PSTR("Loading image '")); 125 | Serial.print(filename); 126 | Serial.println('\''); 127 | // Open requested file on SD card 128 | if ((bmpFile = SD.open(filename)) == NULL) { 129 | progmemPrintln(PSTR("File not found")); 130 | return; 131 | } 132 | 133 | // Parse BMP header 134 | if(read16(bmpFile) == 0x4D42) { // BMP signature 135 | progmemPrint(PSTR("File size: ")); Serial.println(read32(bmpFile)); 136 | (void)read32(bmpFile); // Read & ignore creator bytes 137 | bmpImageoffset = read32(bmpFile); // Start of image data 138 | progmemPrint(PSTR("Image Offset: ")); Serial.println(bmpImageoffset, DEC); 139 | // Read DIB header 140 | progmemPrint(PSTR("Header size: ")); Serial.println(read32(bmpFile)); 141 | bmpWidth = read32(bmpFile); 142 | bmpHeight = read32(bmpFile); 143 | if(read16(bmpFile) == 1) { // # planes -- must be '1' 144 | bmpDepth = read16(bmpFile); // bits per pixel 145 | progmemPrint(PSTR("Bit Depth: ")); Serial.println(bmpDepth); 146 | if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed 147 | 148 | goodBmp = true; // Supported BMP format -- proceed! 149 | progmemPrint(PSTR("Image size: ")); 150 | Serial.print(bmpWidth); 151 | Serial.print('x'); 152 | Serial.println(bmpHeight); 153 | 154 | // BMP rows are padded (if needed) to 4-byte boundary 155 | rowSize = (bmpWidth * 3 + 3) & ~3; 156 | 157 | // If bmpHeight is negative, image is in top-down order. 158 | // This is not canon but has been observed in the wild. 159 | if(bmpHeight < 0) { 160 | bmpHeight = -bmpHeight; 161 | flip = false; 162 | } 163 | 164 | // Crop area to be loaded 165 | w = bmpWidth; 166 | h = bmpHeight; 167 | if((x+w-1) >= tft.width()) w = tft.width() - x; 168 | if((y+h-1) >= tft.height()) h = tft.height() - y; 169 | 170 | // Set TFT address window to clipped image bounds 171 | tft.setAddrWindow(x, y, x+w-1, y+h-1); 172 | 173 | for (row=0; row= sizeof(sdbuffer)) { // Indeed 192 | // Push LCD buffer to the display first 193 | if(lcdidx > 0) { 194 | tft.pushColors(lcdbuffer, lcdidx, first); 195 | lcdidx = 0; 196 | first = false; 197 | } 198 | bmpFile.read(sdbuffer, sizeof(sdbuffer)); 199 | buffidx = 0; // Set index to beginning 200 | } 201 | 202 | // Convert pixel from BMP to TFT format 203 | b = sdbuffer[buffidx++]; 204 | g = sdbuffer[buffidx++]; 205 | r = sdbuffer[buffidx++]; 206 | lcdbuffer[lcdidx++] = tft.color565(r,g,b); 207 | } // end pixel 208 | } // end scanline 209 | // Write any remaining data to LCD 210 | if(lcdidx > 0) { 211 | tft.pushColors(lcdbuffer, lcdidx, first); 212 | } 213 | progmemPrint(PSTR("Loaded in ")); 214 | Serial.print(millis() - startTime); 215 | Serial.println(" ms"); 216 | } // end goodBmp 217 | } 218 | } 219 | 220 | bmpFile.close(); 221 | if(!goodBmp) progmemPrintln(PSTR("BMP format not recognized.")); 222 | } 223 | 224 | // These read 16- and 32-bit types from the SD card file. 225 | // BMP data is stored little-endian, Arduino is little-endian too. 226 | // May need to reverse subscript order if porting elsewhere. 227 | 228 | uint16_t read16(File f) { 229 | uint16_t result; 230 | ((uint8_t *)&result)[0] = f.read(); // LSB 231 | ((uint8_t *)&result)[1] = f.read(); // MSB 232 | return result; 233 | } 234 | 235 | uint32_t read32(File f) { 236 | uint32_t result; 237 | ((uint8_t *)&result)[0] = f.read(); // LSB 238 | ((uint8_t *)&result)[1] = f.read(); 239 | ((uint8_t *)&result)[2] = f.read(); 240 | ((uint8_t *)&result)[3] = f.read(); // MSB 241 | return result; 242 | } 243 | 244 | // Copy string from flash to serial port 245 | // Source string MUST be inside a PSTR() declaration! 246 | void progmemPrint(const char *str) { 247 | char c; 248 | while(c = pgm_read_byte(str++)) Serial.print(c); 249 | } 250 | 251 | // Same as above, with trailing newline 252 | void progmemPrintln(const char *str) { 253 | progmemPrint(str); 254 | Serial.println(); 255 | } 256 | 257 | -------------------------------------------------------------------------------- /SPFD5408/examples/spfd5408_tftbmp/spfd5408_tftbmp.ino: -------------------------------------------------------------------------------- 1 | // BMP-loading example specifically for the TFTLCD breakout board. 2 | // If using the Arduino shield, use the tftbmp_shield.pde sketch instead! 3 | // If using an Arduino Mega, make sure the SD library is configured for 4 | // 'soft' SPI in the file Sd2Card.h. 5 | 6 | /////// ***** Not Tested yet on SPFD5408 - next version I do it 7 | 8 | #include // Core graphics library 9 | #include // Hardware-specific library 10 | #include 11 | 12 | // The control pins for the LCD can be assigned to any digital or 13 | // analog pins...but we'll use the analog pins as this allows us to 14 | // double up the pins with the touch screen (see the TFT paint example). 15 | #define LCD_CS A3 // Chip Select goes to Analog 3 16 | #define LCD_CD A2 // Command/Data goes to Analog 2 17 | #define LCD_WR A1 // LCD Write goes to Analog 1 18 | #define LCD_RD A0 // LCD Read goes to Analog 0 19 | 20 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 21 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 22 | // D0 connects to digital pin 8 (Notice these are 23 | // D1 connects to digital pin 9 NOT in order!) 24 | // D2 connects to digital pin 2 25 | // D3 connects to digital pin 3 26 | // D4 connects to digital pin 4 27 | // D5 connects to digital pin 5 28 | // D6 connects to digital pin 6 29 | // D7 connects to digital pin 7 30 | // For the Arduino Mega, use digital pins 22 through 29 31 | // (on the 2-row header at the end of the board). 32 | 33 | // For Arduino Uno/Duemilanove, etc 34 | // connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard) 35 | // Then pin 10 goes to CS (or whatever you have set up) 36 | #define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library) 37 | 38 | // In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) 39 | // There are examples in the sketch folder 40 | 41 | // our TFT wiring 42 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4); 43 | 44 | void setup() 45 | { 46 | Serial.begin(9600); 47 | digitalWrite(35, HIGH); //I use this on mega for LCD Backlight 48 | tft.reset(); 49 | 50 | uint16_t identifier = tft.readID(); 51 | 52 | if(identifier == 0x9325) { 53 | progmemPrintln(PSTR("Found ILI9325 LCD driver")); 54 | } else if(identifier == 0x9328) { 55 | progmemPrintln(PSTR("Found ILI9328 LCD driver")); 56 | } else if(identifier == 0x7575) { 57 | progmemPrintln(PSTR("Found HX8347G LCD driver")); 58 | } else { 59 | progmemPrint(PSTR("Unknown LCD driver chip: ")); 60 | Serial.println(identifier, HEX); 61 | progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 62 | progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 63 | progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h).")); 64 | progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!")); 65 | progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring")); 66 | progmemPrintln(PSTR("matches the tutorial.")); 67 | return; 68 | } 69 | 70 | tft.begin(identifier); 71 | 72 | progmemPrint(PSTR("Initializing SD card...")); 73 | if (!SD.begin(SD_CS)) { 74 | progmemPrintln(PSTR("failed!")); 75 | return; 76 | } 77 | progmemPrintln(PSTR("OK!")); 78 | 79 | bmpDraw("woof.bmp", 0, 0); 80 | delay(1000); 81 | } 82 | 83 | void loop() 84 | { 85 | for(int i = 0; i<4; i++) { 86 | tft.setRotation(i); 87 | tft.fillScreen(0); 88 | for(int j=0; j <= 200; j += 50) { 89 | bmpDraw("miniwoof.bmp", j, j); 90 | } 91 | delay(1000); 92 | } 93 | } 94 | 95 | // This function opens a Windows Bitmap (BMP) file and 96 | // displays it at the given coordinates. It's sped up 97 | // by reading many pixels worth of data at a time 98 | // (rather than pixel by pixel). Increasing the buffer 99 | // size takes more of the Arduino's precious RAM but 100 | // makes loading a little faster. 20 pixels seems a 101 | // good balance. 102 | 103 | #define BUFFPIXEL 20 104 | 105 | void bmpDraw(char *filename, int x, int y) { 106 | 107 | File bmpFile; 108 | int bmpWidth, bmpHeight; // W+H in pixels 109 | uint8_t bmpDepth; // Bit depth (currently must be 24) 110 | uint32_t bmpImageoffset; // Start of image data in file 111 | uint32_t rowSize; // Not always = bmpWidth; may have padding 112 | uint8_t sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel) 113 | uint16_t lcdbuffer[BUFFPIXEL]; // pixel out buffer (16-bit per pixel) 114 | uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer 115 | boolean goodBmp = false; // Set to true on valid header parse 116 | boolean flip = true; // BMP is stored bottom-to-top 117 | int w, h, row, col; 118 | uint8_t r, g, b; 119 | uint32_t pos = 0, startTime = millis(); 120 | uint8_t lcdidx = 0; 121 | boolean first = true; 122 | 123 | if((x >= tft.width()) || (y >= tft.height())) return; 124 | 125 | Serial.println(); 126 | progmemPrint(PSTR("Loading image '")); 127 | Serial.print(filename); 128 | Serial.println('\''); 129 | // Open requested file on SD card 130 | if ((bmpFile = SD.open(filename)) == NULL) { 131 | progmemPrintln(PSTR("File not found")); 132 | return; 133 | } 134 | 135 | // Parse BMP header 136 | if(read16(bmpFile) == 0x4D42) { // BMP signature 137 | progmemPrint(PSTR("File size: ")); Serial.println(read32(bmpFile)); 138 | (void)read32(bmpFile); // Read & ignore creator bytes 139 | bmpImageoffset = read32(bmpFile); // Start of image data 140 | progmemPrint(PSTR("Image Offset: ")); Serial.println(bmpImageoffset, DEC); 141 | // Read DIB header 142 | progmemPrint(PSTR("Header size: ")); Serial.println(read32(bmpFile)); 143 | bmpWidth = read32(bmpFile); 144 | bmpHeight = read32(bmpFile); 145 | if(read16(bmpFile) == 1) { // # planes -- must be '1' 146 | bmpDepth = read16(bmpFile); // bits per pixel 147 | progmemPrint(PSTR("Bit Depth: ")); Serial.println(bmpDepth); 148 | if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed 149 | 150 | goodBmp = true; // Supported BMP format -- proceed! 151 | progmemPrint(PSTR("Image size: ")); 152 | Serial.print(bmpWidth); 153 | Serial.print('x'); 154 | Serial.println(bmpHeight); 155 | 156 | // BMP rows are padded (if needed) to 4-byte boundary 157 | rowSize = (bmpWidth * 3 + 3) & ~3; 158 | 159 | // If bmpHeight is negative, image is in top-down order. 160 | // This is not canon but has been observed in the wild. 161 | if(bmpHeight < 0) { 162 | bmpHeight = -bmpHeight; 163 | flip = false; 164 | } 165 | 166 | // Crop area to be loaded 167 | w = bmpWidth; 168 | h = bmpHeight; 169 | if((x+w-1) >= tft.width()) w = tft.width() - x; 170 | if((y+h-1) >= tft.height()) h = tft.height() - y; 171 | 172 | // Set TFT address window to clipped image bounds 173 | tft.setAddrWindow(x, y, x+w-1, y+h-1); 174 | 175 | for (row=0; row= sizeof(sdbuffer)) { // Indeed 194 | // Push LCD buffer to the display first 195 | if(lcdidx > 0) { 196 | tft.pushColors(lcdbuffer, lcdidx, first); 197 | lcdidx = 0; 198 | first = false; 199 | } 200 | bmpFile.read(sdbuffer, sizeof(sdbuffer)); 201 | buffidx = 0; // Set index to beginning 202 | } 203 | 204 | // Convert pixel from BMP to TFT format 205 | b = sdbuffer[buffidx++]; 206 | g = sdbuffer[buffidx++]; 207 | r = sdbuffer[buffidx++]; 208 | lcdbuffer[lcdidx++] = tft.color565(r,g,b); 209 | } // end pixel 210 | } // end scanline 211 | // Write any remaining data to LCD 212 | if(lcdidx > 0) { 213 | tft.pushColors(lcdbuffer, lcdidx, first); 214 | } 215 | progmemPrint(PSTR("Loaded in ")); 216 | Serial.print(millis() - startTime); 217 | Serial.println(" ms"); 218 | } // end goodBmp 219 | } 220 | } 221 | 222 | bmpFile.close(); 223 | if(!goodBmp) progmemPrintln(PSTR("BMP format not recognized.")); 224 | } 225 | 226 | // These read 16- and 32-bit types from the SD card file. 227 | // BMP data is stored little-endian, Arduino is little-endian too. 228 | // May need to reverse subscript order if porting elsewhere. 229 | 230 | uint16_t read16(File f) { 231 | uint16_t result; 232 | ((uint8_t *)&result)[0] = f.read(); // LSB 233 | ((uint8_t *)&result)[1] = f.read(); // MSB 234 | return result; 235 | } 236 | 237 | uint32_t read32(File f) { 238 | uint32_t result; 239 | ((uint8_t *)&result)[0] = f.read(); // LSB 240 | ((uint8_t *)&result)[1] = f.read(); 241 | ((uint8_t *)&result)[2] = f.read(); 242 | ((uint8_t *)&result)[3] = f.read(); // MSB 243 | return result; 244 | } 245 | 246 | // Copy string from flash to serial port 247 | // Source string MUST be inside a PSTR() declaration! 248 | void progmemPrint(const char *str) { 249 | char c; 250 | while(c = pgm_read_byte(str++)) Serial.print(c); 251 | } 252 | 253 | // Same as above, with trailing newline 254 | void progmemPrintln(const char *str) { 255 | progmemPrint(str); 256 | Serial.println(); 257 | } 258 | 259 | -------------------------------------------------------------------------------- /SPFD5408/examples/spfd5408_calibrate/spfd5408_calibrate.ino: -------------------------------------------------------------------------------- 1 | /////////////// 2 | // Sketch: Calibrate - Calibrate TFT SPFD5408 Touch 3 | // Author: Joao Lopes F. - joaolopesf@gmail.com 4 | // 5 | // Versions: 6 | // - 0.9.0 First beta - July 2015 7 | // - 0.9.1 Rotation for Mega 8 | // Comments: 9 | // Show the calibration parameters to put in your code 10 | // Please use a small like the eraser on a pencil for best results 11 | // 12 | // Code for buttons, based on Adafruit arduin_o_phone example 13 | /////////////// 14 | 15 | // library SPFD5408 16 | 17 | #include // Core graphics library 18 | #include // Hardware-specific library 19 | #include // Touch library 20 | 21 | // Calibrates value 22 | #define SENSIBILITY 300 23 | #define MINPRESSURE 10 24 | #define MAXPRESSURE 1000 25 | 26 | //These are the pins for the shield! 27 | #define YP A1 28 | #define XM A2 29 | #define YM 7 30 | #define XP 6 31 | 32 | /* 33 | //Macros replaced by variables 34 | #define TS_MINX 150 35 | #define TS_MINY 120 36 | #define TS_MAXX 920 37 | #define TS_MAXY 940 38 | */ 39 | short TS_MINX=150; 40 | short TS_MINY=120; 41 | short TS_MAXX=920; 42 | short TS_MAXY=940; 43 | 44 | // Init TouchScreen: 45 | 46 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, SENSIBILITY); 47 | 48 | // LCD Pin 49 | 50 | #define LCD_CS A3 51 | #define LCD_CD A2 52 | #define LCD_WR A1 53 | #define LCD_RD A0 54 | #define LCD_RESET A4 // Optional : otherwise connect to Arduino's reset pin 55 | 56 | // Assign human-readable names to some common 16-bit color values: 57 | #define BLACK 0x0000 58 | #define BLUE 0x001F 59 | #define RED 0xF800 60 | #define GREEN 0x07E0 61 | #define CYAN 0x07FF 62 | #define MAGENTA 0xF81F 63 | #define YELLOW 0xFFE0 64 | #define WHITE 0xFFFF 65 | 66 | // Init LCD 67 | 68 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 69 | 70 | // Dimensions 71 | 72 | uint16_t width = 0; 73 | uint16_t height = 0; 74 | 75 | // Buttons 76 | 77 | #define BUTTONS 3 78 | #define BUTTON_CLEAR 0 79 | #define BUTTON_SHOW 1 80 | #define BUTTON_RESET 2 81 | 82 | Adafruit_GFX_Button buttons[BUTTONS]; 83 | 84 | uint16_t buttons_y = 0; 85 | 86 | //-- Setup 87 | 88 | void setup(void) { 89 | 90 | // Serial por for debug, not works if shield is plugged in arduino 91 | 92 | // Serial.begin(9600); 93 | 94 | // Inicialize the controller 95 | 96 | tft.reset(); 97 | 98 | tft.begin(0x9341); 99 | 100 | tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial 101 | 102 | width = tft.width() - 1; 103 | height = tft.height() - 1; 104 | 105 | // Debug 106 | 107 | // Serial.println(F("TFT LCD test")); 108 | // Serial.print("TFT size is "); 109 | // Serial.print(tft.width()); 110 | // Serial.print("x"); 111 | // Serial.println(tft.height()); 112 | 113 | // UI 114 | 115 | initializeButtons(); 116 | 117 | // Border 118 | 119 | drawBorder(); 120 | 121 | // Initial screen 122 | 123 | tft.setCursor (55, 50); 124 | tft.setTextSize (3); 125 | tft.setTextColor(RED); 126 | tft.println("SPFD5408"); 127 | tft.setCursor (65, 85); 128 | tft.println("Library"); 129 | tft.setCursor (55, 150); 130 | tft.setTextSize (2); 131 | tft.setTextColor(BLACK); 132 | tft.println("Calibration"); 133 | 134 | tft.setCursor (80, 250); 135 | tft.setTextSize (1); 136 | tft.setTextColor(BLACK); 137 | tft.println("Touch to proceed"); 138 | 139 | // Wait touch 140 | 141 | waitOneTouch(); 142 | 143 | // Calibrate it 144 | 145 | calibrate_TS(); 146 | 147 | // Wait touch 148 | 149 | waitOneTouch(); 150 | 151 | // Calibration 152 | 153 | showCalibration(); 154 | 155 | } 156 | 157 | // -- Loop 158 | 159 | void loop() 160 | { 161 | // Test of calibration 162 | 163 | TSPoint p; 164 | 165 | // Wait a touch 166 | 167 | digitalWrite(13, HIGH); 168 | 169 | p = waitOneTouch(); 170 | 171 | digitalWrite(13, LOW); 172 | 173 | // Map of values 174 | 175 | // p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width()); 176 | // p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height()); 177 | 178 | p.x = mapXValue(p); 179 | p.y = mapYValue(p); 180 | 181 | // Draw a point 182 | 183 | tft.fillCircle(p.x, p.y, 3, BLUE); 184 | 185 | // Show touch screen point (TSPOINT) 186 | 187 | showTouched(p); 188 | 189 | // Buttons 190 | 191 | // Go thru all the buttons, checking if they were pressed 192 | 193 | for (uint8_t b=0; b (width - limit) && mapYValue(p2) > (height - limit))); 279 | 280 | tft.fillScreen(BLACK); 281 | 282 | delay (300); 283 | 284 | temp=p2.x-p1.x; // Calculate the new coefficients, get X difference 285 | tempL=((long)temp*1024)/(tft.width()-20); 286 | TS_MINX=p1.x-( (tempL*10)>>10);// 10 pixels du bord 287 | TS_MAXX=p1.x+( (tempL*tft.width())>>10);// 220 pixels entre points 288 | temp=p2.y-p1.y; // ¨get Y difference 289 | tempL=((long)temp*1024)/(tft.height()-20); 290 | TS_MINY=p1.y-( (tempL*10)>>10);// 10 pixels du bord 291 | TS_MAXY=TS_MINY+( (tempL*tft.height())>>10); 292 | 293 | // Show results 294 | 295 | showResults(); 296 | 297 | // p1.x = map(p1.x, TS_MAXX,TS_MINX, tft.width(), 0); 298 | // p1.y = map(p1.y, TS_MAXY,TS_MINY, tft.height(), 0); 299 | // p2.x = map(p2.x, TS_MAXX,TS_MINX, tft.width(), 0); 300 | // p2.y = map(p2.y, TS_MAXY,TS_MINY, tft.height(), 0); 301 | 302 | p1.x = mapXValue(p1); 303 | p1.y = mapYValue(p1); 304 | p2.x = mapXValue(p2); 305 | p2.y = mapYValue(p2); 306 | 307 | tft.println(); 308 | tft.println("Last touched points: "); 309 | tft.print("Pt 1: ");tft.print(p1.x);tft.print(" : ");tft.println(p1.y); 310 | tft.print("Pt 2: ");tft.print(p2.x);tft.print(" : ");tft.println(p2.y); 311 | 312 | tft.println(); 313 | 314 | // Wait a touch 315 | 316 | tft.println("Touch to proceed"); 317 | 318 | waitOneTouch(); 319 | } 320 | // wait 1 touch to return the point 321 | 322 | TSPoint waitOneTouch() { 323 | 324 | TSPoint p; 325 | 326 | do { 327 | p= ts.getPoint(); 328 | 329 | pinMode(XM, OUTPUT); //Pins configures again for TFT control 330 | pinMode(YP, OUTPUT); 331 | 332 | } while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE)); 333 | 334 | return p; 335 | } 336 | 337 | // Draw a border 338 | 339 | void drawBorder () { 340 | 341 | uint16_t width = tft.width() - 1; 342 | uint16_t height = tft.height() - 1; 343 | uint8_t border = 10; 344 | 345 | tft.fillScreen(RED); 346 | tft.fillRect(border, border, (width - border * 2), (height - border * 2), WHITE); 347 | 348 | } 349 | 350 | // Show a screen of calibration 351 | 352 | void showCalibration() { 353 | 354 | // Clear 355 | 356 | tft.fillScreen(BLACK); 357 | tft.setTextSize (1); 358 | 359 | // Header 360 | 361 | tft.fillRect(0, 0, width, 10, RED); 362 | 363 | tft.setCursor (40, 0); 364 | tft.setTextColor(WHITE); 365 | tft.println("*** Test of calibration ***"); 366 | 367 | // Footer 368 | 369 | TSPoint p; // Only for show initial values 370 | p.x=0; 371 | p.y=0; 372 | p.z=0; 373 | 374 | showTouched(p); 375 | 376 | // Buttons 377 | 378 | for (uint8_t i=0; i<3; i++) { 379 | buttons[i].drawButton(); 380 | } 381 | 382 | } 383 | 384 | // Show the coordinates 385 | 386 | void showTouched(TSPoint p) { 387 | 388 | uint8_t w = 40; // Width 389 | uint8_t h = 10; // Heigth 390 | uint8_t x = (width - (w*2)); // X 391 | uint8_t y = 11; // Y 392 | 393 | tft.fillRect(x, y, w*2, h, WHITE); // For cleanup 394 | 395 | tft.drawRect(x, y, w, h, RED); // For X 396 | tft.drawRect(x+w+2, y, w*2, h, RED); // For Y 397 | 398 | tft.setTextColor(BLACK); 399 | tft.setCursor(x+2, y + 1); 400 | tft.print("X: "); 401 | showValue(p.x); 402 | 403 | tft.setCursor(x+2+w+2, y + 1); 404 | tft.print("Y: "); 405 | showValue(p.y); 406 | 407 | } 408 | 409 | // Show a value of TSPoint 410 | 411 | void showValue (uint16_t value) { 412 | 413 | if (value < 10) 414 | tft.print("00"); 415 | if (value < 100) 416 | tft.print("0"); 417 | 418 | tft.print(value); 419 | 420 | } 421 | 422 | // Show results of calibration 423 | 424 | void showResults() { 425 | 426 | tft.fillScreen(BLACK); 427 | 428 | // Header 429 | 430 | tft.fillRect(0, 0, width, 10, RED); 431 | 432 | tft.setCursor (40, 0); 433 | tft.setTextColor(WHITE); 434 | tft.println("*** Results of calibration ***"); 435 | 436 | // Results 437 | 438 | tft.setCursor(5, 30); 439 | tft.setTextSize(2); 440 | tft.println("After calibration: "); 441 | tft.print("TS_MINX= ");tft.println(TS_MINX); 442 | tft.print("TS_MINY= ");tft.println(TS_MINY); 443 | tft.println(); 444 | tft.print("TS_MAXX= ");tft.println(TS_MAXX); 445 | tft.print("TS_MAXY= ");tft.println(TS_MAXY); 446 | 447 | } 448 | 449 | // Initialize buttons 450 | 451 | void initializeButtons() { 452 | 453 | uint16_t x = 40; 454 | uint16_t y = height - 20; 455 | uint16_t w = 75; 456 | uint16_t h = 20; 457 | 458 | uint8_t spacing_x = 5; 459 | 460 | uint8_t textSize = 1; 461 | 462 | char buttonlabels[3][20] = {"Clear", "Show", "Recalib."}; 463 | uint16_t buttoncolors[15] = {RED, BLUE, RED}; 464 | 465 | for (uint8_t b=0; b<3; b++) { 466 | buttons[b].initButton(&tft, // TFT object 467 | x+b*(w+spacing_x), y, // x, y, 468 | w, h, WHITE, buttoncolors[b], WHITE, // w, h, outline, fill, 469 | buttonlabels[b], textSize); // text 470 | } 471 | 472 | // Save the y position to avoid draws 473 | 474 | buttons_y = y; 475 | 476 | } 477 | 478 | // Map the coordinate X 479 | 480 | uint16_t mapXValue(TSPoint p) { 481 | 482 | uint16_t x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width()); 483 | 484 | //Correct offset of touch. Manual calibration 485 | //x+=1; 486 | 487 | return x; 488 | 489 | } 490 | 491 | // Map the coordinate Y 492 | 493 | uint16_t mapYValue(TSPoint p) { 494 | 495 | uint16_t y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height()); 496 | 497 | //Correct offset of touch. Manual calibration 498 | //y-=2; 499 | 500 | return y; 501 | } 502 | 503 | -------------------------------------------------------------------------------- /SPFD5408/examples/adafruit_originals/graphicstest/graphicstest.pde: -------------------------------------------------------------------------------- 1 | // IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY 2 | // CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. 3 | // SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. 4 | 5 | #include // Core graphics library 6 | #include // Hardware-specific library 7 | 8 | // The control pins for the LCD can be assigned to any digital or 9 | // analog pins...but we'll use the analog pins as this allows us to 10 | // double up the pins with the touch screen (see the TFT paint example). 11 | #define LCD_CS A3 // Chip Select goes to Analog 3 12 | #define LCD_CD A2 // Command/Data goes to Analog 2 13 | #define LCD_WR A1 // LCD Write goes to Analog 1 14 | #define LCD_RD A0 // LCD Read goes to Analog 0 15 | 16 | #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin 17 | 18 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 19 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 20 | // D0 connects to digital pin 8 (Notice these are 21 | // D1 connects to digital pin 9 NOT in order!) 22 | // D2 connects to digital pin 2 23 | // D3 connects to digital pin 3 24 | // D4 connects to digital pin 4 25 | // D5 connects to digital pin 5 26 | // D6 connects to digital pin 6 27 | // D7 connects to digital pin 7 28 | // For the Arduino Mega, use digital pins 22 through 29 29 | // (on the 2-row header at the end of the board). 30 | 31 | // Assign human-readable names to some common 16-bit color values: 32 | #define BLACK 0x0000 33 | #define BLUE 0x001F 34 | #define RED 0xF800 35 | #define GREEN 0x07E0 36 | #define CYAN 0x07FF 37 | #define MAGENTA 0xF81F 38 | #define YELLOW 0xFFE0 39 | #define WHITE 0xFFFF 40 | 41 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 42 | // If using the shield, all control and data lines are fixed, and 43 | // a simpler declaration can optionally be used: 44 | // Adafruit_TFTLCD tft; 45 | 46 | void setup(void) { 47 | Serial.begin(9600); 48 | digitalWrite(35, HIGH); //I use this on mega for LCD Backlight 49 | progmemPrintln(PSTR("TFT LCD test")); 50 | 51 | #ifdef USE_ADAFRUIT_SHIELD_PINOUT 52 | progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout")); 53 | #else 54 | progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout")); 55 | #endif 56 | 57 | tft.reset(); 58 | 59 | uint16_t identifier = tft.readID(); 60 | 61 | if(identifier == 0x9325) { 62 | progmemPrintln(PSTR("Found ILI9325 LCD driver")); 63 | } else if(identifier == 0x9328) { 64 | progmemPrintln(PSTR("Found ILI9328 LCD driver")); 65 | } else if(identifier == 0x7575) { 66 | progmemPrintln(PSTR("Found HX8347G LCD driver")); 67 | } else { 68 | progmemPrint(PSTR("Unknown LCD driver chip: ")); 69 | Serial.println(identifier, HEX); 70 | progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 71 | progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 72 | progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h).")); 73 | progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!")); 74 | progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring")); 75 | progmemPrintln(PSTR("matches the tutorial.")); 76 | return; 77 | } 78 | 79 | tft.begin(identifier); 80 | 81 | progmemPrintln(PSTR("Benchmark Time (microseconds)")); 82 | 83 | progmemPrint(PSTR("Screen fill ")); 84 | Serial.println(testFillScreen()); 85 | delay(500); 86 | 87 | progmemPrint(PSTR("Text ")); 88 | Serial.println(testText()); 89 | delay(3000); 90 | 91 | progmemPrint(PSTR("Lines ")); 92 | Serial.println(testLines(CYAN)); 93 | delay(500); 94 | 95 | progmemPrint(PSTR("Horiz/Vert Lines ")); 96 | Serial.println(testFastLines(RED, BLUE)); 97 | delay(500); 98 | 99 | progmemPrint(PSTR("Rectangles (outline) ")); 100 | Serial.println(testRects(GREEN)); 101 | delay(500); 102 | 103 | progmemPrint(PSTR("Rectangles (filled) ")); 104 | Serial.println(testFilledRects(YELLOW, MAGENTA)); 105 | delay(500); 106 | 107 | progmemPrint(PSTR("Circles (filled) ")); 108 | Serial.println(testFilledCircles(10, MAGENTA)); 109 | 110 | progmemPrint(PSTR("Circles (outline) ")); 111 | Serial.println(testCircles(10, WHITE)); 112 | delay(500); 113 | 114 | progmemPrint(PSTR("Triangles (outline) ")); 115 | Serial.println(testTriangles()); 116 | delay(500); 117 | 118 | progmemPrint(PSTR("Triangles (filled) ")); 119 | Serial.println(testFilledTriangles()); 120 | delay(500); 121 | 122 | progmemPrint(PSTR("Rounded rects (outline) ")); 123 | Serial.println(testRoundRects()); 124 | delay(500); 125 | 126 | progmemPrint(PSTR("Rounded rects (filled) ")); 127 | Serial.println(testFilledRoundRects()); 128 | delay(500); 129 | 130 | progmemPrintln(PSTR("Done!")); 131 | } 132 | 133 | void loop(void) { 134 | for(uint8_t rotation=0; rotation<4; rotation++) { 135 | tft.setRotation(rotation); 136 | testText(); 137 | delay(2000); 138 | } 139 | } 140 | 141 | unsigned long testFillScreen() { 142 | unsigned long start = micros(); 143 | tft.fillScreen(BLACK); 144 | tft.fillScreen(RED); 145 | tft.fillScreen(GREEN); 146 | tft.fillScreen(BLUE); 147 | tft.fillScreen(BLACK); 148 | return micros() - start; 149 | } 150 | 151 | unsigned long testText() { 152 | tft.fillScreen(BLACK); 153 | unsigned long start = micros(); 154 | tft.setCursor(0, 0); 155 | tft.setTextColor(WHITE); tft.setTextSize(1); 156 | tft.println("Hello World!"); 157 | tft.setTextColor(YELLOW); tft.setTextSize(2); 158 | tft.println(1234.56); 159 | tft.setTextColor(RED); tft.setTextSize(3); 160 | tft.println(0xDEADBEEF, HEX); 161 | tft.println(); 162 | tft.setTextColor(GREEN); 163 | tft.setTextSize(5); 164 | tft.println("Groop"); 165 | tft.setTextSize(2); 166 | tft.println("I implore thee,"); 167 | tft.setTextSize(1); 168 | tft.println("my foonting turlingdromes."); 169 | tft.println("And hooptiously drangle me"); 170 | tft.println("with crinkly bindlewurdles,"); 171 | tft.println("Or I will rend thee"); 172 | tft.println("in the gobberwarts"); 173 | tft.println("with my blurglecruncheon,"); 174 | tft.println("see if I don't!"); 175 | return micros() - start; 176 | } 177 | 178 | unsigned long testLines(uint16_t color) { 179 | unsigned long start, t; 180 | int x1, y1, x2, y2, 181 | w = tft.width(), 182 | h = tft.height(); 183 | 184 | tft.fillScreen(BLACK); 185 | 186 | x1 = y1 = 0; 187 | y2 = h - 1; 188 | start = micros(); 189 | for(x2=0; x20; i-=6) { 267 | i2 = i / 2; 268 | start = micros(); 269 | tft.fillRect(cx-i2, cy-i2, i, i, color1); 270 | t += micros() - start; 271 | // Outlines are not included in timing results 272 | tft.drawRect(cx-i2, cy-i2, i, i, color2); 273 | } 274 | 275 | return t; 276 | } 277 | 278 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 279 | unsigned long start; 280 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 281 | 282 | tft.fillScreen(BLACK); 283 | start = micros(); 284 | for(x=radius; x10; i-=5) { 338 | start = micros(); 339 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 340 | tft.color565(0, i, i)); 341 | t += micros() - start; 342 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 343 | tft.color565(i, i, 0)); 344 | } 345 | 346 | return t; 347 | } 348 | 349 | unsigned long testRoundRects() { 350 | unsigned long start; 351 | int w, i, i2, 352 | cx = tft.width() / 2 - 1, 353 | cy = tft.height() / 2 - 1; 354 | 355 | tft.fillScreen(BLACK); 356 | w = min(tft.width(), tft.height()); 357 | start = micros(); 358 | for(i=0; i20; i-=6) { 375 | i2 = i / 2; 376 | tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); 377 | } 378 | 379 | return micros() - start; 380 | } 381 | 382 | // Copy string from flash to serial port 383 | // Source string MUST be inside a PSTR() declaration! 384 | void progmemPrint(const char *str) { 385 | char c; 386 | while(c = pgm_read_byte(str++)) Serial.print(c); 387 | } 388 | 389 | // Same as above, with trailing newline 390 | void progmemPrintln(const char *str) { 391 | progmemPrint(str); 392 | Serial.println(); 393 | } 394 | 395 | -------------------------------------------------------------------------------- /SPFD5408/examples/spfd5408_graphicstest/spfd5408_graphicstest.ino: -------------------------------------------------------------------------------- 1 | // IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY 2 | // CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. 3 | // SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. 4 | 5 | // Modified for SPFD5408 Library by Joao Lopes 6 | // Version 0.9.2 - Rotation for Mega and screen initial 7 | 8 | // *** SPFD5408 change -- Begin 9 | #include // Core graphics library 10 | #include // Hardware-specific library 11 | #include 12 | // *** SPFD5408 change -- End 13 | 14 | // The control pins for the LCD can be assigned to any digital or 15 | // analog pins...but we'll use the analog pins as this allows us to 16 | // double up the pins with the touch screen (see the TFT paint example). 17 | #define LCD_CS A3 // Chip Select goes to Analog 3 18 | #define LCD_CD A2 // Command/Data goes to Analog 2 19 | #define LCD_WR A1 // LCD Write goes to Analog 1 20 | #define LCD_RD A0 // LCD Read goes to Analog 0 21 | 22 | #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin 23 | 24 | // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: 25 | // For the Arduino Uno, Duemilanove, Diecimila, etc.: 26 | // D0 connects to digital pin 8 (Notice these are 27 | // D1 connects to digital pin 9 NOT in order!) 28 | // D2 connects to digital pin 2 29 | // D3 connects to digital pin 3 30 | // D4 connects to digital pin 4 31 | // D5 connects to digital pin 5 32 | // D6 connects to digital pin 6 33 | // D7 connects to digital pin 7 34 | // For the Arduino Mega, use digital pins 22 through 29 35 | // (on the 2-row header at the end of the board). 36 | 37 | // Assign human-readable names to some common 16-bit color values: 38 | #define BLACK 0x0000 39 | #define BLUE 0x001F 40 | #define RED 0xF800 41 | #define GREEN 0x07E0 42 | #define CYAN 0x07FF 43 | #define MAGENTA 0xF81F 44 | #define YELLOW 0xFFE0 45 | #define WHITE 0xFFFF 46 | 47 | Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); 48 | // If using the shield, all control and data lines are fixed, and 49 | // a simpler declaration can optionally be used: 50 | // Adafruit_TFTLCD tft; 51 | 52 | // -- Setup 53 | 54 | void setup(void) { 55 | 56 | Serial.begin(9600); 57 | 58 | progmemPrintln(PSTR("TFT LCD test")); 59 | 60 | #ifdef USE_ADAFRUIT_SHIELD_PINOUT 61 | progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout")); 62 | #else 63 | progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout")); 64 | #endif 65 | 66 | tft.reset(); 67 | 68 | // *** SPFD5408 change -- Begin 69 | 70 | // Original code commented 71 | 72 | // uint16_t identifier = tft.readID(); 73 | // 74 | // if(identifier == 0x9325) { 75 | // Serial.println(F("Found ILI9325 LCD driver")); 76 | // } else if(identifier == 0x9328) { 77 | // Serial.println(F("Found ILI9328 LCD driver")); 78 | // } else if(identifier == 0x7575) { 79 | // Serial.println(F("Found HX8347G LCD driver")); 80 | // } else if(identifier == 0x9341) { 81 | // Serial.println(F("Found ILI9341 LCD driver")); 82 | // } else if(identifier == 0x8357) { 83 | // Serial.println(F("Found HX8357D LCD driver")); 84 | // } else { 85 | // Serial.print(F("Unknown LCD driver chip: ")); 86 | // Serial.println(identifier, HEX); 87 | // Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); 88 | // Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT")); 89 | // Serial.println(F("should appear in the library header (Adafruit_TFT.h).")); 90 | // Serial.println(F("If using the breakout board, it should NOT be #defined!")); 91 | // Serial.println(F("Also if using the breakout, double-check that all wiring")); 92 | // Serial.println(F("matches the tutorial.")); 93 | // return; 94 | // } 95 | // 96 | // tft.begin(identifier); 97 | 98 | // Code changed to works 99 | 100 | tft.begin(0x9341); // SDFP5408 101 | 102 | tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial 103 | 104 | // *** SPFD5408 change -- End 105 | 106 | progmemPrintln(PSTR("Benchmark Time (microseconds)")); 107 | 108 | progmemPrint(PSTR("Screen fill ")); 109 | Serial.println(testFillScreen()); 110 | delay(500); 111 | 112 | progmemPrint(PSTR("Text ")); 113 | Serial.println(testText()); 114 | delay(3000); 115 | 116 | progmemPrint(PSTR("Lines ")); 117 | Serial.println(testLines(CYAN)); 118 | delay(500); 119 | 120 | progmemPrint(PSTR("Horiz/Vert Lines ")); 121 | Serial.println(testFastLines(RED, BLUE)); 122 | delay(500); 123 | 124 | progmemPrint(PSTR("Rectangles (outline) ")); 125 | Serial.println(testRects(GREEN)); 126 | delay(500); 127 | 128 | progmemPrint(PSTR("Rectangles (filled) ")); 129 | Serial.println(testFilledRects(YELLOW, MAGENTA)); 130 | delay(500); 131 | 132 | progmemPrint(PSTR("Circles (filled) ")); 133 | Serial.println(testFilledCircles(10, MAGENTA)); 134 | 135 | progmemPrint(PSTR("Circles (outline) ")); 136 | Serial.println(testCircles(10, WHITE)); 137 | delay(500); 138 | 139 | progmemPrint(PSTR("Triangles (outline) ")); 140 | Serial.println(testTriangles()); 141 | delay(500); 142 | 143 | progmemPrint(PSTR("Triangles (filled) ")); 144 | Serial.println(testFilledTriangles()); 145 | delay(500); 146 | 147 | progmemPrint(PSTR("Rounded rects (outline) ")); 148 | Serial.println(testRoundRects()); 149 | delay(500); 150 | 151 | progmemPrint(PSTR("Rounded rects (filled) ")); 152 | Serial.println(testFilledRoundRects()); 153 | delay(500); 154 | 155 | progmemPrintln(PSTR("Done!")); 156 | } 157 | 158 | void loop(void) { 159 | for(uint8_t rotation=0; rotation<4; rotation++) { 160 | tft.setRotation(rotation); 161 | testText(); 162 | delay(2000); 163 | } 164 | } 165 | 166 | unsigned long testFillScreen() { 167 | unsigned long start = micros(); 168 | tft.fillScreen(BLACK); 169 | tft.fillScreen(RED); 170 | tft.fillScreen(GREEN); 171 | tft.fillScreen(BLUE); 172 | tft.fillScreen(BLACK); 173 | return micros() - start; 174 | } 175 | 176 | unsigned long testText() { 177 | tft.fillScreen(BLACK); 178 | unsigned long start = micros(); 179 | tft.setCursor(0, 0); 180 | tft.setTextColor(WHITE); tft.setTextSize(1); 181 | tft.println("Hello World!"); 182 | tft.setTextColor(YELLOW); tft.setTextSize(2); 183 | tft.println(1234.56); 184 | tft.setTextColor(RED); tft.setTextSize(3); 185 | tft.println(0xDEADBEEF, HEX); 186 | tft.println(); 187 | tft.setTextColor(GREEN); 188 | tft.setTextSize(5); 189 | tft.println("Groop"); 190 | tft.setTextSize(2); 191 | tft.println("I implore thee,"); 192 | tft.setTextSize(1); 193 | tft.println("my foonting turlingdromes."); 194 | tft.println("And hooptiously drangle me"); 195 | tft.println("with crinkly bindlewurdles,"); 196 | tft.println("Or I will rend thee"); 197 | tft.println("in the gobberwarts"); 198 | tft.println("with my blurglecruncheon,"); 199 | tft.println("see if I don't!"); 200 | return micros() - start; 201 | } 202 | 203 | unsigned long testLines(uint16_t color) { 204 | unsigned long start, t; 205 | int x1, y1, x2, y2, 206 | w = tft.width(), 207 | h = tft.height(); 208 | 209 | tft.fillScreen(BLACK); 210 | 211 | x1 = y1 = 0; 212 | y2 = h - 1; 213 | start = micros(); 214 | for(x2=0; x20; i-=6) { 292 | i2 = i / 2; 293 | start = micros(); 294 | tft.fillRect(cx-i2, cy-i2, i, i, color1); 295 | t += micros() - start; 296 | // Outlines are not included in timing results 297 | tft.drawRect(cx-i2, cy-i2, i, i, color2); 298 | } 299 | 300 | return t; 301 | } 302 | 303 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) { 304 | unsigned long start; 305 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; 306 | 307 | tft.fillScreen(BLACK); 308 | start = micros(); 309 | for(x=radius; x10; i-=5) { 363 | start = micros(); 364 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 365 | tft.color565(0, i, i)); 366 | t += micros() - start; 367 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, 368 | tft.color565(i, i, 0)); 369 | } 370 | 371 | return t; 372 | } 373 | 374 | unsigned long testRoundRects() { 375 | unsigned long start; 376 | int w, i, i2, 377 | cx = tft.width() / 2 - 1, 378 | cy = tft.height() / 2 - 1; 379 | 380 | tft.fillScreen(BLACK); 381 | w = min(tft.width(), tft.height()); 382 | start = micros(); 383 | for(i=0; i20; i-=6) { 400 | i2 = i / 2; 401 | tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); 402 | } 403 | 404 | return micros() - start; 405 | } 406 | 407 | // Copy string from flash to serial port 408 | // Source string MUST be inside a PSTR() declaration! 409 | void progmemPrint(const char *str) { 410 | char c; 411 | while(c = pgm_read_byte(str++)) Serial.print(c); 412 | } 413 | 414 | // Same as above, with trailing newline 415 | void progmemPrintln(const char *str) { 416 | progmemPrint(str); 417 | Serial.println(); 418 | } 419 | 420 | -------------------------------------------------------------------------------- /SPFD5408/SPFD5408_Adafruit_GFX.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This is the core graphics library for all our displays, providing a common 3 | set of graphics primitives (points, lines, circles, etc.). It needs to be 4 | paired with a hardware-specific library for each display device we carry 5 | (to handle the lower-level functions). 6 | 7 | Adafruit invests time and resources providing this open source code, please 8 | support Adafruit & open-source hardware by purchasing products from Adafruit! 9 | 10 | Copyright (c) 2013 Adafruit Industries. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | // Modified for SPFD5408 by Joao Lopes to work with SPFD5408 35 | 36 | // *** SPFD5408 change -- Begin 37 | #include 38 | // *** SPFD5408 change -- End 39 | 40 | #include "glcdfont.c" 41 | #ifdef __AVR__ 42 | #include 43 | #elif defined(ESP8266) 44 | #include 45 | #else 46 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 47 | #endif 48 | 49 | #ifndef min 50 | #define min(a,b) ((a < b) ? a : b) 51 | #endif 52 | 53 | Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h): 54 | WIDTH(w), HEIGHT(h) 55 | { 56 | _width = WIDTH; 57 | _height = HEIGHT; 58 | rotation = 0; 59 | cursor_y = cursor_x = 0; 60 | textsize = 1; 61 | textcolor = textbgcolor = 0xFFFF; 62 | wrap = true; 63 | _cp437 = false; 64 | } 65 | 66 | // Draw a circle outline 67 | void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, 68 | uint16_t color) { 69 | int16_t f = 1 - r; 70 | int16_t ddF_x = 1; 71 | int16_t ddF_y = -2 * r; 72 | int16_t x = 0; 73 | int16_t y = r; 74 | 75 | drawPixel(x0 , y0+r, color); 76 | drawPixel(x0 , y0-r, color); 77 | drawPixel(x0+r, y0 , color); 78 | drawPixel(x0-r, y0 , color); 79 | 80 | while (x= 0) { 82 | y--; 83 | ddF_y += 2; 84 | f += ddF_y; 85 | } 86 | x++; 87 | ddF_x += 2; 88 | f += ddF_x; 89 | 90 | drawPixel(x0 + x, y0 + y, color); 91 | drawPixel(x0 - x, y0 + y, color); 92 | drawPixel(x0 + x, y0 - y, color); 93 | drawPixel(x0 - x, y0 - y, color); 94 | drawPixel(x0 + y, y0 + x, color); 95 | drawPixel(x0 - y, y0 + x, color); 96 | drawPixel(x0 + y, y0 - x, color); 97 | drawPixel(x0 - y, y0 - x, color); 98 | } 99 | } 100 | 101 | void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, 102 | int16_t r, uint8_t cornername, uint16_t color) { 103 | int16_t f = 1 - r; 104 | int16_t ddF_x = 1; 105 | int16_t ddF_y = -2 * r; 106 | int16_t x = 0; 107 | int16_t y = r; 108 | 109 | while (x= 0) { 111 | y--; 112 | ddF_y += 2; 113 | f += ddF_y; 114 | } 115 | x++; 116 | ddF_x += 2; 117 | f += ddF_x; 118 | if (cornername & 0x4) { 119 | drawPixel(x0 + x, y0 + y, color); 120 | drawPixel(x0 + y, y0 + x, color); 121 | } 122 | if (cornername & 0x2) { 123 | drawPixel(x0 + x, y0 - y, color); 124 | drawPixel(x0 + y, y0 - x, color); 125 | } 126 | if (cornername & 0x8) { 127 | drawPixel(x0 - y, y0 + x, color); 128 | drawPixel(x0 - x, y0 + y, color); 129 | } 130 | if (cornername & 0x1) { 131 | drawPixel(x0 - y, y0 - x, color); 132 | drawPixel(x0 - x, y0 - y, color); 133 | } 134 | } 135 | } 136 | 137 | void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, 138 | uint16_t color) { 139 | drawFastVLine(x0, y0-r, 2*r+1, color); 140 | fillCircleHelper(x0, y0, r, 3, 0, color); 141 | } 142 | 143 | // Used to do circles and roundrects 144 | void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 145 | uint8_t cornername, int16_t delta, uint16_t color) { 146 | 147 | int16_t f = 1 - r; 148 | int16_t ddF_x = 1; 149 | int16_t ddF_y = -2 * r; 150 | int16_t x = 0; 151 | int16_t y = r; 152 | 153 | while (x= 0) { 155 | y--; 156 | ddF_y += 2; 157 | f += ddF_y; 158 | } 159 | x++; 160 | ddF_x += 2; 161 | f += ddF_x; 162 | 163 | if (cornername & 0x1) { 164 | drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); 165 | drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); 166 | } 167 | if (cornername & 0x2) { 168 | drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); 169 | drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); 170 | } 171 | } 172 | } 173 | 174 | // Bresenham's algorithm - thx wikpedia 175 | void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, 176 | int16_t x1, int16_t y1, 177 | uint16_t color) { 178 | int16_t steep = abs(y1 - y0) > abs(x1 - x0); 179 | if (steep) { 180 | swap(x0, y0); 181 | swap(x1, y1); 182 | } 183 | 184 | if (x0 > x1) { 185 | swap(x0, x1); 186 | swap(y0, y1); 187 | } 188 | 189 | int16_t dx, dy; 190 | dx = x1 - x0; 191 | dy = abs(y1 - y0); 192 | 193 | int16_t err = dx / 2; 194 | int16_t ystep; 195 | 196 | if (y0 < y1) { 197 | ystep = 1; 198 | } else { 199 | ystep = -1; 200 | } 201 | 202 | for (; x0<=x1; x0++) { 203 | if (steep) { 204 | drawPixel(y0, x0, color); 205 | } else { 206 | drawPixel(x0, y0, color); 207 | } 208 | err -= dy; 209 | if (err < 0) { 210 | y0 += ystep; 211 | err += dx; 212 | } 213 | } 214 | } 215 | 216 | // Draw a rectangle 217 | void Adafruit_GFX::drawRect(int16_t x, int16_t y, 218 | int16_t w, int16_t h, 219 | uint16_t color) { 220 | drawFastHLine(x, y, w, color); 221 | drawFastHLine(x, y+h-1, w, color); 222 | drawFastVLine(x, y, h, color); 223 | drawFastVLine(x+w-1, y, h, color); 224 | } 225 | 226 | void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, 227 | int16_t h, uint16_t color) { 228 | // Update in subclasses if desired! 229 | drawLine(x, y, x, y+h-1, color); 230 | } 231 | 232 | void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, 233 | int16_t w, uint16_t color) { 234 | // Update in subclasses if desired! 235 | drawLine(x, y, x+w-1, y, color); 236 | } 237 | 238 | void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 239 | uint16_t color) { 240 | // Update in subclasses if desired! 241 | for (int16_t i=x; i= y1 >= y0) 293 | if (y0 > y1) { 294 | swap(y0, y1); swap(x0, x1); 295 | } 296 | if (y1 > y2) { 297 | swap(y2, y1); swap(x2, x1); 298 | } 299 | if (y0 > y1) { 300 | swap(y0, y1); swap(x0, x1); 301 | } 302 | 303 | if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing 304 | a = b = x0; 305 | if(x1 < a) a = x1; 306 | else if(x1 > b) b = x1; 307 | if(x2 < a) a = x2; 308 | else if(x2 > b) b = x2; 309 | drawFastHLine(a, y0, b-a+1, color); 310 | return; 311 | } 312 | 313 | int16_t 314 | dx01 = x1 - x0, 315 | dy01 = y1 - y0, 316 | dx02 = x2 - x0, 317 | dy02 = y2 - y0, 318 | dx12 = x2 - x1, 319 | dy12 = y2 - y1; 320 | int32_t 321 | sa = 0, 322 | sb = 0; 323 | 324 | // For upper part of triangle, find scanline crossings for segments 325 | // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 326 | // is included here (and second loop will be skipped, avoiding a /0 327 | // error there), otherwise scanline y1 is skipped here and handled 328 | // in the second loop...which also avoids a /0 error here if y0=y1 329 | // (flat-topped triangle). 330 | if(y1 == y2) last = y1; // Include y1 scanline 331 | else last = y1-1; // Skip it 332 | 333 | for(y=y0; y<=last; y++) { 334 | a = x0 + sa / dy01; 335 | b = x0 + sb / dy02; 336 | sa += dx01; 337 | sb += dx02; 338 | /* longhand: 339 | a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); 340 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 341 | */ 342 | if(a > b) swap(a,b); 343 | drawFastHLine(a, y, b-a+1, color); 344 | } 345 | 346 | // For lower part of triangle, find scanline crossings for segments 347 | // 0-2 and 1-2. This loop is skipped if y1=y2. 348 | sa = dx12 * (y - y1); 349 | sb = dx02 * (y - y0); 350 | for(; y<=y2; y++) { 351 | a = x1 + sa / dy12; 352 | b = x0 + sb / dy02; 353 | sa += dx12; 354 | sb += dx02; 355 | /* longhand: 356 | a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); 357 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 358 | */ 359 | if(a > b) swap(a,b); 360 | drawFastHLine(a, y, b-a+1, color); 361 | } 362 | } 363 | 364 | void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, 365 | const uint8_t *bitmap, int16_t w, int16_t h, 366 | uint16_t color) { 367 | 368 | int16_t i, j, byteWidth = (w + 7) / 8; 369 | 370 | for(j=0; j> (i & 7))) { 373 | drawPixel(x+i, y+j, color); 374 | } 375 | } 376 | } 377 | } 378 | 379 | // Draw a 1-bit color bitmap at the specified x, y position from the 380 | // provided bitmap buffer (must be PROGMEM memory) using color as the 381 | // foreground color and bg as the background color. 382 | void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, 383 | const uint8_t *bitmap, int16_t w, int16_t h, 384 | uint16_t color, uint16_t bg) { 385 | 386 | int16_t i, j, byteWidth = (w + 7) / 8; 387 | 388 | for(j=0; j> (i & 7))) { 391 | drawPixel(x+i, y+j, color); 392 | } 393 | else { 394 | drawPixel(x+i, y+j, bg); 395 | } 396 | } 397 | } 398 | } 399 | 400 | //Draw XBitMap Files (*.xbm), exported from GIMP, 401 | //Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor. 402 | //C Array can be directly used with this function 403 | void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y, 404 | const uint8_t *bitmap, int16_t w, int16_t h, 405 | uint16_t color) { 406 | 407 | int16_t i, j, byteWidth = (w + 7) / 8; 408 | 409 | for(j=0; j= 100 419 | size_t Adafruit_GFX::write(uint8_t c) { 420 | #else 421 | void Adafruit_GFX::write(uint8_t c) { 422 | #endif 423 | if (c == '\n') { 424 | cursor_y += textsize*8; 425 | cursor_x = 0; 426 | } else if (c == '\r') { 427 | // skip em 428 | } else { 429 | drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); 430 | cursor_x += textsize*6; 431 | if (wrap && (cursor_x > (_width - textsize*6))) { 432 | cursor_y += textsize*8; 433 | cursor_x = 0; 434 | } 435 | } 436 | #if ARDUINO >= 100 437 | return 1; 438 | #endif 439 | } 440 | 441 | // Draw a character 442 | void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, 443 | uint16_t color, uint16_t bg, uint8_t size) { 444 | 445 | if((x >= _width) || // Clip right 446 | (y >= _height) || // Clip bottom 447 | ((x + 6 * size - 1) < 0) || // Clip left 448 | ((y + 8 * size - 1) < 0)) // Clip top 449 | return; 450 | 451 | if(!_cp437 && (c >= 176)) c++; // Handle 'classic' charset behavior 452 | 453 | for (int8_t i=0; i<6; i++ ) { 454 | uint8_t line; 455 | if (i == 5) 456 | line = 0x0; 457 | else 458 | line = pgm_read_byte(font+(c*5)+i); 459 | for (int8_t j = 0; j<8; j++) { 460 | if (line & 0x1) { 461 | if (size == 1) // default size 462 | drawPixel(x+i, y+j, color); 463 | else { // big size 464 | fillRect(x+(i*size), y+(j*size), size, size, color); 465 | } 466 | } else if (bg != color) { 467 | if (size == 1) // default size 468 | drawPixel(x+i, y+j, bg); 469 | else { // big size 470 | fillRect(x+i*size, y+j*size, size, size, bg); 471 | } 472 | } 473 | line >>= 1; 474 | } 475 | } 476 | } 477 | 478 | void Adafruit_GFX::setCursor(int16_t x, int16_t y) { 479 | cursor_x = x; 480 | cursor_y = y; 481 | } 482 | 483 | int16_t Adafruit_GFX::getCursorX(void) const { 484 | return cursor_x; 485 | } 486 | 487 | int16_t Adafruit_GFX::getCursorY(void) const { 488 | return cursor_y; 489 | } 490 | 491 | void Adafruit_GFX::setTextSize(uint8_t s) { 492 | textsize = (s > 0) ? s : 1; 493 | } 494 | 495 | void Adafruit_GFX::setTextColor(uint16_t c) { 496 | // For 'transparent' background, we'll set the bg 497 | // to the same as fg instead of using a flag 498 | textcolor = textbgcolor = c; 499 | } 500 | 501 | void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) { 502 | textcolor = c; 503 | textbgcolor = b; 504 | } 505 | 506 | void Adafruit_GFX::setTextWrap(boolean w) { 507 | wrap = w; 508 | } 509 | 510 | uint8_t Adafruit_GFX::getRotation(void) const { 511 | return rotation; 512 | } 513 | 514 | void Adafruit_GFX::setRotation(uint8_t x) { 515 | rotation = (x & 3); 516 | switch(rotation) { 517 | case 0: 518 | case 2: 519 | _width = WIDTH; 520 | _height = HEIGHT; 521 | break; 522 | case 1: 523 | case 3: 524 | _width = HEIGHT; 525 | _height = WIDTH; 526 | break; 527 | } 528 | } 529 | 530 | // Enable (or disable) Code Page 437-compatible charset. 531 | // There was an error in glcdfont.c for the longest time -- one character 532 | // (#176, the 'light shade' block) was missing -- this threw off the index 533 | // of every character that followed it. But a TON of code has been written 534 | // with the erroneous character indices. By default, the library uses the 535 | // original 'wrong' behavior and old sketches will still work. Pass 'true' 536 | // to this function to use correct CP437 character values in your code. 537 | void Adafruit_GFX::cp437(boolean x) { 538 | _cp437 = x; 539 | } 540 | 541 | // Return the size of the display (per current rotation) 542 | int16_t Adafruit_GFX::width(void) const { 543 | return _width; 544 | } 545 | 546 | int16_t Adafruit_GFX::height(void) const { 547 | return _height; 548 | } 549 | 550 | void Adafruit_GFX::invertDisplay(boolean i) { 551 | // Do nothing, must be subclassed if supported 552 | } 553 | 554 | /***************************************************************************/ 555 | // code for the GFX button UI element 556 | 557 | Adafruit_GFX_Button::Adafruit_GFX_Button(void) { 558 | _gfx = 0; 559 | } 560 | 561 | void Adafruit_GFX_Button::initButton(Adafruit_GFX *gfx, 562 | int16_t x, int16_t y, 563 | uint8_t w, uint8_t h, 564 | uint16_t outline, uint16_t fill, 565 | uint16_t textcolor, 566 | char *label, uint8_t textsize) 567 | { 568 | _x = x; 569 | _y = y; 570 | _w = w; 571 | _h = h; 572 | _outlinecolor = outline; 573 | _fillcolor = fill; 574 | _textcolor = textcolor; 575 | _textsize = textsize; 576 | _gfx = gfx; 577 | strncpy(_label, label, 9); 578 | _label[9] = 0; 579 | } 580 | 581 | 582 | 583 | void Adafruit_GFX_Button::drawButton(boolean inverted) { 584 | uint16_t fill, outline, text; 585 | 586 | if (! inverted) { 587 | fill = _fillcolor; 588 | outline = _outlinecolor; 589 | text = _textcolor; 590 | } else { 591 | fill = _textcolor; 592 | outline = _outlinecolor; 593 | text = _fillcolor; 594 | } 595 | 596 | _gfx->fillRoundRect(_x - (_w/2), _y - (_h/2), _w, _h, min(_w,_h)/4, fill); 597 | _gfx->drawRoundRect(_x - (_w/2), _y - (_h/2), _w, _h, min(_w,_h)/4, outline); 598 | 599 | 600 | _gfx->setCursor(_x - strlen(_label)*3*_textsize, _y-4*_textsize); 601 | _gfx->setTextColor(text); 602 | _gfx->setTextSize(_textsize); 603 | _gfx->print(_label); 604 | } 605 | 606 | boolean Adafruit_GFX_Button::contains(int16_t x, int16_t y) { 607 | if ((x < (_x - _w/2)) || (x > (_x + _w/2))) return false; 608 | if ((y < (_y - _h)) || (y > (_y + _h/2))) return false; 609 | return true; 610 | } 611 | 612 | 613 | void Adafruit_GFX_Button::press(boolean p) { 614 | laststate = currstate; 615 | currstate = p; 616 | } 617 | 618 | boolean Adafruit_GFX_Button::isPressed() { return currstate; } 619 | boolean Adafruit_GFX_Button::justPressed() { return (currstate && !laststate); } 620 | boolean Adafruit_GFX_Button::justReleased() { return (!currstate && laststate); } 621 | --------------------------------------------------------------------------------