/***************************************************************
Please note that the getColor function in this example generates a colorful pattern based
on the pixel coordinates. You can modify this function to display different patterns or
load actual image data if you have a specific art image you want to display. You may also
want to adjust the rotation setting in tft.setRotation() to match the orientation of your display.
Remember to refer to the datasheets and documentation of your specific display
and wiring to ensure proper connections and functionality.
To display colorful art on an Arduino connected to an ILI9341 TFT display, you'll need to write
C++ code using the Arduino IDE and the Adafruit_ILI9341
library (or a compatible library) to interact with the display. Below is a basic example
of how you can display colorful art on the screen using RGB565 color format.
First, make sure you have the Adafruit_ILI9341 library installed in your Arduino IDE by
going to "Sketch" > "Include Library" > "Manage Libraries" and searching for "Adafruit_ILI9341."
Then, connect your ILI9341 display to the Arduino board using appropriate connections
(SPI communication). Ensure you know the SPI pins for your specific Arduino board.
bt arvind 29/07/23
*************************************************************************/
#include <Adafruit_ILI9341.h>
#include <SPI.h>
// ILI9341 Display Configuration
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
// Create an instance of the display library
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.begin();
tft.setRotation(3); // Adjust the rotation to match your display's orientation
// Clear the screen
tft.fillScreen(ILI9341_BLACK);
// Draw colorful art
drawColorfulArt();
}
void loop() {
// Leave the loop empty, as we only need to display the art once
}
void drawColorfulArt() {
// Loop through the display pixels and draw colorful patterns
for (int y = 0; y < tft.height(); y++) {
for (int x = 0; x < tft.width(); x++) {
// Calculate RGB values based on the position
uint16_t color = getColor(x, y);
// Draw the pixel
tft.drawPixel(x, y, color);
}
}
}
// Function to generate a colorful pattern based on the pixel coordinates
uint16_t getColor(int x, int y) {
// Play around with the formula to get different colorful patterns
uint8_t r = sin(x * 0.3) * 127 + 128;
uint8_t g = cos(y * 0.2) * 127 + 128;
uint8_t b = cos((x+ y) * 0.3) * 127 + 128;
// Combine RGB components into a 16-bit color value (RGB565 format)
return tft.color565(r, g, b);
}
Loading
ili9341-cap-touch
ili9341-cap-touch