Display Block & Color Lamp Block

In this tutorial, I will cover the adjustments of the display and the color lamp blocks from the LEGO Mindstorms NXT-G. Today I will show you how to use the color lamp in order to make your robot more interesting or how to display sensors values or try to draw something on the screen of the brick.

  • #23
  • 30 May 2013
  • 8:55

Basic NXT Tutorials

The next episode of this series isĀ Episode 35, where I go through the touch sensor.

Smile Face

- NXT-G source code of program that draws a smile face on the brick's screen.

Sample program using the color lamp

- NXT-G source code;

Distance to the wall

- NXT-G source code of a program that shows on the screen the distance to the wall in centimeters;

English

Preview/Introduction

In this tutorial I will cover the display and the color lamp blocks. For the time being I will skip the send message block, because I will talk about Bluetooth in one of the next tutorials. Today I will show you how to use the color lamp in order to make your robot more interesting or how to display some values of the sensors or try to draw something interesting.

 

Drawing a smile

Now let's take a look at the display block. There are four options and the first one is called image. Then we have the option to clear the screen. If it is checked it will clear the screen and afterwards it will display the image. Otherwise it will leave the previously displayed things. Then we can choose from a number of predefined images and when we select one it will be displayed on the screen. Here we have x coordinate and y coordinate. The x coordinate can variate from 0 to 99 and the y coordinate can variate from 0 to 63. You can see the result on this block here. For the more enthusiastic ones you can go to drawing, where you can draw points, lines or circles. To illustrate it I will try to make a smile. First I will uncheck the clear option and go to circle. I will make a circle at (33;50), which will be the left eye of our smile. I will take another display block and this time , I will make a circle at (66;50), which will be the right eye. Then I will take several lines. The first one will begin at (20;30) and it's end point will be (33;25). Okay, so again a display block, this one will begin at the end point of the previous one, so it is (33;25) and will end at (49;20). The next line will again begin at the previous ending point, so it is (49;20). It will end at (66;25). The last line will be from (66;25) to (79;30). At the end I will put a wait block in order to see the result. Because after the last display block the program will finish and we could not see the image drawn. I will set the time to 10 and download the program to see the result.

 

Visualize the smile

Now, let's see how the smile looks like. I will run the program and a smile is displayed.

 

Text and reset options

There are two more actions to be explored. The text action and the reset action. The reset action will clear the screen and will display the default screen, while an application is running. Using the text action you can display a simple text, you have entered here. For instance “Hello world!” and then set the x and the y coordinate or the line at which it will be visualized and again you can check how it will look like, here. Another way to use the text action is by connecting a string to this input, here. Commonly the number to text block is used with the display block, because we need to display numbers, like the value of a sensor and the display could only visualize text. So we connect the value, here and then the converted string we connect to the display. Now I will show you a simple example, using the Ultrasonic Sensor. So I take the Ultrasonic Sensor block and connect it's value to the number to text block. All of this I will put in a loop, so that we can constantly track the distance to the wall. I will download the program.

 

Distance to the wall

I will use the scorpion robot to illustrate the use of the program. When we start the program, the distance to the closest object appears on the screen. If we move the object forward, the distance is changed. It gets smaller and if we move it backward it gets greater.

 

Color Lamp

The color sensor can be used no only as a sensor, but also as a color lamp. It can generate light in three different colors – red, green or blue. Unlike the regular nxt lamp, which is controlled from the move or from the motor block, the color lamp has it's own block. In the adjustments you can set on which port is connected the color sensor, then whether to turn on or turn off the lamp and then in which color to generate light. To illustrate the block I will make a simple program. It will change it's color each second and it will repeat this three times. I will begin with the red color, than I will wait for second, after which I will change the color to green. Then again wait for a second, afterward change the color to blue and then I will wait again for a second. All of this I will put in a loop, which will repeat itself three times. Afterward I will turn the lamp off. Let's download the program.

 

Color lamp sample

After we start the program it starts to generate light. Each color last for one second and it is repeated three times. Afterward the lamp is turned off.