Go Down

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

echigard

Hello Jacques,
                     first of all your tutorial is great. For the last two weeks I am trying to find a way for a project, I discovered State Machine and I saw that there is a solution there but now, with your tutorial I am sure that I have to walk in this direction.
 I would ask you please for a clue. How I should manage the state machine statement if I have more control devices, in my case I have a motor and its behavior depends of one sensor and two buttons. Sensor always start and stop, and the buttons change direction.
Any suggestion will be very welcome and thank you again for the tutorial

edgardo

jbellavance

#16
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.

Go Up