LED switch on/off

I am currently working on a LED screen and I want it to display different sprite animations. My goal is to have it so two buttons control whether the display is on or off.

The problem I am having is that whenever I press the “on” button, the animation is executed just once and I am unable to switch it off when I press the “off” button.

The only way it works is for me to wait until the animation finishes. If I press the “off” button then, the screen does turn off.

I eventually want to have the animation loop indefinitely until I press the “off” button. But for now, as long as I am able to turn the screen “off” at will without having to wait the animation out is fine by me.

I have attached my code for reference.

FYI, I am a newbie at programming so any tips to condense, streamline, or plain improve my code are welcome.

Pokemon.ino (23.2 KB)

Either take a look at interrupts, or add button checks more frequently.