屏幕

例程

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import lcd
import time

lcd.init()
a=0
while a<4 :
    lcd.clear()
    lcd.rotation(a)
    lcd.draw_string(30, 30, "Embedfire", lcd.WHITE, lcd.BLACK)
    time.sleep(1)
    a=a+1

lcd.clear()
lcd.rotation(0)
lcd.draw_string(140, 100, "Embedfire", lcd.WHITE, lcd.BLACK)
time.sleep(1)

lcd.clear(lcd.WHITE)
lcd.draw_string(140, 100, "Embedfire", lcd.BLACK, lcd.WHITE)

实验准备

  1. 野火K210 AI视觉相机 连接到 CanMV IDE

  2. 执行程序

运行结果

1.图像的左上角出现 Embedfire .此时屏幕没旋转

野火logo

2.图像的右上角出现 Embedfire .此时屏幕顺时针旋转了90度

野火logo

3.图像的右下角出现 Embedfire .此时屏幕顺时针旋转了180度

野火logo

4.图像的左下角出现 Embedfire .此时屏幕顺时针旋转了270度

野火logo

5.图像的中心出现 Embedfire

野火logo

6.图像的颜色和背景都和上图的相反,变成了白底黑字

野火logo

程序分析

1
2
import lcd
import time
  • import lcd :导入用于控制LCD显示屏的模块。

  • import time :导入Python的时间模块,用于实现延时功能。

1
2
3
4
5
6
7
8
lcd.init()
a=0
while a<4 :
    lcd.clear()
    lcd.rotation(a)
    lcd.draw_string(30, 30, "Embedfire", lcd.WHITE, lcd.BLACK)
    time.sleep(1)
    a=a+1
  • lcd.init() : 初始化LCD显示屏

  • a=0 : 初始化变量a,用作循环计数器。

  • while a<4 : : 开始一个循环,当a小于4时执行。

  • lcd.clear() : 清除LCD显示屏上的内容。

  • lcd.rotation(a) :设置LCD的显示方向,参数a从0到3, 0:不旋转 ,1:顺时针旋转90度 2:顺时针旋转180度 3:顺时针旋转270度

  • lcd.draw_string(30, 30, "Embedfire", lcd.WHITE, lcd.BLACK) : 在LCD上绘制字符串”Embedfire”,指定文本颜色为白色,背景颜色为黑色,坐标为(30, 30)。

  • time.sleep(1) : 让程序暂停1秒。

  • a=a+1 :增加循环计数器a的值。

1
2
3
4
lcd.clear()
lcd.rotation(0)
lcd.draw_string(140, 100, "Embedfire", lcd.WHITE, lcd.BLACK)
time.sleep(1)
  • lcd.clear() : 清除LCD显示屏上的内容。

  • lcd.rotation(0) :将LCD的显示方向恢复为默认值(0度,即正常方向)。

  • lcd.draw_string(140, 100, "Embedfire", lcd.WHITE, lcd.BLACK) : 在LCD上绘制字符串”Embedfire”,指定文本颜色为白色,背景颜色为黑色,坐标为(140, 100)。

  • time.sleep(1) : 让程序暂停1秒。

1
2
lcd.clear(lcd.WHITE)
lcd.draw_string(140, 100, "Embedfire", lcd.BLACK, lcd.WHITE)
  • lcd.WHITE : 清除LCD显示屏上的内容,并使用白色填充屏幕。

  • lcd.draw_string(140, 100, "Embedfire", lcd.BLACK, lcd.WHITE) : 在LCD上绘制字符串”Embedfire”,指定文本颜色为黑色,背景颜色为白色,坐标为(140, 100)。