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

Colour_Test.ino (3506B)

      1 
      2 //   Diagnostic test for the displayed colour order
      3 //
      4 // Written by Bodmer 17/2/19 for the TFT_eSPI library:
      5 // https://github.com/Bodmer/TFT_eSPI
      6 
      7 /* 
      8  Different hardware manufacturers use different colour order
      9  configurations at the hardware level.  This may result in
     10  incorrect colours being displayed.
     11 
     12  Incorrectly displayed colours could also be the result of
     13  using the wrong display driver in the library setup file.
     14 
     15  Typically displays have a control register (MADCTL) that can
     16  be used to set the Red Green Blue (RGB) colour order to RGB
     17  or BRG so that red and blue are swapped on the display.
     18 
     19  This control register is also used to manage the display
     20  rotation and coordinate mirroring. The control register
     21  typically has 8 bits, for the ILI9341 these are:
     22 
     23  Bit Function
     24  7   Mirror Y coordinate (row address order)
     25  6   Mirror X coordinate (column address order)
     26  5   Row/column exchange (for rotation)
     27  4   Refresh direction (top to bottom or bottom to top in portrait orientation)
     28  3   RGB order (swaps red and blue)
     29  2   Refresh direction (top to bottom or bottom to top in landscape orientation)
     30  1   Not used
     31  0   Not used
     32 
     33  The control register bits can be written with this example command sequence:
     34  
     35     tft.writecommand(TFT_MADCTL);
     36     tft.writedata(0x48);          // Bits 6 and 3 set
     37     
     38  0x48 is the default value for ILI9341 (0xA8 for ESP32 M5STACK)
     39  in rotation 0 orientation.
     40  
     41  Another control register can be used to "invert" colours,
     42  this swaps black and white as well as other colours (e.g.
     43  green to magenta, red to cyan, blue to yellow).
     44  
     45  To invert colours insert this line after tft.init() or tft.begin():
     46 
     47     tft.invertDisplay( invert ); // Where invert is true or false
     48 
     49 */
     50 
     51 #include <SPI.h>
     52 
     53 #include <TFT_eSPI.h>       // Hardware-specific library
     54 
     55 TFT_eSPI tft = TFT_eSPI();  // Invoke custom library
     56 
     57 void setup(void) {
     58   tft.init();
     59 
     60   tft.fillScreen(TFT_BLACK);
     61   tft.drawRect(0, 0, tft.width(), tft.height(), TFT_GREEN);
     62 
     63   // Set "cursor" at top left corner of display (0,0) and select font 4
     64   tft.setCursor(0, 4, 4);
     65 
     66   // Set the font colour to be white with a black background
     67   tft.setTextColor(TFT_WHITE);
     68 
     69   // We can now plot text on screen using the "print" class
     70   tft.println(" Initialised default\n");
     71   tft.println(" White text");
     72   
     73   tft.setTextColor(TFT_RED);
     74   tft.println(" Red text");
     75   
     76   tft.setTextColor(TFT_GREEN);
     77   tft.println(" Green text");
     78   
     79   tft.setTextColor(TFT_BLUE);
     80   tft.println(" Blue text");
     81 
     82   delay(5000);
     83 
     84 }
     85 
     86 void loop() {
     87 
     88   tft.invertDisplay( false ); // Where i is true or false
     89  
     90   tft.fillScreen(TFT_BLACK);
     91   tft.drawRect(0, 0, tft.width(), tft.height(), TFT_GREEN);
     92 
     93   tft.setCursor(0, 4, 4);
     94 
     95   tft.setTextColor(TFT_WHITE);
     96   tft.println(" Invert OFF\n");
     97 
     98   tft.println(" White text");
     99   
    100   tft.setTextColor(TFT_RED);
    101   tft.println(" Red text");
    102   
    103   tft.setTextColor(TFT_GREEN);
    104   tft.println(" Green text");
    105   
    106   tft.setTextColor(TFT_BLUE);
    107   tft.println(" Blue text");
    108 
    109   delay(5000);
    110 
    111 
    112   // Binary inversion of colours
    113   tft.invertDisplay( true ); // Where i is true or false
    114  
    115   tft.fillScreen(TFT_BLACK);
    116   tft.drawRect(0, 0, tft.width(), tft.height(), TFT_GREEN);
    117 
    118   tft.setCursor(0, 4, 4);
    119 
    120   tft.setTextColor(TFT_WHITE);
    121   tft.println(" Invert ON\n");
    122 
    123   tft.println(" White text");
    124   
    125   tft.setTextColor(TFT_RED);
    126   tft.println(" Red text");
    127   
    128   tft.setTextColor(TFT_GREEN);
    129   tft.println(" Green text");
    130   
    131   tft.setTextColor(TFT_BLUE);
    132   tft.println(" Blue text");
    133 
    134   delay(5000);
    135 }