-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbit-lcd1602.ts
More file actions
113 lines (109 loc) · 4.07 KB
/
Copy pathbit-lcd1602.ts
File metadata and controls
113 lines (109 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* IKBIT PACKAGES
*/
//% weight=1000 color=#436EEE icon="\uf1cb" block="Ckmaker-BIT"
namespace ikbit {
const BIT_LCD1602_ADD = 0X02;
const REG_1602_CLEAR_SCREEN = 0X30;
const REG_1602_LINE1_NORMAL = 0X31;
const REG_1602_LINE2_NORMAL = 0X32;
const REG_1602_LINE1_SCROLL = 0X33;
const REG_1602_LINE2_SCROLL = 0X34;
const REG_1602_BACK_LIGHT = 0X35;
/**
* clear BIT-LCD1602 screen display
*/
//% blockId=lcd1602ClearScreen block="BIT-LCD1602 ClearScreen"
//% weight=190 blockGap=3 color=#2E8B57
export function lcd1602ClearScreen(): void {
writeReg(BIT_LCD1602_ADD,REG_1602_CLEAR_SCREEN);
}
/**
* Set BIT-LCD1602 backlight
* @param value set Backlight level[0-5] , eg: "3"
*/
//% blockId=lcd1602SetBackLight block="BIT-LCD1602 SetBackLight|%value "
//% value.min=0 value.max=5
//% weight=189 blockGap=3 color=#2E8B57
export function lcd1602SetBackLight(value: number): void {
if (value < 0 || value > 5) { return; }
let buf = pins.createBuffer(1);
buf[0] = value;
ikbit.writeRegBufNoLength(BIT_LCD1602_ADD,REG_1602_BACK_LIGHT,buf);
}
/**
* Display a string at a specified location in BIT-LCD1602
* @param x The location in a line begins to display , eg: "1"
* @param y The location in a row begins to display , eg: "1"
*/
//% blockId=lcd1602DisString block="BIT-LCD1602 DisString|X %x |y %y |%str"
//% x.min=1 x.max=2
//% y.min=1 y.max=16
//% weight=188 blockGap=3 color=#2E8B57
export function lcd1602DisString(x: number, y: number, str: string): void {
if (y > 16) return;
let size = str.length;
if (size > 16) size = 16;
let tline: number;
let tbuf = pins.createBuffer(size +1);
if (x == 1) {
tline = REG_1602_LINE1_NORMAL;
}
else if (x == 2) {
tline = REG_1602_LINE2_NORMAL;
}
tbuf[0] = y;
copyStrToBuf(str, tbuf, 1, size);
writeRegBufNoLength(BIT_LCD1602_ADD,tline,tbuf);
}
/**
* Display a number at a specified location in BIT-LCD1602
* @param x The location in a line begins to display , eg: "1"
* @param y The location in a row begins to display , eg: "1"
*/
//% blockId=ikbit_lcd1602DisNumber block="BIT-LCD1602 display number|X|%x |y|%y |value|%num"
//% x.min=1 x.max=2
//% y.min=1 y.max=16
//% weight=187 blockGap=3 color=#2E8B57
export function lcd1602DisNumber(x: number, y: number, n: number): void {
let str=n.toString();
lcd1602DisString(x,y,str);
}
/**
* Scroll display a string at a specified location in BIT-LCD1602
* @param x The location in a line begins to display , eg: "1"
* @param y The location in a row begins to display , eg: "1"
*/
//% blockId=ikbit_lcd1602ScrollDisString block="BIT-LCD1602 scroll display string|X|%x |y|%y |%str"
//% x.min=1 x.max=2
//% y.min=1 y.max=16
//% weight=186 blockGap=3 color=#2E8B57
export function lcd1602ScrollDisString(x: number, y: number, str: string): void {
let size=str.length;
if (size > 16) size = 16;
let tline: number;
let tbuf = pins.createBuffer(size +1);
if (x == 1) {
tline = REG_1602_LINE1_SCROLL;
}
else if (x == 2) {
tline = REG_1602_LINE2_SCROLL;
}
tbuf[0] = y;
copyStrToBuf(str, tbuf, 1, size);
writeRegBufNoLength(BIT_LCD1602_ADD,tline,tbuf);
}
/**
* Scroll display a number at a specified location in BIT-LCD1602
* @param x The location in a line begins to display , eg: "1"
* @param y The location in a row begins to display , eg: "1"
*/
//% blockId=ikbit_lcd1602ScrollDisNumber block="BIT-LCD1602 scroll display number|X|%x |y|%y |value|%num"
//% x.min=1 x.max=2
//% y.min=1 y.max=16
//% weight=185 blockGap=30 color=#2E8B57
export function lcd1602ScrollDisNumber(x: number, y: number, n: number): void {
let str=n.toString();
lcd1602ScrollDisString(x,y,str);
}
}