Buttons
In this chapter, we'll learn how to change the color of the screen and write different words by clicking on different buttons.
For coding anything with buttons, you need I/O block section.
Find the "when button left pressed" in the I/O block section and drop it into the drawing area.
When we press this particular button, we want the screen to turn black, and for the word "left" to appear on it.
To do so, create this block:
The 'X' and 'Y' coordinates in the block indicate where the word will show on the screen.
Feel free to choose any color you want for the background of the screen or for the word. We'll use black for the background and white for the word in this example.
Don't forget the "push frame" block at the end.
Now we'll write the code for what happens when the pushbutton is released.
Find this block in the I/O block section:
We want for the screen to turn black, and for the word to disappear.
Let's repeat this for each button.
This is what your code should look like at the end:
Don't forget the "loop forever" and "scan buttons" blocks at the end.
Click on the Run button, and start pressing the pushbuttons on your gaming console.
If the color of the screen changes and the words appear, your code was successful.
For coding anything with buttons, you need I/O block section.
Find the "when button left pressed" in the I/O block section and drop it into the drawing area.
When we press this particular button, we want the screen to turn black, and for the word "left" to appear on it.
To do so, create this block:
The 'X' and 'Y' coordinates in the block indicate where the word will show on the screen.
Feel free to choose any color you want for the background of the screen or for the word. We'll use black for the background and white for the word in this example.
Don't forget the "push frame" block at the end.
Now we'll write the code for what happens when the pushbutton is released.
Find this block in the I/O block section:
We want for the screen to turn black, and for the word to disappear.
Let's repeat this for each button.
This is what your code should look like at the end:
Don't forget the "loop forever" and "scan buttons" blocks at the end.
Click on the Run button, and start pressing the pushbuttons on your gaming console.
If the color of the screen changes and the words appear, your code was successful.