Inputs seem to be remembered

This is going to be difficult to explain, and I must say wierd.
I have writen a very large programme which is behaving strangely. To be as quick as possible, it is a game where there are several butons that are pressed in a sequence.
If the sequence is wrong then the game starts again.
Trouble is that after they have got it wrong, if they press buttons before the game starts, the arduino seems to remember them. Like I said wierd.
From what I understand, the only time inputs are read, is when there is a digital readevent. All read events are not running, then when turned back on all the events (upto 3) are recorded, which were pressed when the readevents were not turned on.
Here is a snippet from my programme to try to illustrate this:
In the loop event i have:
if (dontrun == 0)
{
checkbuttonpress(); //sets out variables “in” to 0 or 1 depending on button press
}

in one of my subroutines (which deos go trough the loop event I have:
if (done_in_time == 0)
{
dontrun = 1;
myDFPlayer.play(41);//you got
delay(1000);
myDFPlayer.play(beat_tot);
delay(3000);
beat = 3;
beat_tot = 0;
allinszero;
dontrun = 0;
}

the variables are not important, but you can see that dontrun is set to 1 at the start and returned to 1 at the end. Yet if I press buttons while the delays etc are running, the button presses are remembered after the subroute has finished.
Hope that makes some sence, it is very strange.

Here is a snippet of my reply:
It’s because.

Please remember to use code tags when posting snippets

Sorry Im new, I did try but couldn;t find the / mark mentioned, I am not sure it maters in this case as it was just examples, not actual code. How do I edit it now.

You didn't post enough of your sketch to see where you made the mistake.

To be honest, and I don't mean to sound ignorant, but I don't think there is a mistake in the code, I think its an arduino thing, I guess what I am asking is, has anyone else ever encountered this problem.
Thereis 2900 lines of code, so posting that would be very confusing, I just posted the relevant part.

Uknod:
To be honest, and I don’t mean to sound ignorant, but I don’t think there is a mistake in the code, I think its an arduino thing,

No, you made a mistake. Of that, you can be certain.

Uknod:
I just posted the relevant part.

You didn’t post enough. You didn’t show the definition of “checkbuttonpress”. You don’t show the declarations of any of your global variables.
If you don’t want to show all of your code, at least put the parts that you do want to show into a sketch that will compile and reproduce the problem.

Are your buttons set up like this:

pinMode(switchIn,INPUT_PULLUP);

or, like this:

pinMode(switchIn,INPUT);

Uknod:
the variables are not important, but...

au contraire. It's important to know what *type * of variables one is working with.

      allinszero;

Is 'allinszero' a function you thought you were calling? You aren't. To call a function you have to provide an argument list (which may be empty).

      allinszero();

…but it could be a macro.

However, we still can’t see the code.

TheMemberFormerlyKnownAsAWOL:
...but it could be a macro.

Which is why I asked "Is 'allinszero' a function you thought you were calling?" :slight_smile:

Uknod:
To be honest, and I don't mean to sound ignorant, but I don't think there is a mistake in the code, I think its an arduino thing, I guess what I am asking is, has anyone else ever encountered this problem.
Thereis 2900 lines of code, so posting that would be very confusing, I just posted the relevant part.

To be honest, and I don't mean to sound condescending, but if you knew where the problem was, you wouldn't be posting here.

You can be sure, it is a problem with the code.

I just posted the relevant part.

Nope. Post the minimum, complete code that demonstrates the problem.

Why do you set dontrun to 1 and then set it to 0 when you don't do anything with it in between?

    if (done_in_time == 0)
    {
      dontrun = 1;
      myDFPlayer.play(41);//you got
      delay(1000);
      myDFPlayer.play(beat_tot);
      delay(3000);
      beat = 3;
      beat_tot = 0;
      allinszero;
      dontrun = 0;
    }

ToddL1962:
Why do you set dontrun to 1 and then set it to 0 when you don't do anything with it in between?

    if (done_in_time == 0)

{
     dontrun = 1;
     myDFPlayer.play(41);//you got
     delay(1000);
     myDFPlayer.play(beat_tot);
     delay(3000);
     beat = 3;
     beat_tot = 0;
     allinszero;
     dontrun = 0;
   }

Exactly, nothing is being done, yet the arduino still responds to inputs. The dontrun variable I put in to try to see if that would stop it. All it does is prevents the checkbuttonpress subrouting from running in the loop. Should even be neccessary.
The checkbuttonpress sub is mearly readevents for the inputs, but multiplied by 19 inputs. I can post it but I'm not trying to tell you to suck eggs.
allinszero, yes I did forget to put on the brackets, but again it was purely just something to try to solve it, again not in oringinal code and not relevant.
So let me expalin again. The sub routing that I have posted, records a readevent. IE chronologically:
1: no buttons being pressed
2: code above runs.
3: button pressed while sounds are made and delays etc.
4: before the end of the code no buttons pressed.
Then after the code, nothing should be happening, yet it goes to run upto 3 button presses.
The question I am asking is, has anyone ever had this problem before, I am sure it is a hardware thing, not code.

Uknod:
So let me expalin again. The sub routing that I have posted, records a readevent. IE chronologically:
1: no buttons being pressed
2: code above runs.
3: button pressed while sounds are made and delays etc.
4: before the end of the code no buttons pressed.
Then after the code, nothing should be happening, yet it goes to run upto 3 button presses.
The question I am asking is, has anyone ever had this problem before, I am sure it is a hardware thing, not code.

I don't have a clue because I can't see your code. Can't rule out the code and say it is hardware until we see the code AND a wiring diagram.

Floating inputs?
Who knows?

Uknod:
Then after the code, nothing should be happening, yet it goes to run upto 3 button presses.
The question I am asking is, has anyone ever had this problem before, I am sure it is a hardware thing, not code.

Also, there is no parallel execution of code in the Arduino because there is no executive or operating system. Therefore if you call a function from loop() that function executes fully before returning to loop(). That is why I was asking about the 'dontrun' variable. There is no buffering of digitalRead(). It just returns the state of the input at the time you read it.

Uknod:
The question I am asking is, has anyone ever had this problem before, I am sure it is a hardware thing, not code.

I have had problems like this before. It has always turned out to be a mistake I made in my code or a wiring mistake in my hardware.

ToddL1962:
Also, there is no parallel execution of code in the Arduino because there is no executive or operating system. Therefore if you call a function from loop() that function executes fully before returning to loop(). That is why I was asking about the 'dontrun' variable. There is no buffering of digitalRead(). It just returns the state of the input at the time you read it.

Yes that what I thought, that pretty much settles it, it must be something on the hardware of the inputs that is storring it, not sure how. Its basically 19 touch sensitive switchs. When I run other games from it it behaves itself, its just this particular game that it does it on. Very frustrating. I will try and emulate the problem by cutting down the complete programme to something smaller, then I will post all the code.