EV3 Scratch 指南

EV3 Scratch 指南 > Display(显示)

Display 显示

The EV3 can display images and write text.
EV3 可以显示图像和写入文本。

Display an image  显示图像

You can display an image for a specified time duration. The following program displays neutral eyes for 2 seconds.
您可以在指定的持续时间内显示图像。以下程序显示中性眼睛 2 秒钟。

Display  显示

After 2 seconds the screen is cleared and becomes white. There is also an option for displaying an image continously, without erasing.
2 秒后,屏幕被清除并变为白色。还有一个选项可以连续显示图像,而不进行擦除。

Display  显示

There is a command to clear the screen.
有一个命令可以清除屏幕。

Display  显示

The command display for X seconds can be composed from:
X 秒的命令显示可以由以下部分组成:

  • display image  显示图像
  • wait X seconds  等待 X 秒
  • clear display  清晰的显示
Display  显示

Move the eyes  移动眼睛

You can use the 5 buttons to display eyes which look into the direction of the button. We start with a neutral position, and can return to that position with the center button.
您可以使用 5 个按钮来显示注视按钮方向的眼睛。我们从中立位置开始,然后可以通过中心按钮返回到该位置。

Display  显示

With the left/right buttons you can move the eyes to the left and to the right.
使用左/右按钮,您可以将眼睛向左和向右移动。

Display  显示

With the up/down buttons you can move the eyes up and down.
使用向上/向下按钮,您可以上下移动眼睛。

Display  显示

Show a beating heart  显示跳动的心

By displaying two images in repetition we can create a simple animation. The following loop displays two hearts, a small one and a larger one.
通过重复显示两个图像,我们可以创建一个简单的动画。下面的循环显示两个心,一个小的和一个较大的。

We define a variable time which we set to 0.5. Then we enter a forever loop where we:
我们定义了一个可变时间 ,并将其设置为 0.5。然后我们进入一个 forever 循环,其中我们:

  • play a click sound
    播放咔嗒
  • display the large heart for time seconds
    显示大心形时间秒针
  • display the small heart for 2*time seconds
    显示小心形 2*时间秒
Display  显示

The up/down buttons serve to change the time variable by increments of 0.1.
向上/向下按钮用于以 0.1 为增量更改时间变量。

Display  显示

Write lines of text  编写文本行

You can write text to one of 12 lines. The following program sets the variable x to 1 and increases it to 12 in a loop, in order to write text on each line.
您可以将文本写入 12 行中的一行。下面的程序将变量 x 设置为 1 并在循环中将其增加到 12,以便在每一行上写入文本。

Display  显示

This is the result:  结果如下:

line 1 
line 2 
line 3 
line 4 
line 5 
line 6 
line 7 
line 8 
line 9 
line 10 
line 11 
line 12 

We also can slow it down and write line by line.
我们也可以放慢速度并逐行写入。

Display  显示

Write in different styles
以不同的风格编写

The second write instruction allows to write at any position (x, y)
第二个写入指令允许在任何位置 (x, y) 写入and to use one out of 6 styles:
并使用 6 种样式中的一种:
  • normal black  普通黑色
  • bold black  粗体黑色
  • large black  大号 黑色
  • normal white  普通白色
  • bold white  粗体白色
  • large white  大号 白色
Display  显示

Write at position (x, y)
写入位置 (x, y)

The following program uses two rotary encoders to write the letter x at position (x, y).
下面的程序使用两个旋转编码器在位置 (x, y) 写入字母 x

Display  显示

It produces output like this:
它产生如下输出:

x=80 
y=20
                    x 

Display sensor values  显示传感器值

Sometimes it is useful to display multiple sensor values on the display. This program displays 4 sensor values on the first 4 lines.
有时,在显示屏上显示多个传感器值很有用。该程序在前 4 行显示 4 个传感器值。

Display  显示

It produces output like this:
它产生如下输出:

123 
0 
2 
34.5 

To better write this line of information we can define a function which:
为了更好地编写这行信息,我们可以定义一个函数,该函数:

  • adds a text  添加文本
  • writes the number  写入数字
  • adds extra space after it (to erase erroneous digits)
    在它后面添加额外的空格(以擦除错误的数字)
  • increments the line number
    递增行号
Display  显示

Now we can display these values with an explanatory text (position, speed, etc.)
现在,我们可以用解释性文本(位置、速度等)来显示这些值。

Display  显示

It produces output like this:
它产生如下输出:

position = 123 speed = 0 color = 2 distance = 34.5 

Set the status light  设置状态指示灯

The status light around the buttons can be set to:
按钮周围的状态指示灯可以设置为:

  • green  绿
  • orange  橙
  • red  红

It also can be set to flashing mode called:
它也可以设置为闪烁模式,称为:

  • green pulse  绿色脉冲
  • orange pulse  橙色脉冲
  • red pulse  红色脉冲
Display  显示