Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Adafruit TFT ILI9341

  1. #1
    Junior Member
    Join Date
    Mar 2020
    Posts
    4

    Adafruit TFT ILI9341

    I am trying to use the following code just to test my screen and continue on my project. Adds a grid to what it should look like which is a grid of colored buttons, but also seems stretched. Currently have the MOSI connected to 11 on teensy, and 10 to CS. MISO to 12, 6 to D/C
    Code:
    #include <SPI.h>
    #include "Adafruit_GFX.h"
    #include "Adafruit_HX8357.h"
    
    #define TFT_CS 11
    #define TFT_DC 6
    #define TFT_RST 0 // RST can be set to -1 if you tie it to Arduino's reset
    
    #define XMAX 320
    #define YMAX 480
    #define BWIDTH 110
    #define BHIGHT 90
    
    uint16_t clr = HX8357_GREEN;
    
    // Use hardware SPI
    Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
    
    void setup() {
      //tft.reset();
      tft.begin();
      tft.fillScreen(HX8357_BLACK);
    
    }
    
    void loop() {
      static bool pressed;
    
      tft.fillRoundRect(30, 30, BWIDTH, BHIGHT, 5, 0xFFFF - clr);
      tft.fillRoundRect(XMAX - 30 - BWIDTH, 30, BWIDTH, BHIGHT, 5, clr);
      tft.fillRoundRect(XMAX - 30 - BWIDTH, YMAX/2 - BHIGHT/2, BWIDTH, BHIGHT, 5, clr);
      tft.fillRoundRect(30, YMAX/2 - BHIGHT/2, BWIDTH, BHIGHT, 5, 0xFFFF - clr);
      tft.fillRoundRect(XMAX - 30 - BWIDTH, YMAX - 30 - BHIGHT, BWIDTH, BHIGHT, 5, clr);
      tft.fillRoundRect(30, YMAX - 30 - BHIGHT, BWIDTH, BHIGHT, 5, 0xFFFF - clr);
    
      uint16_t button = digitalRead(35);
    
      if (button)
      {
        if (!pressed)
        {
          clr = random(0xFFFF);
        }
        pressed = true;
      }
      else
      {
        pressed = false;
      }
      delay(20);
    }

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,363
    Looks like you are ysing the wrong library?
    Code:
    #include "Adafruit_HX8357.h"
    Should be:
    Code:
    #include "Adafruit_ILI9341.h"
    The HX8357 is a larger display with more pixels...

  3. #3
    Junior Member
    Join Date
    Mar 2020
    Posts
    4
    heh. Should have noticed that. Thank you Kurt. Will probably be back later with a different kind of question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •