cancel
Showing results for 
Search instead for 
Did you mean: 

How can i flash the colors of the boxes with TouchGFX ?

TSour.1
Associate II
 
3 REPLIES 3
Yoann KLEIN
ST Employee

Hello @Community member​ ,

I'm not sure to understand what you mean with "Flash the colors".

Can you please elaborate ?

Thanks,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX
TSour.1
Associate II

Hello @Yoann KLEIN​ 

thank you for your return, I want to make the color of a block flashes for a specific duration.

I don't know if it's possible !

Thanks,

Hello,

There is a very easy way to do that :

  • In Screen1View.cpp, implement the handleTickEvent() method (don't forget to declare this function also in the Screen1View.hpp file).
  • In Screen1View.hpp, declare a boolean variable to toggle the color of your widget (e.g. bool toggle=false), and a integer variable that you can initialize at 0 (e.g. int counter=0)
  • Then, in the handleTickEvent() method, you can increment your counter every time the method is called, and implement a switch case mechanism in order to toggle the color of your widget, like this:
counter++;
 
if(counter%60 == 0) //  toggle color every second
{
	toggle = !toggle;
 
	switch(toggle)
	{
	case false:
	box2.setColor(red);
	break;
 
	case true:
	box2.setColor(blue);
	break;
	}
 
	box2.invalidate();
	counter=0;
}

Please note that you can change the blinking rhythm by modifying the "if(counter%60 == 0) " condition (For example : "if(counter%30 == 0)" will enable you to change the color every half second).

Let me know if that helped,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX