Do you need tutorials ?
Moderator: Stef
Re: Do you need tutorials ?
I want create a timer event when countdown is 0 do something i dont know how use this
-
- Interested
- Posts: 24
- Joined: Sun Feb 27, 2022 3:27 am
Re: Do you need tutorials ?
I have no idea if this is the best approach (I'm learning C simultaneously), but here is what I've done to control some animations:
I have an animationTimer variable that I increment at the very end of my main() function.
Then, I pass it along with a "state variable" as pointers into my desired function so I can reset it when I perform whatever action I was waiting on the timer for:
I have an animationTimer variable that I increment at the very end of my main() function.
Code: Select all
if (animationTimer > 59){
animationTimer = 0;
}
else{
animationTimer++;
}
}
Code: Select all
void myFunction(u8 *animationTimer, u8 *functionState){
switch(*functionState)){
case functionReady:
*animationTimer = 0; //Prepare Timer
*functionState = functionDoStuff; //Advance case.
case functionDoStuff:
int timerEventVaue = 15;
if (*animationTimer > timerEventValue){
*animationTimer = 0;
//Do Stuff
*functionState = functionReady; //Reset the case.
}
break;
}
}