Repository navigation
Expand file tree
/
Copy pathinput2.js
More file actions
58 lines (55 loc) · 1.57 KB
/
Copy pathinput2.js
File metadata and controls
58 lines (55 loc) · 1.57 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
require('bonescript');
outputPin = bone.P8_3;
inputPin = bone.P8_5;
outputPin2 = bone.P8_7;
inputPin2 = bone.P8_9;
ledPin = bone.USR3;
ledPin2 = bone.USR2;
mydelay = 100;
mydelay2 = 33;
blink2Loop = 0;
setup = function() {
console.log('Please connect ' + inputPin.key + ' to ' + outputPin.key +
' with a 1kohm resistor');
console.log('Please connect ' + inputPin2.key + ' to ' + outputPin2.key +
' with a 1kohm resistor');
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
digitalWrite(outputPin, LOW);
pinMode(ledPin, OUTPUT);
pinMode(inputPin2, INPUT);
pinMode(outputPin2, OUTPUT);
digitalWrite(outputPin2, LOW);
pinMode(ledPin2, OUTPUT);
attachInterrupt(inputPin, function(x) {
digitalWrite(ledPin, x.value);
}, CHANGE);
attachInterrupt(inputPin2, function(x) {
digitalWrite(ledPin2, x.value);
}, CHANGE);
var blink2 = function() {
digitalWrite(outputPin2, HIGH);
delay(mydelay2);
digitalWrite(outputPin2, LOW);
delay(mydelay2);
};
function toggleBlink2() {
if(blink2Loop) {
console.log('Disabling toggle2');
removeLoop(blink2Loop);
blink2Loop = 0;
} else {
console.log('Enabling toggle2');
blink2Loop = addLoop(blink2);
}
setTimeout(toggleBlink2, 10000);
};
setTimeout(toggleBlink2, 10000);
blink2Loop = addLoop(blink2);
};
loop = function() {
digitalWrite(outputPin, HIGH);
delay(mydelay);
digitalWrite(outputPin, LOW);
delay(mydelay);
};