pictureEmbed.ino 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // ILI9341 example with embedded color bitmaps in sketch.
  2. // WILL NOT FIT ON ARDUINO UNO OR OTHER AVR BOARDS;
  3. // uses large bitmap image stored in array!
  4. // Options for converting images to the format used here include:
  5. // http://www.rinkydinkelectronics.com/t_imageconverter565.php
  6. // or
  7. // GIMP (https://www.gimp.org/) as follows:
  8. // 1. File -> Export As
  9. // 2. In Export Image dialog, use 'C source code (*.c)' as filetype.
  10. // 3. Press export to get the export options dialog.
  11. // 4. Type the desired variable name into the 'prefixed name' box.
  12. // 5. Uncheck 'GLIB types (guint8*)'
  13. // 6. Check 'Save as RGB565 (16-bit)'
  14. // 7. Press export to save your image.
  15. // Assuming 'image_name' was typed in the 'prefixed name' box of step 4,
  16. // you can have to include the c file, then using the image can be done with:
  17. // tft.drawRGBBitmap(0, 0, image_name.pixel_data, image_name.width, image_name.height);
  18. // See also https://forum.pjrc.com/threads/35575-Export-for-ILI9341_t3-with-GIMP
  19. #include "SPI.h"
  20. #include <Adafruit_ILI9341.h>
  21. #include "dragon.h"
  22. // For the Adafruit shield, these are the default.
  23. //#define TFT_DC 9
  24. //#define TFT_CS 10
  25. // Feather 32u4 or M0 with TFT FeatherWing:
  26. #define TFT_DC 10
  27. #define TFT_CS 9
  28. // ESP8266:
  29. //#define TFT_DC 15
  30. //#define TFT_CS 0
  31. // Other boards (including Feather boards) may have other pinouts;
  32. // see learn.adafruit.com/adafruit-2-4-tft-touch-screen-featherwing/pinouts
  33. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
  34. // If using the breakout, change pins as desired
  35. //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
  36. void setup() {
  37. tft.begin();
  38. }
  39. void loop(void) {
  40. for(uint8_t r=0; r<4; r++) {
  41. tft.setRotation(r);
  42. tft.fillScreen(ILI9341_BLACK);
  43. for(uint8_t j=0; j<20; j++) {
  44. tft.drawRGBBitmap(
  45. random(-DRAGON_WIDTH , tft.width()),
  46. random(-DRAGON_HEIGHT, tft.height()),
  47. #if defined(__AVR__) || defined(ESP8266)
  48. dragonBitmap,
  49. #else
  50. // Some non-AVR MCU's have a "flat" memory model and don't
  51. // distinguish between flash and RAM addresses. In this case,
  52. // the RAM-resident-optimized drawRGBBitmap in the ILI9341
  53. // library can be invoked by forcibly type-converting the
  54. // PROGMEM bitmap pointer to a non-const uint16_t *.
  55. (uint16_t *)dragonBitmap,
  56. #endif
  57. DRAGON_WIDTH, DRAGON_HEIGHT);
  58. delay(1); // Allow ESP8266 to handle watchdog & WiFi stuff
  59. }
  60. delay(3000);
  61. }
  62. }