-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathinput.js
executable file
·36 lines (30 loc) · 869 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 P1_33 via a callback.
// Wiring: Connect P1_33to P1_36 with a 1kOhm resistor.
// Setup:
// See:
////////////////////////////////////////
var b = require('bonescript');
var outputPin = "P1_36";
var inputPin = "P1_33";
var ledPin = "USR3";
var mydelay = 100;
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);
}