using ILI9431 without the blinking

Status
Not open for further replies.

Bastiaan

Well-known member
for a science project and to test people if they can recognize vibrations with the fingertips.
I am trying to program a ILI9431 2.4inch tft display without the blinking.

Problem: What i am trying to do and where I get stuck in the following Void loop.

Program function:

input voltage A0=0V Yellow screen with a large white Zero in the center// ok works and without blink
input voltage A0=1.5V Red screen with a large white One in the center wait for a vibration 1//starts blinking
input voltage A0=3.3V Blue screen with a large white Two in the center wait for a vibration 2 //starts blinking

Press button red or blue

go back to screen Yellow show a large white Zero and wait for another signal from labchart.

I can switch from Yellow to each and the other colours, but how do I stop the blinking? if I make a transistion from Yellow to red the 1 starts blinking I really dont have a clue, do I use pointers?

down below is the attached program. I clearly have some fundamental problems with how this can be done. therefore help is greatly appreciated.

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

int center_x=110;
int center_y=50;
int Fsize=20;

//void loop steps
int prevX=0; //Yellow
//int prevX1=512; //Red
//int prevX2=1023; //Blue
int prevcounti=0;

//steps numbers screen

void setup()
{
Serial.begin(9600);
tft.begin();
tft.setRotation(3);
tft.setCursor(150,100);
tft.fillScreen(ILI9341_YELLOW);

}


void loop(void)
{
int input=analogRead(A0);
Serial.print("input ");
Serial.print(input);
delay(10);

if(input!=prevX)//0
{
TextInfront();// call this function to get to the tft.print("0") to switch it on
// should i give a parameter to this function? how? pointers?
}
else
{
TextInfront();// call this function to get to the tft.print("0") to switch it off
}

Serial.print("Prev X ");
Serial.println(prevX);
delay(1000);
int prevX=input;

}
//--------------------step 1 display shows Zero

void TextInFront()
{ int counti=0;


Serial.print("counti ");
Serial.println(counti);

if(counti!=prevcounti)
{
tft.setCursor(center_x,center_y);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(Fsize);
tft.println("0");
counti++;
}
else
{
tft.println("");
}
prevcounti=counti;

}

help is greatly appreciated.

sincerely yours

Bastiaan
 
Sorry not really sure what you are saying here with the code. You say things like Blink and Vibration but not sure what you mean by this.

That is are you wish to update the screen and change text from Yellow display with white text to Red display with white text and not see a flash in the area of the text?

That is if you do do something like tft.fillScreen(RED) followed by a tft.print("1")... (Note I did not use the correct syntax and set text cursor...)
That you don't want to see where the 1 is displayed to draw all RED and then text shown?

The easiest code is to do logically above, but yes you will see area redraw twice... You can instead do more complex update, where you to do a fill rect for every line above where text is, another fill rect for the lines the text displays up to the start of text output, folllowed by Opaque text output, followed by another fill rect to draw the rest of the lines that have text area to end of display and a final fill rect to fill all of the lines below the text....

Or are you saying you wish to have the text "1" flash on and off without redrawing the whole screen? You can probably use Opaque text output (set both fg and bg font color), to draw over region to draw it, and to undraw could just do fill rect...

You have not specified what board you are using... If T3.6, you have enough memory one could use a version of library with a backing frame buffer, where you do all of your updates to memory and then tell the screen to update...

But again not sure what you are asking
 
Only looked a second - but are one of these helpful? Either the BOLD or the UNDERLINED addition - perhaps both?

Code:
[U]static int16_t doclear=1;[/U]
if(input!=prevX)//0
{
  TextInfront();// call this function to get to the tft.print("0") to switch it on
  // should i give a parameter to this function? how? pointers?
  [B]input = prevX;[/B]
  [U]doclear=1;[/U]
}
else
{
  TextInfront();// call this function to get to the tft.print("0") to switch it off
  [U]doclear=0;[/U]
}

That delay(1000) is going to make it act funny?
 
Sorry not really sure what you are saying here with the code. You say things like Blink and Vibration but not sure what you mean by this.

That is are you wish to update the screen and change text from Yellow display with white text to Red display with white text and not see a flash in the area of the text?

That is if you do do something like tft.fillScreen(RED) followed by a tft.print("1")... (Note I did not use the correct syntax and set text cursor...)
That you don't want to see where the 1 is displayed to draw all RED and then text shown?

The easiest code is to do logically above, but yes you will see area redraw twice... You can instead do more complex update, where you to do a fill rect for every line above where text is, another fill rect for the lines the text displays up to the start of text output, folllowed by Opaque text output, followed by another fill rect to draw the rest of the lines that have text area to end of display and a final fill rect to fill all of the lines below the text....

Or are you saying you wish to have the text "1" flash on and off without redrawing the whole screen? You can probably use Opaque text output (set both fg and bg font color), to draw over region to draw it, and to undraw could just do fill rect...

You have not specified what board you are using... If T3.6, you have enough memory one could use a version of library with a backing frame buffer, where you do all of your updates to memory and then tell the screen to update...

But again not sure what you are asking


no problem,

what I try to do is having a Yellow Screen with a white Zero in the center.
which should stay there during a change in voltage.

After a voltage change lets say a value of 512 the Red Screen pops up with a white one and stays there during the voltage change.

After 820 analog input value the screen should go to Blue with a 2 on the display. all of the numbers 0,1,2 should not blink during different voltage levels.

the background color should not change during voltage level as well but should stick to its state
0=Yellow
1=Red
2=Blue


sorry for writing such a confusing post.

new code:
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

int center_x=110;
int center_y=50;
int Fsize=20;


