forked from jadonk/cloud9-examples
-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinput.js
executable file
·36 lines (30 loc) · 926 Bytes
/
input.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
#!/usr/bin/env node
////////////////////////////////////////
// input.js
// Responds to changes on P8_19 via a callback.
// Wiring: Connect P8_19 to P9_14 with a 1kOhm resistor.
// Setup:
// See:
////////////////////////////////////////
const b = require('bonescript');
const outputPin = "P9_14";
const inputPin = "P8_19";
const ledPin = "USR3";
const mydelay = 250;
var state = b.LOW;
console.log('Please connect ' + inputPin + ' to ' + outputPin +
' with a 1kOhm resistor');
b.pinMode(inputPin, b.INPUT);
b.pinMode(outputPin, b.OUTPUT);
b.pinMode(ledPin, b.OUTPUT);
b.digitalWrite(outputPin, b.LOW);
b.attachInterrupt(inputPin, setLED, b.CHANGE);
toggle();
function setLED(x) {
b.digitalWrite(ledPin, x.value);
}
function toggle() {
state = (state == b.LOW) ? b.HIGH : b.LOW;
b.digitalWrite(outputPin, state);
setTimeout(toggle, mydelay); // Waut a bit, and then toggle again
}