Determining order buttons are pressed

Hi I have a project for an interactive display where there are 5 buttons which are answers to questions. If the questions are answered in the correct order then an output should go high but if they are answered in the wrong order a different output should go high. Could somebody give me some direction on how to achieve this? I understand how to turn an output on if an input is triggered it's getting the board to determine the order the inputs were triggered that I'm struggling with.

I've programmed this on a PLC which works well but is an expensive way or doing things and it seems to me that the Arduino is perfect for this application.

Any help would be much appreciated.

Google "State Machine" .

Could somebody give me some direction on how to achieve this?

You have an array with the numbers of the buttons in the correct order.

Then you read what button is pressed and see if this is equal to the first array element, if it is you increment a variable which tells you what the next array element to press. If there is no match then game over and output your fault condition. However you might want to delay this feedback until all the answers are in to make it harder to just guess the answers.

Nice, Mike!

Thanks for the input!

How about this.

Define an empty string

String answers = ""; String target = "abcde"; boolean okay = true;

Then write your button scanning routines (partially pseudocode)

void loop()

{ if (button1 pressed) answers = answers + 'a'; if (button2 pressed) answers = answers + 'b'; if (button3 pressed) answers = answers + 'c'; if (button4 pressed) answers = answers + 'd'; if (button1 pressed) answers = answers + 'e';

if (!target.startsWith(answers)) okay = false;

if (!okay){ do what needs yo be done}

}

This very simply keeps track of what order the buttons were pressed, and checks after each press to see if the user has gone off track.