//void loop steps
int prev_val=0; //yellow
//int prevX1=1023; //Red
//int prevX2=1023; //Blue
int prevcounti=0;

//steps numbers screen



void setup()
{
Serial.begin(9600);
tft.begin();
tft.setRotation(3);
//tft.setCursor(150,100);

tft.setCursor(center_x,center_y);
}

void TFT_Background(uint16_t Colour)
{
tft.fillScreen(Colour);
}

void TextbeforeBackgroundOn(int x)
{
int on_off=x;
tft.setCursor(center_x,center_y);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(Fsize);
// Serial.println("what happens");
// Serial.println(on_off);
tft.println(on_off);
}

//-----------screeen backgrounds call them in the void loop if statements

void loop(void)
{
int i=0;
int input=analogRead(A0);
if(input<10&&i==0)//0
{i=1;
delay(100);
TFT_Background(YELLOW);
TextbeforeBackgroundOn(0);
Serial.print("State Yellow ");
Serial.print(i);
Serial.print(" state ");
Serial.print(" input ");
Serial.println( input );
}
else
{
if(input>0&&input<1000&&i==2)
{
TFT_Background(RED);
TextbeforeBackgroundOn(1);

delay(100);
Serial.println("State Red ");
Serial.println(i);
Serial.println("input ");
Serial.println(input);
i=3;
}
else
{
if(input>1022&&i==3)
{
TFT_Background(BLUE);
TextbeforeBackgroundOn(2);

delay(100);
Serial.print("State Blue ");
Serial.print(i);
Serial.print("input ");
Serial.println(input);
i=0;
}




}


}

}
 
Oh and youd have re-decalred a STACK version of this at the end of loop() that will mess with the global static so my BOLD would be redundant::
int prevX=input;

}
//--------------------step 1 display shows Zero
 
thanks for the patience,
I am currently using a teensy3.2
what I try to do is having a Yellow Screen with a white Zero in the center.
which should stay there during a change in voltage.

After a voltage change lets say a value of 512 the Red Screen pops up with a white one and stays there during the voltage change.

After 820 analog input value the screen should go to Blue with a 2 on the display. all of the numbers 0,1,2 should not blink during different voltage levels.

the background color should not change during voltage level as well but should stick to its state
0=Yellow
1=Red
2=Blue


sorry for writing such a confusing post.

new code:
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

int center_x=110;
int center_y=50;
int Fsize=20;


//void loop steps
int prev_val=0; //yellow
//int prevX1=1023; //Red
//int prevX2=1023; //Blue
int prevcounti=0;

//steps numbers screen



void setup()
{
Serial.begin(9600);
tft.begin();
tft.setRotation(3);
//tft.setCursor(150,100);

tft.setCursor(center_x,center_y);
}

void TFT_Background(uint16_t Colour)
{
tft.fillScreen(Colour);
}

void TextbeforeBackgroundOn(int x)
{
int on_off=x;
tft.setCursor(center_x,center_y);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(Fsize);
// Serial.println("what happens");
// Serial.println(on_off);
tft.println(on_off);
}

//-----------screeen backgrounds call them in the void loop if statements

void loop(void)
{
int i=0;
int input=analogRead(A0);
if(input<10&&i==0)//0
{i=1;
delay(100);
TFT_Background(YELLOW);
TextbeforeBackgroundOn(0);
Serial.print("State Yellow ");
Serial.print(i);
Serial.print(" state ");
Serial.print(" input ");
Serial.println( input );
}
else
{
if(input>0&&input<1000&&i==2)
{
TFT_Background(RED);
TextbeforeBackgroundOn(1);

delay(100);
Serial.println("State Red ");
Serial.println(i);
Serial.println("input ");
Serial.println(input);
i=3;
}
else
{
if(input>1022&&i==3)
{
TFT_Background(BLUE);
TextbeforeBackgroundOn(2);

delay(100);
Serial.print("State Blue ");
Serial.print(i);
Serial.print("input ");
Serial.println(input);
i=0;
}




}


}

}
 
drawpixel maybe?

The thing is that the code for drawing the background is a function that is being called from the library tft.
on top of that function, is a called function that draws, scales a zero over the background.
which will stay on top of the background, during the conditions in the loop.

what I am trying to do is, stopping the blinking of the Zero, or any number, it should stay there during the different color phases. I am wondering how to do this.

should I use the pixel function and fill the whole screen yellow with a white part in the center that resembles a Zero or a One?

I am kindly asking for your expertise.

Best

Bastiaan
 
Code is too hard to read without CODE formatting.
code.PNG

I get as far as seeing things like already noted above - local/stack variables declared and initialized like this:
Code:
void loop(void) 
{
[U]int i=0; [/U]
int input=analogRead(A0);
if(input<10&&[U][B]i==0[/B][/U])//0

That variable 'i' will always be "==0". The prior note I indicated where it seemed some screen update would always be drawn in each loop() because the variable was not tracking the need for an update.

That may not be the problem as I can't read the code - but that test for I==0 seems to just be a waste.
 
Code is too hard to read without CODE formatting.
View attachment 10741

I get as far as seeing things like already noted above - local/stack variables declared and initialized like this:
Code:
void loop(void) 
{
[U]int i=0; [/U]
int input=analogRead(A0);
if(input<10&&[U][B]i==0[/B][/U])//0

That variable 'i' will always be "==0". The prior note I indicated where it seemed some screen update would always be drawn in each loop() because the variable was not tracking the need for an update.

That may not be the problem as I can't read the code - but that test for I==0 seems to just be a waste.

ill check that, i have the board at home at the moment, now I know what you mean with formatting:)
 
Status
Not open for further replies.
Back
Top