Go Down

Topic: New State machine tutorial (Read 8108 times) previous topic - next topic

jbellavance

#15
Jun 11, 2018, 10:41 pm Last Edit: Jun 11, 2018, 10:41 pm by jbellavance
Hi @echigard,

Then you have a motor with 3 states : running CW, stopped and running CCW
You would probably want to rember the last direction your motor was running before it was stopped. (last running state)

The sensor changes the state of the motor's state as:
- if the state is (runningCW or running CCW) then {last running state = motor's state; motor's state = stopped}
- else: the motor's state is the last running state.

button1 state falling -> motor state : running CW
button2 state falling -> motor state : running CCW

Jacques
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

jbellavance

Hi @cyrut2,

Read this first.

PullUp is just the exact opposite of PullDown. hence:
Code: [Select]
if (switchMode == PULLUP) pinIs = !pinIs;
If the mode is pullup, pinIs = not pinIs

Jacques
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

nielyay

Hello,

Thanks for the tutorial sir, its very helpfull.

Btw, i want to ask you on Part 1 files > TwoStateMachines

Code: [Select]
enum LedStates{ON, OFF};

*what is [enum] function?

nielyay

Hi,
its was great!
Thanks for sharing :)

dfitterman

I have enjoyed reading the example PDF's. Very helpful!
I think that there is an error in Part 1, p. 9. The case IS_FALLING should start with a call to toggleMachine() as shown in the c++ files. Without this it is not different from the previous example.

Go Up