-
Notifications
You must be signed in to change notification settings - Fork 0
/
displaynumber.js
59 lines (50 loc) · 1.08 KB
/
displaynumber.js
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
let item = 0
input.onButtonPressed(Button.A, () => {
item += 1
shortDisplayNumber(item)
})
input.onButtonPressed(Button.B, () => {
item += -1
shortDisplayNumber(item)
})
input.onButtonPressed(Button.AB, () => {
basic.showNumber(item)
shortDisplayNumber(item)
})
item = 0
function plotVLine(x: number, y: number) {
for (let i = 0; i <= 4; i++) {
if (i >= y) {
led.unplot(x, 4 - i);
}
else {
led.plot(x, 4 - i);
}
}
}
function shortDisplayNumber(n: number) {
if (n >= 0 && n <= 599) {
let n2 = n / 100
let n1 = (n - n2 * 100) / 10;
let n0 = (n - n2 * 100 - n1 * 10);
if (n0 > 5) {
plotVLine(4, 5);
plotVLine(3, n0 - 5);
}
else {
plotVLine(4, n0);
plotVLine(3, 0);
}
if (n1 > 5) {
plotVLine(2, 5);
plotVLine(1, n1 - 5);
}
else {
plotVLine(2, n1);
plotVLine(1, 0);
}
plotVLine(0, n2);
}
}
basic.forever(() => {
})