Exercise-003 Defining initial transition function
In the protimer_state_mach.cpp, we will implement the state machine. First, let’s start with our initial transition.
#include "main.h" void protimer_init(protimer_t *mobj){ mobj->active_state = IDLE; mobj->pro_time = 0; }
protimer_state_mach.cpp
The Initial transition function is shown in above.
Create one function. void protimer_init().
Here, the function argument will be pointed to the main application structure. The main application structure is protimer_t; I will give the pointer variable name mobj. This variable we used throughout the state machine diagram.
And mobj->active_state = IDLE. We have got associated action(Initial transition action). That is, we have to initialize the mobj->pro_time = 0.
You have to call the protimer_init function from the main.cpp.
#include "main.h" /*Main application object */ static protimer_t protimer; void setup() { // put your setup code here, to run once: protimer_init(&protimer); }
main.cpp
In the main.cpp, first, let’s create the main application object as a global variable protimer.
protimer_t protimer is a main application object. You can also protect the main application object using the ‘static’ keyword. And send the address, write in the setup function; protimer_init(&protimer).
protimer_state_mach.cpp file has to share the prototype of that function.
For that, just copy the void_protimer(protimer_t *mobj) function declarator in protimer_state_mach.cpp and go to main.h and will give the prototype(Figure 1).
FastBit Embedded Brain Academy Courses
click here: https://fastbitlab.com/course1