Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pico-micropython-grove
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Embeded
pico-micropython-grove
Commits
5e85a0e8
提交
5e85a0e8
authored
2月 26, 2021
作者:
唐睿骞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化LCD1602库
上级
69436a06
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
26 行删除
+31
-26
lcd1602.py
I2C/lcd1602.py
+31
-26
没有找到文件。
I2C/lcd1602.py
浏览文件 @
5e85a0e8
from
machine
import
I2C
,
Pin
import
time
class
Display
(
object
):
# color define
WHITE
=
0
RED
=
1
GREEN
=
2
BLUE
=
3
REG_RED
=
0x04
# pwm2
REG_GREEN
=
0x03
# pwm1
REG_BLUE
=
0x02
# pwm0
REG_MODE1
=
0x00
REG_MODE2
=
0x01
REG_OUTPUT
=
0x08
class
LCD1602
(
object
):
#commands
LCD_CLEARDISPLAY
=
0x01
LCD_RETURNHOME
=
0x02
...
...
@@ -53,10 +39,9 @@ class Display(object):
LCD_5x10DOTS
=
0x04
LCD_5x8DOTS
=
0x00
def
__init__
(
self
,
i2c
,
lines
,
dotsize
,
lcd_addr
=
0x3E
,
rgb_addr
=
0x62
):
def
__init__
(
self
,
i2c
,
lines
,
dotsize
,
lcd_addr
=
0x3E
):
self
.
i2c
=
i2c
self
.
lcd_address
=
lcd_addr
self
.
rgb_address
=
rgb_addr
self
.
line
=
lines
self
.
currline
=
0
;
self
.
display_control
=
self
.
LCD_DISPLAYON
...
...
@@ -99,13 +84,7 @@ class Display(object):
#Initialize to default text direction (for romance languages)
self
.
display_mode
=
self
.
LCD_ENTRYLEFT
|
self
.
LCD_ENTRYSHIFTDECREMENT
#set the entry mode
self
.
command
(
self
.
LCD_ENTRYMODESET
|
self
.
display_mode
)
#backlight init
self
.
set_reg
(
0
,
0
)
self
.
set_reg
(
1
,
0
)
self
.
set_reg
(
0x08
,
0xAA
)
#all led control by pwm
self
.
set_rgb
(
255
,
255
,
255
)
self
.
command
(
self
.
LCD_ENTRYMODESET
|
self
.
display_mode
)
def
clear
(
self
):
self
.
command
(
self
.
LCD_CLEARDISPLAY
)
#clear display, set cursor position to zero
...
...
@@ -170,6 +149,32 @@ class Display(object):
for
char
in
text
:
self
.
write
(
ord
(
char
))
class
LCD1602_RGB
(
LCD1602
):
# color define
WHITE
=
0
RED
=
1
GREEN
=
2
BLUE
=
3
REG_RED
=
0x04
# pwm2
REG_GREEN
=
0x03
# pwm1
REG_BLUE
=
0x02
# pwm0
REG_MODE1
=
0x00
REG_MODE2
=
0x01
REG_OUTPUT
=
0x08
def
__init__
(
self
,
i2c
,
lines
,
dotsize
,
lcd_addr
=
0x3E
,
rgb_addr
=
0x62
):
self
.
rgb_address
=
rgb_addr
LCD1602
.
__init__
(
self
,
i2c
,
lines
,
dotsize
,
lcd_addr
)
#backlight init
self
.
set_reg
(
0
,
0
)
self
.
set_reg
(
1
,
0
)
self
.
set_reg
(
0x08
,
0xAA
)
#all led control by pwm
self
.
set_rgb
(
255
,
255
,
255
)
def
set_reg
(
self
,
addr
,
value
):
value
=
bytearray
([
value
])
self
.
i2c
.
writeto_mem
(
self
.
rgb_address
,
addr
,
bytearray
([]))
...
...
@@ -195,4 +200,5 @@ class Display(object):
else
:
return
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论