-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino.js
55 lines (46 loc) · 1.31 KB
/
arduino.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
function printList(portList) {
// portList is an array of serial port names
for (var i = 0; i < portList.length; i++) {
// Display the list the console:
console.log(i + " " + portList[i]);
}
}
function serverConnected() {
console.log('connected to server.');
}
function portOpen() {
console.log('the serial port opened.')
}
function serialEvent() {
var data = serial.readLine();
if (data.length > 0) {
// console.log(data);
var sensors = split(data, ",");
// console.log(sensors);
P1 = int(sensors[0]);
P2 = int(sensors[1]);
P3 = int(sensors[2]);
P4 = int(sensors[3]);
}
}
function serialError(err) {
console.log('Something went wrong with the serial port. ' + err);
}
function portClose() {
console.log('The serial port closed.');
}
// create some HTML elements in the sketch:
function createHTML() {
serialDiv = createElement('p', 'incoming data goes here');
serialDiv.attribute('aria-label', 'incoming data');
serialDiv.attribute('aria-role', 'alert');
serialDiv.attribute('aria-live', 'polite');
serialDiv.style('color', 'white');
serialDiv.position(10, 40);
}
function printData(inString) {
// put the input in the serialDiv div:
serialDiv.html('log: ' + inString);
// print it to the console as well
// console.log(inString);
}