Hi all,
I`m working on a fan controller for my pc and have some trouble with my TFT Display Shield.
It´s an ILI9486: Link
It is mounted to an Arduino Mega 2560 Board.
All Examples from its libary work fine - so does 99% of my code.
In the setup I`ve created a layout for the displayed information (picture).
In the loop I first do some calculations and then I use the function "anzeige()" to display the values.
The Problem within this function is the function "my_lcd.Fill_Rectangle" at the end of the code. If I comment these for and if statements out, my Display works fine. If I activate them again, the Display stays white.
There is no error message and if I place serial.print inside the for and if´s they also work.
So everything works except the "my_lcd.Fill_Rectangle" inside these statements.
My attempts so far:
Serial.printed all values to see if something isn´t right --> values are good- A different function as seen in code --> didnt work
Fill_Rectanglefuntion(s) outside the for statement with different (lower) values --> worked
#include <OneWire.h> // OneWire-Bibliothek einbinden
#include <DallasTemperature.h> // DS18B20-Bibliothek einbinden
#include <LCDWIKI_GUI.h> //Display Libary: Core graphics library
#include <LCDWIKI_KBV.h> //Display Libary: Hardware-specific library
//Konstanten global
unsigned long previousMillis = 0;
const int fanpins [4] = {6, 7, 8, 9};
const int RGB [3] = {5, 3, 2}; //Rot grün blau
const int dpin_Temp [2] = {A3, A4};
const int apin_Temp [2] = {A1, A2};
const int threshold [4] = {160, 180, 150 , 50};
const int thresh_loud [4] = {215, 225, 200 , 150};
const int WasserTemp [3] = {25 - 10, 38 - 10, 42 - 10};
const int threshold_test [4] = {0, 0, 0 , 0};
//Variablen global
LCDWIKI_KBV my_lcd(ILI9486, 40, 38, 39, 44, 41); //model,cs,cd,wr,rd,reset
float Celsius [2]; //Feld für main
double oneTemp [2];
int fanspeed_wasser[2] = {};
int fanspeed_luft [2] = {};
//Variablen für LCD global
//Hälfte der Displaygröße
int16_t hhigh = my_lcd.Get_Display_Height() / 2 ;
int16_t hwide = my_lcd.Get_Display_Width() / 2 ;
//Koordinaten Grad Zeichen
uint16_t Grad [4] = {29, 193, 2, 3}; // X-Grad 1, X-Grad 2, delta x Grad, Grad [3] Grad
//Delta Koordiante Celsius
int8_t dxC = 8 ;
//Y-Koordinaten Texte
uint16_t yText [3] = {40, 75, 270}; //
//Delta Koordiante Temperatur Werte
int8_t dxZahl = 80;
//Rechteck-Koordinaten Fans
int16_t yy [2] = {247, 254};
int16_t tt [7] = {0, 56, 240 - 31, 356, 118, 240 + 31 , 418};
uint16_t stufen_neu [3] = {0, 0, 0};
uint16_t stufen_alt [3] = {0, 0, 0} ;
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define COLD 0x31FF
#define GRAY 70, 70, 70
OneWire onewire0(dpin_Temp[0]); // OneWire Referenz setzen
DallasTemperature sensors0(&onewire0); // DS18B20 initialisieren
OneWire onewire1(dpin_Temp[1]); // OneWire Referenz setzen
DallasTemperature sensors1(&onewire1); // DS18B20 initialisieren
void setup() {
Serial.begin(9600);
TCCR2B = TCCR2B & 0b11111000 | 0x01; //Timer 2 auf 31.300 Hz
TCCR4B = TCCR4B & 0b11111000 | 0x01; //Timer 4 auf 31.300 Hz
pinMode (RGB, OUTPUT);
pinMode (fanpins, OUTPUT);
pinMode (dpin_Temp, INPUT);
pinMode (apin_Temp, INPUT);
//LCD Display
my_lcd.Init_LCD();
my_lcd.Fill_Screen(BLACK);
my_lcd.Set_Rotation(1);
my_lcd.Set_Text_colour(WHITE);
my_lcd.Set_Text_Size(3.5);
my_lcd.Set_Text_Mode(1);
my_lcd.Print_String("Temperaturen", CENTER, 3 );
my_lcd.Print_String("Wasser", LEFT + 2, yText [0] );
my_lcd.Print_String("Luft", LEFT + 2, yText [1] );
//Wasser Temps Raster
my_lcd.Set_Text_colour(COLD);
my_lcd.Print_String("C", hhigh + Grad [0] + dxC, yText [0] ); //Erstes C
my_lcd.Set_Draw_color(COLD);
my_lcd.Draw_Circle (hhigh + Grad [0], yText [0] + Grad [2], Grad [3]);
my_lcd.Set_Text_colour(RED);
my_lcd.Print_String("C", hhigh + Grad [1] + dxC, yText [0] ); //Zweites C
my_lcd.Set_Draw_color(RED);
my_lcd.Draw_Circle (hhigh + Grad [1], yText [0] + Grad [2] , Grad [3]);
//Lüfter Bezeichungnen
my_lcd.Set_Text_Size(2);
my_lcd.Print_String("Radiator", hhigh - 200, yText [2] );
my_lcd.Print_String("unten", hhigh - 200 + 18, yText [2] + 20 );
my_lcd.Print_String("Radiator", CENTER, yText [2] );
my_lcd.Print_String("oben", CENTER, yText [2] + 20 );
my_lcd.Print_String("Gehaeuse", hhigh + 100 , yText [2] );
//Template Power Fans
my_lcd.Set_Draw_color(GRAY);
for (uint8_t t = 1 ; t < 4 ; t++)
{
uint8_t rr = 0;
for (uint8_t r = 0 ; r < 10; r ++) {
my_lcd.Draw_Rectangle ( tt[t], yy[0] - rr, tt[t + 3] , yy[1] - rr) ;
rr = rr + 13;
}
}
}
void loop() {
//timed interval
uint16_t interval = 2000;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval ) {
// 1. Temperatures
//....1.1 Water
NTC_temperaturberechnung(Celsius);
//....1.2Air via oneWire
Luft_Temperaturen (oneTemp);
}
// 2. Fan controller
//....2.1 Radiatorlüfter Geschwindigkeit
WasserLuefter (fanspeed_wasser);
analogWrite (fanpins [1], fanspeed_wasser [0]);
analogWrite (fanpins [2], fanspeed_wasser [1]);
//....2.2 Gehäuselüfter Geschwindigkeit
GehaeuseLuefter (fanspeed_luft);
analogWrite (fanpins [0], fanspeed_luft [0] );
analogWrite (fanpins [3], fanspeed_luft [1] );
//analogWrite (fanpins [4], fanspeed_luft [2] );
//3. Display
anzeige();
}
void anzeige () // LCD settings
{ uint16_t d;
uint16_t pwm [3] = {}; //0:none 1:SP 2:EK 3:Fractal
uint16_t prozent [3] = {};
uint16_t fanspeeds [3];
uint8_t s = 0;
uint8_t a = 0;
//water temp
my_lcd.Set_Text_Back_colour (BLACK);
my_lcd.Set_Text_Size(3);
my_lcd.Set_Text_Mode(0);
my_lcd.Set_Text_colour(COLD);
//my_lcd.Set_Text_Cousur(hhigh + Grad [0] - dxZahl, yText [0]);
my_lcd.Print_Number_Float(Celsius [0] , 1, hhigh + Grad [0] - dxZahl, yText [0], '.', 1, ' ');
my_lcd.Set_Text_colour(RED);
my_lcd.Set_Text_Cousur(hhigh + Grad [1] - dxZahl , yText [0]);
my_lcd.Print_Number_Float(Celsius [1], 1 , hhigh + Grad [1] - dxZahl , yText [0], '.', 1, ' ');
//Air temp
my_lcd.Set_Text_colour(WHITE);
my_lcd.Print_Number_Float( oneTemp [0] , 1, hhigh + Grad [0] - dxZahl, yText [1], '.', 1, ' ');
my_lcd.Print_Number_Float( oneTemp [1], 1 , hhigh + Grad [1] - dxZahl , yText [1], '.', 1, ' ');
//Power Fans
// my_lcd.Fill_Rectangle (209, 247, 256, 260); //### works here
// my_lcd.Fill_Rect (209, 247, 62, 5, RED); //### works here
fanspeeds [0] = fanspeed_wasser [0];
fanspeeds [1] = fanspeed_wasser [1];
fanspeeds [2] = fanspeed_luft [1];
if (0 > 1) { // ### This IF is just for testing purposes to enable oder disable the corrupt part
a = 0;
for ( a = 0; a < 3 ; a++ )
{
my_lcd.Set_Draw_color(70, 70, 70);
my_lcd.Fill_Rectangle (100, 100, 110, 110);
prozent[a] = map (fanspeeds[a], threshold_test[a + 1], 255, 0, 100);
stufen_neu [a] = round(prozent[a] / 10.0);
if (stufen_neu [a] != stufen_alt [a]) {
my_lcd.Set_Draw_color(70, 70, 70);
my_lcd.Fill_Rectangle (100 + 10, 100 + 10, 110 + 10, 110 + 10);
d = 0;
stufen_alt [a] = stufen_neu [a];
for (s = 0 ; s < stufen_neu [a] ; s++)
{
my_lcd.Set_Draw_color(70, 70, 70);
my_lcd.Fill_Rectangle ( tt[a], yy[0] - d, tt[a + 3] , yy[1] - d) ; //!! makes the display sta white
//my_lcd.Fill_Rect (tt[a], yy[0] - d, 62, 7, WHITE); //also doesn´t work
d = d + 13;
}
}
else {
Serial.print("No temperature change in sensor");
Serial.print(a);
Serial.print("\n ");
continue;
}
}
}
}

