How to require an order of functions to be performed to make something happen

Hi everyone.

This may be a simple question but I'm not fluent in C++ so I may be overlooking the obvious.

I am trying to figure out how to perform an action only after certain other actions have been performed in the correct order. The desired result is for X to happen only after A,B,C,A, and D happened in that order. If A,B,D,C and A occur then X should not happen and so on.

How would I go about doing this?

Thanks,

Bruce

When these "actions have been performed", or "external data has been received"? You have complete control over any actions that you perform so that is a different situation than monitoring external events.

You need to be less abstract and explain what your letters ABC... really represent.

Read up about "state machine". It is a rather fancy name for a very simple concept. Use a variable to keep track of where you are in the process.

Suppose task J is running. When it is finished it sets the value of the variable to 'K' and then the code for task K would be something like this pseudo code (only a little oversimplified)

if (taskDue == 'K') {
  // do my stuff
  if (i am finished) {
     taskDue = 'L';
  }
}

By choosing the appropriate ID for the next task things can be done in any order

...R
Planning and Implementing a Program

Here is some more insight. I am trying to make my own frameless laser harp. My end goal is to have a locked box open or a hidden door open only when the right notes have been played in the right order.

So it isn't that I want to do things in a certain order but rather when the notes are played in a preset order then the Arduino sets a pin HIGH.

Brewskio:
Here is some more insight. I am trying to make my own frameless laser harp. My end goal is to have a locked box open or a hidden door open only when the right notes have been played in the right order.

So it isn't that I want to do things in a certain order but rather when the notes are played in a preset order then the Arduino sets a pin HIGH.

Then a state machine as described above will work by examining input.

The problem is exactly the same as a password unlock, of which there are a bazillion examples in this forum that you can search for.