if i call a function
screenflash()
can i make it run in the background while running the rest of the loop? As it is waiting until that function stops then it will continue with the rest of the code
so i have a function that will rotate the background colour of a tft screen
but also at the same time i want it to continue to send a TXT message to multiple phones while the screen is flashing
Nothing happens in the background.
Things are sequential.
Things do run very fast as long as the code is none blocking.
Hi Mike
You will need to change the design of your function to achieve what you want.
Break it down into (a) stuff you will do once to set things up before you start flashing (if required), and (b) something you will do every XXX milliseconds to move the effect on, a bit like the individual frames of an animated movie.
To call your function that does (b) at the right interval, look at an example program in the Arduino IDE called BlinkWithoutDelay. It just blinks an LED off and on, but the same approach can be used to call functions at regular intervals while letting other code in loop() execute as well.
You may also need a boolean variable that you set to true when you want to start the effect, and which gets set to false when the effect has finished. This combined with the BlinkWithoutDelay timing will make sure that your function gets called in the right circumstances.
If you post your screenflash() function and the rest of your program, I'm sure you'll get more specific advice too. Please use code tags when posting - the </> button on the toolbar.
ADDED Also suggest looking at @Robin2's tutorial on program design: Planning and Implementing an Arduino Program - Programming Questions - Arduino Forum
Regards
Ray
Hackscribble:
Hi Mike
You will need to change the design of your function to achieve what you want.
Break it down into (a) stuff you will do once to set things up before you start flashing (if required), and (b) something you will do every XXX milliseconds to move the effect on, a bit like the individual frames of an animated movie.
To call your function that does (b) at the right interval, look at an example program in the Arduino IDE called BlinkWithoutDelay. It just blinks an LED off and on, but the same approach can be used to call functions at regular intervals while letting other code in loop() execute as well.
You may also need a boolean variable that you set to true when you want to start the effect, and which gets set to false when the effect has finished. This combined with the BlinkWithoutDelay timing will make sure that your function gets called in the right circumstances.
If you post your screenflash() function and the rest of your program, I'm sure you'll get more specific advice too. Please use code tags when posting - the </> button on the toolbar.
ADDED Also suggest looking at @Robin2's tutorial on program design: Planning and Implementing an Arduino Program - Programming Questions - Arduino Forum
Regards
Ray
thanks for that i will check it out..... i know my coding is very basic and i know there will be a better way to do things. but hey i gotta start somewhere