forked from jadonk/cloud9-examples
-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinput2.js
executable file
·60 lines (52 loc) · 1.6 KB
/
input2.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
60
#!/usr/bin/env node
////////////////////////////////////////
// input2.js
// Responds to changes on P8_19 and P9_16 via callbacks.
// Wiring: Connect P8_19 to P9_14 with a 1kOhm resistor
// Connect P9_15 to P9_16 with a 1kOhm resistor
// Setup:
// See:
////////////////////////////////////////
const b = require('bonescript');
const outputPin = "P9_14";
const inputPin = "P8_19";
const outputPin2 = "P9_16";
const inputPin2 = "P9_15";
const ledPin = "USR3";
const ledPin2 = "USR2";
const mydelay = 100;
const mydelay2 = 33;
var toggleState = b.LOW;
var toggleState2 = b.LOW;
console.log('Please connect ' + inputPin + ' to ' + outputPin +
' with a 1kOhm resistor');
console.log('Please connect ' + inputPin2 + ' to ' + outputPin2 +
' with a 1kOhm resistor');
b.pinMode(inputPin, b.INPUT);
b.pinMode(outputPin, b.OUTPUT);
b.pinMode(ledPin, b.OUTPUT);
b.pinMode(inputPin2, b.INPUT);
b.pinMode(outputPin2, b.OUTPUT);
b.pinMode(ledPin2, b.OUTPUT);
b.digitalWrite(outputPin, b.LOW);
b.digitalWrite(outputPin2, b.LOW);
b.attachInterrupt(inputPin, inputHandler, b.CHANGE);
b.attachInterrupt(inputPin2, inputHandler2, b.CHANGE);
toggle();
toggle2();
function inputHandler(x) {
b.digitalWrite(ledPin, x.value);
}
function inputHandler2(x) {
b.digitalWrite(ledPin2, x.value);
}
function toggle() {
toggleState = (toggleState == b.LOW) ? b.HIGH : b.LOW;
b.digitalWrite(outputPin, toggleState);
setTimeout(toggle, mydelay);
}
function toggle2() {
toggleState2 = (toggleState2 == b.LOW) ? b.HIGH : b.LOW;
b.digitalWrite(outputPin2, toggleState2);
setTimeout(toggle2, mydelay2);
}