ILI9341 Blink TFT teensy3.2 help

Status
Not open for further replies.

Bastiaan

Well-known member
Hi I am having a problem with the following software syntax.

What I am trying to do:

read in voltage divider Values 0...4096 from a function generator.(0...10V) by using a simple voltage divider I get the voltages I need.

seperating the voltage levels in to ranges by using an If Statement, i get a yellow, red, and blue screen.
therefore I use the command tft.fillScreen(ILI9341_BLACK, YELLOW, RED or BLUE);

In front of this background I would like to have during these If statement a String with a Number or a variable or question mark to show up. it shows up but it blinks.

how do I stop the blinking? it is quit frustrating, a clear helping answer would be most kind.

point of notice: The first If statement<250 can be used to recreate all the following if statements, just change the colours to see if it blinks.

I used the print commands with the \n on the end, for overwritting the print command,
I tried looking at the GFX Files, which i simply dont grasp that well.
removing the fillscreen will work only for the black screen but not for the other colours.
and I know that setTextColor(ILI9341_WHITE,ILI9341_BLACK/or other colour works only partly, try it yourself if you dont believe me).

tx for readin this post.

sincerely yours

B
 

Attachments

  • TweenyTodd123_v3.ino
    7.4 KB · Views: 90
Sorry, I have not gone through your code in detail and am not sure what all of the issues are you are trying to solve, but will try to give a few hints to hopefully help you fix it.

If you are running on a Teensy 3.2, you might want to try the much faster ili9341_t3 library. It probably won't fix your stuff, but may help some.
But lets for example take a look at the section:
Code:
    if (dataNew < 250)
    {
         tft.fillScreen(ILI9341_YELLOW);
         tft.setCursor(0,0);
         tft.setTextSize(10);
         tft.setTextColor(ILI9341_WHITE); 
         tft.print("       ?        "); 
         tft.setTextColor(ILI9341_YELLOW);
         tft.setCursor(0,100);
         tft.print("                ");
         Serial.print("    ");
         Serial.print(dataNew);
         Serial.println(" Case 0 = ?  bl ");
    }
    //between loops
Again quick read through code, the only delay I see in loop is a delay of 50ms after the ADC read before this if...

So assuming your ADC values don't change much between calls. So lets say your dataNew is at 200. You are going to be calling this many times a second

Which sort of acts like this: Erase screen, draw something, repeat...

Which will give you lots of flickering and may not actually be able to read whatever it is you are outputting.

What would I do?

Probably keep the state from the previous call. That is keep a global variable, that you set at the end of loop like: dataPrev = dataNew;

Then in your condition, only fill screen when the logical state changed...
Maybe something like in the condition for <250 change the fillscreen, to: if (dataPrev >= 250) tft.fillScreen(...);

Now to output the text, I would do a couple of things:
1) test if dataPrev != dataNew --- If equal no use in updating the display

2) For any titles you wish to display, I would probably output them once as part of the test for fillScreen I mentioned above.

3) I would use opaque text output, so characters that output overwrite the data beneath them.
Code:
  tft.setTestColor(ILI9341_WHITE, ILI9341_YELLOW);
  tft.print(dataNew);
  tft.print("  ");

Note: in the above, you were not outputting any actual data like datanew, but I showed how I would do it, the above case, would be handled by simply not outputting unless the state changed...

Hope that helps
 
Hi KurtE,

Tx for the library, didnt know that.
ok I stopped the blinking but the background doesnt come along, ill install it tomorrow.


What I am trying to do is the following each predefined voltage level (If Statement) to show between voltage ranges to create a Screen. each screen has a fillscreen Background Color and in front of the background I have the following strings showing extra which state they are:
State 0 = ?(Black screen), white Questionmark.
State 1 = 1(Yellow Screen) White one
State 2 = 2(Red Screen); White Two
State 3 = 3(Blue Screen); White Three
State 4 = Press the Red or Blue Button White Text.
Repeat if I give a next step function with the function generator.

if (dataNew < 250)
{


if(dataPrev !=dataNew)
{

tft.setCursor(0,100);
tft.setTextSize(10);
tft.setTextColor(ILI9341_WHITE);
// tft.print(dataNew);
tft.print(" ? ");
tft.print(" ");
Serial.print(" ");
Serial.print(dataNew);
Serial.println(" Case 0 = ? bl ");

dataNew=500; //move to other if statement


}
}
else
{
tft.fillScreen(ILI9341_YELLOW);

}





the fillscreen is somewhat of a problem I would reallly like to to have the fillscreen fill my whole screen Yellow + show a 1 on the screen without blinking...
and after the if statement is finished it should move on towards the next voltage level shown on the Screen in RED.

I tried the setTextColor(ILI9431_WHITE,ILI9431_YELLOW); but it partly solves the problem, but not the blinking.
 
Note: please use the code tags # as it makes code easier to read...

Code:
if (dataNew < 250)
{
  if(dataPrev !=dataNew)
  {
    tft.setCursor(0,100);
    tft.setTextSize(10);
    tft.setTextColor(ILI9341_WHITE);
    // tft.print(dataNew);
    tft.print(" ? ");
    tft.print(" ");
    Serial.print(" ");
    Serial.print(dataNew);
    Serial.println(" Case 0 = ? bl ");
    dataNew=500; //move to other if statement
  }
}
else
{
  tft.fillScreen(ILI9341_YELLOW);
}
Again if your code for where dataNew is 500 draws something like fill the screen with RED, and therefor you see a blink where it goes Yellow -> Read or the like and then you do another read and it blinks again... Then it is probably doing exactly what you are telling it to do.

Also with analog reads, I would suspec that you are not getting a steady stream of the exact same value... Maybe something like:
220 219 221 220 ... So again you will run through similar stuff... Could do averaging, could do slop factor, could do...

You probably need to setup your code to remember states. Like I am in yellow zone and I have reported it, so don't report again (or maybe report again if the last reporting was over N seconds (or milliseconds) since the last time I reported it.

You just need to stand back a foot or two and logically walk yourself through your code. and logically see what happens.
 
I have heared that before:),
yes I took a step back and added another condition in the if statement behind the Voltage level, millis-previousMillis>Interval
which did the trick. it runs smoothly now, i have to admit the teensy is so darn fast.

I dont know what slop factor means, it does calculate the slope?
 
Status
Not open for further replies.
Back
Top