-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
40 lines (39 loc) · 932 Bytes
/
main.ts
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
let granularity = [20, 100, 500]
let x = 0
let y = 0
let tx = 0
let ty = 0
function position(reading: number) {
// position, calculate the position on the display
let res = 0
let modification = 1
if (reading < 0) {
reading = Math.abs(reading)
modification = -1
}
for (let pos = 0; pos < granularity.length; pos++) {
res = 2 + (pos * modification)
if (Math.min(granularity[pos], reading) == reading) {
break
}
}
return res
}
function draw(x: number, y: number) {
// draw, draw cross pointer
basic.clearScreen()
led.plot(x, y)
led.plot(x, y - 1)
led.plot(x - 1, y)
led.plot(x, y + 1)
led.plot(x + 1, y)
}
basic.forever(function () {
x = position(input.acceleration(Dimension.X))
y = position(input.acceleration(Dimension.Y))
if (x != tx || y != ty) {
draw(x, y)
tx = x
ty = y
}
})