Pressing the buttons

Pressing the buttons

Nibble has 7 main clickable buttons, 1 reset button, and 1 power switch. It's quite simple - you press the button and something happens.

Only the main 7 buttons are programmable, while the remaining two always have the same function.

The buttons have tiny white text next to them so you know which is which.

On the left side of the console there are directional buttons and the menu button, while on the right side A and B buttons.

We're going to focus here on using the functions of drawing on the screen, but this time we're controlling it with a simple press of a button.

This gives us much more flexibility and dramatically improves the possibilities of a program.

random image

This program is really simple - it changes the color of the screen and writes a simple text when a button has been pressed.

The screen color and the text are different depending on the button that has been pressed.

The system that is used on Nibble is called the callback system, meaning that the button presses are small events that trigger whenever a button press has been detected.

That way there is no checking whether the button has been pressed or not in the loop section, but rather only when a button has been pressed a button press function is called.

If you decide to write your own program using C/C++, check this LoopManager in the loop section as well as button callbacks in the setup section. Those will guide you and help you write your own code
Another way of activating something via a button is by releasing the button.
This way, the event will happen only after the button has been released and not when it has been pressed.

Change your program up a bit to look like this, and then try it.

random image

Holding the buttons and multiple functions

Now we go a bit more advanced.

Besides activating the button on press and release, you can also activate it after holding it down for a certain amount of time.

Additionally, you can add multiple events to a single button.

For example, let's set the button up so that it draws a circle on the screen after it has been held down for two seconds.

Also, when you release it, it will color the screen black.

random image

We've also done something similar to the button-down.

This will help you a lot especially when the coding movement for your character in games.

The combinations for this are nearly endless and you can create wonders using these three simple methods.