Advertisement
pleasedontcode

Cat Display rev_17

Dec 9th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Cat Display
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-09 10:39:52
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Show a colorful cat graphic on the ILI9341 TFT */
  21.     /* display, utilizing the U8g2_for_Adafruit_GFX */
  22.     /* library for enhanced visual quality and */
  23.     /* performance. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <SPI.h>
  31. #include <Adafruit_ILI9341.h>   //https://github.com/adafruit/Adafruit_ILI9341
  32. #include <U8g2_for_Adafruit_GFX.h>  //https://github.com/olikraus/U8g2_for_Adafruit_GFX
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void drawCatGraphic(); // Function to draw the cat graphic
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t display_ILI9341_TFT_RST_PIN_D2        = 2;
  41. const uint8_t display_ILI9341_TFT_DC_PIN_D3     = 3;
  42.  
  43. /***** DEFINITION OF SPI PINS *****/
  44. const uint8_t display_ILI9341_TFT_SPI_PIN_MOSI_D11      = 11;
  45. const uint8_t display_ILI9341_TFT_SPI_PIN_MISO_D12      = 12;
  46. const uint8_t display_ILI9341_TFT_SPI_PIN_SCLK_D13      = 13;
  47. const uint8_t display_ILI9341_TFT_SPI_PIN_CS_D10        = 10;
  48.  
  49. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  50. bool    display_ILI9341_TFT_RST_PIN_D2_rawData      = 0;
  51. bool    display_ILI9341_TFT_DC_PIN_D3_rawData       = 0;
  52.  
  53. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  54. float   display_ILI9341_TFT_RST_PIN_D2_phyData      = 0.0;
  55. float   display_ILI9341_TFT_DC_PIN_D3_phyData       = 0.0;
  56.  
  57. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  58. // Create an instance of the ILI9341 display
  59. Adafruit_ILI9341 tft(display_ILI9341_TFT_SPI_PIN_CS_D10, display_ILI9341_TFT_DC_PIN_D3, display_ILI9341_TFT_SPI_PIN_MOSI_D11, display_ILI9341_TFT_SPI_PIN_SCLK_D13, display_ILI9341_TFT_RST_PIN_D2);
  60.  
  61. // Create an instance of the U8g2 for Adafruit GFX
  62. U8G2_FOR_ADAFRUIT_GFX u8g2;
  63.  
  64. void setup(void)
  65. {
  66.     // put your setup code here, to run once:
  67.  
  68.     pinMode(display_ILI9341_TFT_RST_PIN_D2,  OUTPUT);
  69.     pinMode(display_ILI9341_TFT_DC_PIN_D3,   OUTPUT);
  70.     pinMode(display_ILI9341_TFT_SPI_PIN_CS_D10,  OUTPUT);
  71.    
  72.     // start the SPI library:
  73.     SPI.begin();
  74.    
  75.     // Initialize the display
  76.     tft.begin();
  77.     tft.setRotation(3); // Set the rotation of the display
  78.     tft.fillScreen(ILI9341_BLACK); // Clear the screen with black color
  79.  
  80.     // Initialize U8g2
  81.     u8g2.begin(tft); // Pass the Adafruit_GFX instance to U8g2
  82.     u8g2.setFont(u8g2_font_ncenB08_tr); // Set a font for U8g2
  83. }
  84.  
  85. void loop(void)
  86. {
  87.     // put your main code here, to run repeatedly:
  88.     drawCatGraphic(); // Draw the cat graphic on the display
  89.     while (true); // Stop the loop
  90. }
  91.  
  92. void drawCatGraphic()
  93. {
  94.     // Draw a colorful cat graphic using U8g2
  95.     u8g2.setForegroundColor(ILI9341_YELLOW); // Set the color for the cat
  96.     u8g2.setBackgroundColor(ILI9341_BLACK); // Set the background color
  97.     u8g2.setFontMode(1); // Transparent mode
  98.     u8g2.setFontDirection(0); // Normal direction
  99.     u8g2.drawStr(10, 30, "Meow!"); // Draw text
  100.     // Add more drawing commands here to create the cat graphic
  101. }
  102.  
  103. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement