As a beginning programmer i'm testing the functions of the arduino tft. Displa constant figures are no problem but when i start to display variables all the problem starts.
I use the example from the arduino website in my main program to display the value measured on analog pin A0
My background is black and the color of the value of A0 is red.
But it seems like the value is shaking or flickering very fast...
I thought the cause would be an delay but i only use a 1ms delay in the whole program...
Sombody had eny experience with this or knows a better way for clearing a screen so values displayed don't overwrite eachother?
I have a counter, the value of that counter can be raised or lowered in steps from one.
I want to display this value on the arduino tft. I used the method of putting this variable in a char array shown on the aduino website. But when i startup my arduino the whole tft flickers and i can do nothing.
What is the right procedure go display an int value?
#2. In the IDE, Tools , Auto Format to give easier to read code. And take out all (most) of those blank likes. #3. If you want to display an integer, just do it. Don't try to convert it to something else. I think your display will accept that. #4. After you have your sketch reformatted, show it us again. This time put it in the code brackets The forum editor has a icon for that #
The flickering you're seeing is because you're wiping the area, then overwriting it with fresh text. For me, the solution was to instead get your library functions etc to overwrite the old text with the new text AND a background at the same time.
In the adafruit library thats done by a setcolor command that sets foreground and background in one hit tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
I took a look to the example from scrumfled but to be onhest my programming experience is not great enough to understand this code.
If i listen to scrumfled's solution i just have to clear the display and set background.
So with the arduino tft library i just have to call in my loop:
TFTscreen.begin() //to clear the display
TFTscreen.background(0,0,0) //i use a black background in my project
//rest of my program which write my variables to tft etc...
What procedure you people use?
My second idea is only to overwrite the old value when the value changes and then overwrite it with the new one. I couldn't manage to write a code for that mayby you guys have any starting tips?
To be ohnest a 16MHz chip refreshes 16.10^6 times per second i tought this flickering would 't be visible when using no delay.
Jazzy, maybe i didnt explain myself very well. The way I was fixing it was to overwrite the new data, including the background colour behind the text (not the entire background of the screen) in a single command.
scrumfled:
Jazzy, maybe i didnt explain myself very well. The way I was fixing it was to overwrite the new data, including the background colour behind the text (not the entire background of the screen) in a single command.
Can you maybe give an example code?
Let say something with a counter that counts and displays the value or something you thinkd that's good...
Why not see if the variable changes first, then if it does change, clear that segment of the screen and display the new number. This way you will get rid of the flicker and make it look much smoother and professional.
HazardsMind:
Why not see if the variable changes first, then if it does change, clear that segment of the screen and display the new number. This way you will get rid of the flicker and make it look much smoother and professional.
That is what i want to do but i can't figure out where to start...
Tonight after work i will try to set up some code so we have at least something to start!
int current_value, old_value; //set globally
current_value = analogRead(A0); // Read a value from analogpin 0
if(current_value != old_value) // Check to see if anything changed, if it did change show it, otherwise don't.
{
//print(" ", X, Y); // clear that section of the lcd
//print(current_value, X, Y); // show the new value
}
old_value = current_value; // Update old_value
minimal variation on the code of HazardsMind - update the old value only when there is a other one.
int current_value = 0, old_value =-1; //set globally
current_value = analogRead(A0); // Read a value from analogpin 0
if (current_value != old_value) // Check to see if anything changed, if it did change show it, otherwise don't.
{
//print(" ", X, Y); // clear that section of the lcd
//print(current_value, X, Y); // show the new value
old_value = current_value; // Update old_value only if it is changed
}