A little bit of colour

Step 4
Step completed?

Let's brighten up our text with colors!

Challenge #2

We have understood how to write text on the screen, but it is white. Let's try to write it in blue for example! We'll help you a little bit: the instruction to change the color is as follows: display.setColor(color.RED) It's up to you!

Need help?

  • Don't forget what we saw above: in Python, each line is equivalent to an instruction, and the instructions are executed one after the other: so you have to write the instruction to change the color just before the instruction to write our text!
  • There is a small pitfall in the example we have given you: indeed, this code changes the color to red, while we want blue. Simply replace RED with the desired color, in English.
  • In display.setColor(color.RED) (and in all the instructions we will see later), case sensitivity (upper and lower case) is very important! If you write the same thing in lowercase, the program will no longer work.

Expected result

Solution

See
from gamebuino_meta import begin, waitForUpdate, display, buttons, color

while True:
    waitForUpdate()
    display.clear()
    
    display.setColor(color.BLUE)
    display.print("My name is Bob")

Explanations

The instructions are read one after the other. So we told our program to select the blue color, and then write the text on the screen, with the color previously chosen.

Go further

Try to change the color, for example with YELLOW, PINK, BROWN... Try also to write several sentences in a row, in different colors. You shouldn't have too many problems!

If you block, look at the little program we made:

See
from gamebuino_meta import begin, waitForUpdate, display, buttons, color

while True:
    waitForUpdate()
    display.clear()
    
    display.print("Hello!")
		
    display.setColor(color.BLUE)
    display.print("My name is Bob.")
    
    display.setColor(color.RED)
    display.print("\n")
    display.print("What's your name?")

Nothing new in all this! We only added instructions, in the right order. You don't know display.print("\n"): this instruction simply allows you to make a line break.

Steps