Repository navigation
Expand file tree
/
Copy pathsao_touchwheel.js
More file actions
64 lines (58 loc) · 1.67 KB
/
Copy pathsao_touchwheel.js
File metadata and controls
64 lines (58 loc) · 1.67 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
// Demo a https://github.com/todbot/TouchwheelSAO
// Components are: ATtiny816
// Connect an Touchwheel SAO to the I2C bus of the Flipper Zero.
// SDA=pin 15, SCL=pin 16, VCC=pin 9, GND=pin 8, GPIO1=pin 2.
let i2c = require("i2c");
function i2c_find_first_device() {
let addr = -1;
for (let try_addr = 0; try_addr !== 0xff; try_addr++) {
if (i2c.isDeviceReady(try_addr, 5)) {
addr = try_addr;
break;
}
}
return addr;
}
function touchwheelRead(addr) {
let data_buf = i2c.writeRead(addr, [0x00], 1, 100);
if (data_buf === undefined) {
return undefined;
} else {
return Uint8Array(data_buf)[0];
}
}
function touchwheelRgb(addr, r, g, b) {
i2c.write(addr, [15, r]); delay(20);
i2c.write(addr, [16, g]); delay(20);
i2c.write(addr, [17, b]);
}
let addr = i2c_find_first_device();
if (addr === -1) {
print("I2C device not found");
print("Please connect a Touchwheel SAO to the Flipper Zero.");
print("SDA=pin 15, SCL=pin 16, VCC=pin 9, GND=pin 8.");
} else {
print("I2C device found at address: " + (addr >> 1).toString(16));
delay(1000);
touchwheelRgb(addr,0,0,0);
delay(1000);
touchwheelRgb(addr,128,128,128);
delay(2000);
touchwheelRgb(addr,128,0,0);
delay(1000);
touchwheelRgb(addr,0,128,0);
delay(1000);
touchwheelRgb(addr,0,0,128);
delay(1000);
touchwheelRgb(addr,128,128,0);
delay(1000);
touchwheelRgb(addr,128,0,128);
delay(1000);
touchwheelRgb(addr,0,128,128);
delay(1000);
for (let i=0; i<1000;i++) {
let position = touchwheelRead(addr);
print ("Position: ", position,"/255");
delay(100);
}
}