Play with the red button!

This time, we'll do something similar to the Simple timer example. The code, on the other hand, will not execute in the loops but will begin when you click on the big red button.

If you wish to code something with the buttons, head to the I/O block section

To begin, drag this "When big button pressed" block onto the drawing area. 

Inside this I/O block will be the code for what should happen once you hit the button. 

We want the matrix to light up when we press the button and switch off when we release it. 

Change the 0 in the "fill frame with 0" block to 255 to ensure it lights up. 

Also, don't forget the "push frame to matrix" so your code is executed properly. 

Now, let's code what'll happen once we release the button. 

Return to the I/O block section and look for the "when big button released" block. 

Drag an drop it onto the drawing area. 

You can duplicate the same "matrix" blocks inside it. 

This time, make sure to replace 255 to 0. 

Here's how your code should look: 

Your code is almost finished!

The only thing that's missing is the "scan buttons" block inside the "loop forever" block. 

It is critical to include these two blocks whenever you are coding anything with buttons; else, your code will fail. 

Click on the Run button, and start playing with the big red button.