Jump to content
ELFORUM - Forumul electronistilor

Portare TFT ILI9225 la ILI9341


aetius
 Share

Recommended Posts

Buna ziua.

As dori s-a construiesc swr-metru de aici... https://cloud.mail.ru/public/M1nc/nb9k12etY

Dar nu stiu cum s-a procedez ,vad ca sunt biblioteci diferetie ,dar care ar fi bune pentru ILI9341 (am cateva bucati si le-as pune la treaba) ?

Nu sunt mare specialist in programare  dar pot citi si invata...

#include "SPI.h"
#include "TFT_22_ILI9225.h"

#define TFT_RST 50                                                                              //50 вывод Mega2560 на RST ЖКИ
#define TFT_RS  49                                                                              //49 вывод Mega2560 на RS ЖКИ
#define TFT_CS  53                                                                              //53 вывод Mega2560 на CS ЖКИ
#define TFT_SDI 51                                                                              //51 вывод Mega2560 на SDI ЖКИ
#define TFT_CLK 52                                                                              //52 вывод Mega2560 на CLK ЖКИ
#define TFT_LED 45                                                                              //45 вывод ШИМ для подсветки
#define TFT_BRIGHTNESS 120                                                                      //инициализация яркости подсветки ЖКИ
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED, TFT_BRIGHTNESS);          //инициализация аппаратного SPI

int a_old, b_old;

void setup() {
//***************************** Заставка ******************************
    tft.setBacklight(0);                                                          //отключаем подсветку экрана
    tft.begin(); tft.clear();                                                     //инициализация дисплея, очистка экрана, задержка 1000мс
    tft.setOrientation(1);                                                        //альбомная ориентация экрана
}

void loop() {
    int a=analogRead(A0)/25;                                                      //расчет переменной a
    int ReadR=analogRead(A0);
    int ReadG=analogRead(A0);
    int ReadB=analogRead(A0);
    int R,G,B;
  
  if (ReadB<=255) {ReadB=255; B=ReadB;}
  if (ReadB>512) {ReadB=0; B=ReadB;}
  if ((ReadB>255)&&(ReadB<=512)){B=map(ReadB,512,256,0,255);}

  if (ReadG<=255){G=map(ReadG,0,255,0,255);}
  if ((ReadG>255)&&(ReadG<=768)){ReadG=255; G=ReadG;}
  if (ReadG>768){G=map(ReadG,769,1023,255,0);}

  if (ReadR<512){ReadR=0; R=ReadR;}
  if ((ReadR>=512)&&(ReadR<=768)){R=map(ReadR,512,768,0,255);}
  if (ReadR>769){ReadR=255; R=ReadR;}
  
  if (a > a_old) {                                                                //если новое значение больше старого(движение градусника вправо)
  for(int i=a_old; i<a; i++){                                                     //включаем цикл
    tft.fillRectangle(10+i*5,60,12+i*5,75,tft.setColor(R,G,B));}                  //рисуем градусник
    a_old=a;}                                                                     //выравниваем старое и новое значение
  else {                                                                          //иначе
    tft.fillRectangle(10+a*5,60,12+a_old*5,75,COLOR_BLACK);                       //стираем градусник при движении влево
    a_old=a;}                                                                     //выравниваем старое и новое значение

}

Cred ca de aici s-ar incepe  dar nu stiu ce s-a modific ?

Multumesc de citire.

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Multumesc de raspuns.am modificat ce am stiut ...

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "SPI.h"

#define TFT_CS 8
#define TFT_RST 9
#define TFT_DC 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

int a_old, b_old;

void setup() {
  tft.begin();
  tft.setRotation(3); // Depending on your display orientation, you might need to adjust this value.

  // Fill the screen with a background color
  tft.fillScreen(ILI9341_BLACK);
}



