Before we get into the code, let's first learn how to launch our first program on the Gamebuino!
Launch the Mu software. This is a text editor in which you will write your programs. If you are in the workshop with us, it is possible that we have already launched it for you. Simply click on its icon in the taskbar to open it!
An empty window appears (see image below): this is where you will write your first program! If the window does not appear, or if an error message is displayed, close everything, and start over from the beginning: you may have skipped a step! 3.Click on "Mode'' on the left corner of the Mu window. Then, select : Adafruit Circuit Python. And press OK.
Copy the code below, and paste it into the Mu window. Don't try to understand what this means, don't worry we'll see it together later!
from gamebuino_meta import begin, waitForUpdate, display, buttons, color
while True:
waitForUpdate()
display.clear()
display.print("Hello world")
You may have noticed in the little piece of code above, the lines can be more or less shifted to the right. This is called indentation and it's essential in the Python language that it be strictly respected. Otherwise the code will not work !
Many times, if there is a problem for your code to be executed, the mistake can come from there.
To shift a line, we must use the tab character (the key with two arrows). A line of code "belongs" to the instructions bloc defined by the first line above it with one step less of indentation.
This is an ugly sentence, but do not worry, you have plenty of time to understand all of this ! You will quickly become familiar with it, it is actually very simple.
You have just launched your very first program in Python, the result of which is to display the sentence "Hello, world" on the screen. It's a kind of tradition in the computer world: we create this first program to make sure that everything works as it should. So that's good news! If you see this sentence on the screen of your Gamebuino, it is because we can get down to business.
If nothing appears, try to start over from the beginning. In programming, it is normal to make mistakes, and not everything necessarily works the first time, even for the most experienced programmers!