hola que tal compañeros
tengo un problema con una pantalla LCD 2.4" TFT
el problema es que parpadea por causa del delay de refresh y quisiera evitarlo pero no se como
el programa es muy sencillo solamente hace una "grafica" conforme suben o bajan los valores de un sensor, pero como les comento cada vez que se refresca la pantalla y no se como evitarlo espero me puedan ayudar.
Mi codigo es el siguiente:
#include <pin_magic_MEGA.h> // cambia los pines para hacerlo compatible con arduino mega
#include <Adafruit_GFX.h> // Libreria de graficos
#include <Adafruit_TFTLCD.h> // Libreria de LCD
// Pines de conexion del LCD
#define LCD_CS A3 // Chip Select - Pin analogico 3
#define LCD_CD A2 // Command/Data - Pin Analogico 2
#define LCD_WR A1 // LCD Write - Pin Analogico 1
#define LCD_RD A0 // LCD Read - Pin Analogico 0
#define LCD_RESET A4 // LCD Reset - Pin Analogico 4
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // Instancia del LCD
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF
#define BLUE 0x001F
#define CYAN 0x07FF
#define YELLOW 0xFFE0
#define MAGENTA 0xF81F
const int analogInPin = A15; // cambiar este valor a la entrada del sensor
int sensorValue = 0;
void setup(void)
{
Serial.begin(9600);
tft.begin(0x9341); // Iniciamos el LCD especificando el controlador de nuestro LC. En este caso el ILI9341.
tft.fillScreen(BLACK); // Establecemos el fondo de la patalla
}
void loop(void)
{
tft.fillScreen(BLACK);
sensorValue = analogRead(analogInPin);
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\n");
tft.setRotation(1); // Establecemos la posición de la pantalla Vertical=0 u Horizontal=1
tft.setCursor(60, 20); // Situamos el cursor en la posicion del LCD deseada,
// (X, Y) siendo X el ancho (240 px max.) e Y el alto (320 px max.)
tft.setTextSize(3); // Definimos tamaño del texto. (Probado tamaños del 1 al 10)
tft.setTextColor(CYAN); // Definimos el color del texto
tft.println("Temperatura"); // Escribimos nuestro texto en el LCD. Realizará un salto de linea
// automatico si el texto es mayor que el tamaño del LCD
tft.setCursor(60, 50);
tft.setTextSize(2);
tft.setTextColor(MAGENTA);
tft.println(sensorValue);
if(sensorValue <= 102)
{
tft.fillRect(20, 165, 20, 50, GREEN);
}
if(sensorValue <= 204 && sensorValue >102)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
}
if(sensorValue <= 306 && sensorValue >204)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
}
if(sensorValue <= 408 && sensorValue >306)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
tft.fillRect(95, 135, 20, 80, YELLOW);
}
if(sensorValue <= 510 && sensorValue >408)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
tft.fillRect(95, 135, 20, 80, YELLOW);
tft.fillRect(120, 125, 20, 90, RED);
}
if(sensorValue <= 612 && sensorValue >510)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
tft.fillRect(95, 135, 20, 80, YELLOW);
tft.fillRect(120, 125, 20, 90, RED);
tft.fillRect(145, 115, 20, 100, RED);
}
if(sensorValue <= 714 && sensorValue >612)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
tft.fillRect(95, 135, 20, 80, YELLOW);
tft.fillRect(120, 125, 20, 90, RED);
tft.fillRect(145, 115, 20, 100, RED);
tft.fillRect(170, 105, 20, 110, WHITE);
}
if(sensorValue <= 816 && sensorValue >714)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
tft.fillRect(95, 135, 20, 80, YELLOW);
tft.fillRect(120, 125, 20, 90, RED);
tft.fillRect(145, 115, 20, 100, RED);
tft.fillRect(170, 105, 20, 110, WHITE);
tft.fillRect(195, 95, 20, 120, WHITE);
}
if(sensorValue <= 918 && sensorValue >816)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
tft.fillRect(95, 135, 20, 80, YELLOW);
tft.fillRect(120, 125, 20, 90, RED);
tft.fillRect(145, 115, 20, 100, RED);
tft.fillRect(170, 105, 20, 110, WHITE);
tft.fillRect(195, 95, 20, 120, WHITE);
tft.fillRect(220, 85, 20, 130, MAGENTA);
}
if(sensorValue <= 1023 && sensorValue >918)
{
tft.fillRect(20, 165, 20, 50, GREEN);
tft.fillRect(45, 155, 20, 60, GREEN);
tft.fillRect(70, 145, 20, 70, YELLOW);
tft.fillRect(95, 135, 20, 80, YELLOW);
tft.fillRect(120, 125, 20, 90, RED);
tft.fillRect(145, 115, 20, 100, RED);
tft.fillRect(170, 105, 20, 110, WHITE);
tft.fillRect(195, 95, 20, 120, WHITE);
tft.fillRect(220, 85, 20, 130, MAGENTA);
tft.fillRect(245, 75, 20, 140, MAGENTA);
}
delay(100);
}
Editado por única vez, para las próximas veces lee las normas del foro.