acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

Rotated_Sprite_3.ino (4936B)

      1 /*====================================================================================
      2 
      3   This example draws a jpeg image in a Sprite then plot a rotated copy of the Sprite
      4   to the TFT.
      5 
      6   The jpeg used in in the sketch Data folder (press Ctrl+K to see folder)
      7 
      8   The jpeg must be uploaded to the ESP8266 or ESP32 SPIFFS by using the Tools menu
      9   sketch data upload option of the Arduino IDE. If you do not have that option it can
     10   be added. Close the Serial Monitor window before uploading to avoid an error message!
     11 
     12   To add the upload option for the ESP8266 see:
     13   http://www.esp8266.com/viewtopic.php?f=32&t=10081
     14   https://github.com/esp8266/arduino-esp8266fs-plugin/releases
     15 
     16   To add the upload option for the ESP32 see:
     17   https://github.com/me-no-dev/arduino-esp32fs-plugin
     18 
     19   Created by Bodmer 6/1/19 as an example to the TFT_eSPI library:
     20   https://github.com/Bodmer/TFT_eSPI
     21 
     22   Extension functions in the TFT_eFEX library are used to list SPIFFS files and render
     23   the jpeg to the TFT and to the Sprite:
     24   https://github.com/Bodmer/TFT_eFEX
     25 
     26   To render the Jpeg image the JPEGDecoder library is needed, this can be obtained
     27   with the IDE library manager, or downloaded from here:
     28   https://github.com/Bodmer/JPEGDecoder
     29 
     30   ==================================================================================*/
     31 
     32 //====================================================================================
     33 //                                  Libraries
     34 //====================================================================================
     35 // Call up the SPIFFS FLASH filing system, this is part of the ESP Core
     36 #define FS_NO_GLOBALS
     37 #include <FS.h>
     38 
     39 #ifdef ESP32
     40 #include "SPIFFS.h" // Needed for ESP32 only
     41 #endif
     42 
     43 // https://github.com/Bodmer/TFT_eSPI
     44 #include <TFT_eSPI.h>                 // Hardware-specific library
     45 TFT_eSPI tft = TFT_eSPI();            // Invoke custom library
     46 TFT_eSprite spr = TFT_eSprite(&tft);  // Create Sprite object "spr" with pointer to "tft" object
     47 
     48 // https://github.com/Bodmer/TFT_eFEX
     49 #include <TFT_eFEX.h>                 // Include the function extension library
     50 TFT_eFEX fex = TFT_eFEX(&tft);        // Create TFT_eFX object "fex" with pointer to "tft" object
     51 
     52 
     53 //====================================================================================
     54 //                                    Setup
     55 //====================================================================================
     56 void setup()
     57 {
     58   Serial.begin(250000); // Used for messages
     59 
     60   tft.begin();
     61   tft.setRotation(0);  // 0 & 2 Portrait. 1 & 3 landscape
     62   tft.fillScreen(TFT_BLACK);
     63 
     64   // Create a sprite to hold the jpeg (or part of it)
     65   spr.createSprite(80, 64);
     66 
     67   // Initialise SPIFFS
     68   if (!SPIFFS.begin()) {
     69     Serial.println("SPIFFS initialisation failed!");
     70     while (1) yield(); // Stay here twiddling thumbs waiting
     71   }
     72   Serial.println("\r\nInitialisation done.\r\n");
     73 
     74   // Lists the files so you can see what is in the SPIFFS
     75   fex.listSPIFFS();
     76 
     77   // Note the / before the SPIFFS file name must be present, this means the file is in
     78   // the root directory of the SPIFFS, e.g. "/tiger.jpg" for a file called "tiger.jpg"
     79 
     80   // Send jpeg info to serial port
     81   fex.jpegInfo("/Eye_80x64.jpg");
     82 
     83   // Draw jpeg iamge in Sprite spr at 0,0
     84   fex.drawJpeg("/Eye_80x64.jpg", 0 , 0, &spr);
     85 }
     86 
     87 //====================================================================================
     88 //                                    Loop
     89 //====================================================================================
     90 void loop()
     91 {
     92 
     93   tft.fillScreen(random(0xFFFF));
     94 
     95 
     96   // Set the TFT pivot point to the centre of the screen
     97   tft.setPivot(tft.width() / 2, tft.height() / 2);
     98 
     99   // Set Sprite pivot point to centre of Sprite
    100   spr.setPivot(spr.width() / 2, spr.height() / 2);
    101 
    102   // Push Sprite to the TFT at 0,0 (not rotated)
    103   spr.pushSprite(0, 0);
    104 
    105   delay(1000);
    106 
    107   // Push copies of Sprite rotated through increasing angles 0-360 degrees
    108   // with 45 fegree increments
    109   for (int16_t angle = 0; angle <= 360; angle += 45) {
    110     spr.pushRotated(angle);
    111     delay(500);
    112   }
    113 
    114   delay(2000);
    115 
    116   // Move Sprite pivot to a point above the image at 40,-60
    117   // (Note: Top left corner is Sprite coordinate 0,0)
    118   // The TFT pivot point has already been set to middle of screen.
    119   /*                    .Pivot point at 40,-60
    120                         ^
    121                         |
    122                        -60
    123                   < 40 >|
    124                   ______V______
    125                  |             |
    126                  |   Sprite    |
    127                  |_____________|
    128   */
    129   spr.setPivot(40, -60);
    130 
    131   // Push Sprite to screen rotated about the new pivot points
    132   // negative angle rotates Sprite anticlockwise
    133   for (int16_t angle = 330; angle >= 0; angle -= 30) {
    134     spr.pushRotated(angle);
    135     yield(); // Stop watchdog triggering
    136   }
    137 
    138   delay(5000);
    139 }
    140 //====================================================================================