void loop() 
{
    int a=analogRead(A0)/25;                                                   
    int ReadR=analogRead(A0);
    int ReadG=analogRead(A0);
    int ReadB=analogRead(A0);
    int R,G,B;
  
  if (ReadB<=255) {ReadB=255; B=ReadB;}
  if (ReadB>512) {ReadB=0; B=ReadB;}
  if ((ReadB>255)&&(ReadB<=512)){B=map(ReadB,512,256,0,255);}

  if (ReadG<=255){G=map(ReadG,0,255,0,255);}
  if ((ReadG>255)&&(ReadG<=768)){ReadG=255; G=ReadG;}
  if (ReadG>768){G=map(ReadG,769,1023,255,0);}

  if (ReadR<512){ReadR=0; R=ReadR;}
  if ((ReadR>=512)&&(ReadR<=768)){R=map(ReadR,512,768,0,255);}
  if (ReadR>769){ReadR=255; R=ReadR;}
  
  if (a > a_old) {                                                               
  for(int i=a_old; i<a; i++){                                                
    tft.fillRect(10+i*5,60,12+i*5,75,ILI9341_RED);}            //AM PUS CULOARE ROSIE ,NU AM STIUT CUM ALTFEL     
    a_old=a;}                                                                    
  else {                                                                          
    tft.fillRect(10+a*5,60,12+a_old*5,75,ILI9341_BLACK);                     
    a_old=a;}                                                                     

}

Nu am erori ,dar NU am obtinut ce este in poza...(Vreo 2 exemple cat am incercat de la adafruit merg pe ili9341)

IMG_20180620_171029 (1).jpg

Am obtinut ce este mai jos in imagine...

WhatsApp Image 2023-09-17 at 23.25.12.jpeg

Edited by aetius
Link to comment
Share on other sites

Foloseste urmatoarele:

#include "Adafruit_SPITFT.h"

Si in loc de:

 

//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// in loc de ce este scris folosesti asta:
Adafruit_SPITFT tft = Adafruit_SPITFT(30, 240, TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


tft.fillRect(10+i*5,60,12+i*5,75,ILI9341_RED);}            //AM PUS CULOARE ROSIE ,NU AM STIUT CUM ALTFEL     
    a_old=a;}  

scrie :

tft.fillRect(10+i*5,60,12+i*5,75,tft.color565);}              
    a_old=a;}  

TFT_MOSI si TFT_SCLK trebuie sa le definesti tu, conform conexiunilor cu placa Arduino.

Link to comment
Share on other sites

#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <Adafruit_ILI9341.h>

#define TFT_CS 8
#define TFT_RST 9
#define TFT_DC 10


Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
//Adafruit_SPITFT tft = Adafruit_SPITFT(30, 240, TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
int a_old, b_old;

void setup() {
  tft.begin();
  tft.setRotation(3); // Depending on your display orientation, you might need to adjust this value.

  // Fill the screen with a background color
  tft.fillScreen(ILI9341_BLACK);
}



void loop()
{
  int a = analogRead(A0) / 25;
  int ReadR = analogRead(A0);
  int ReadG = analogRead(A0);
  int ReadB = analogRead(A0);
  int R, G, B;

  if (ReadB <= 255) {
    ReadB = 255;
    B = ReadB;
  }
  if (ReadB > 512) {
    ReadB = 0;
    B = ReadB;
  }
  if ((ReadB > 255) && (ReadB <= 512)) {
    B = map(ReadB, 512, 256, 0, 255);
  }

  if (ReadG <= 255) {
    G = map(ReadG, 0, 255, 0, 255);
  }
  if ((ReadG > 255) && (ReadG <= 768)) {
    ReadG = 255;
    G = ReadG;
  }
  if (ReadG > 768) {
    G = map(ReadG, 769, 1023, 255, 0);
  }

  if (ReadR < 512) {
    ReadR = 0;
    R = ReadR;
  }
  if ((ReadR >= 512) && (ReadR <= 768)) {
    R = map(ReadR, 512, 768, 0, 255);
  }
  if (ReadR > 769) {
    ReadR = 255;
    R = ReadR;
  }

  if (a > a_old) {
    for (int i = a_old; i < a; i++) {
      tft.fillRect(10 + i * 5, 60, 12 + i * 5, 75, tft.color565(R, G, B));
    }
    a_old = a;
  } else {
    tft.fillRect(10 + a * 5, 60, 12 + a_old * 5, 75, tft.color565(R, G, B));
  }
  a_old = a;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share




×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines