-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (55 loc) · 1.46 KB
/
index.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
61
62
63
64
var five = require("johnny-five"),
board, button;
board = new five.Board();
board.on("ready", function() {
// Create a new `button` hardware instance.
// This example allows the button module to
// create a completely default instance
button1 = new five.Button({
board: board,
pin: 2,
holdtime: 500,
invert: false // Default: "false". Set to "true" if button is Active-Low
});
button2 = new five.Button({
board: board,
pin: 3,
holdtime: 500,
invert: false // Default: "false". Set to "true" if button is Active-Low
});
var led = new five.Led(11);
var brightness = 0; //start brightness
// Inject the `button` hardware into
// the Repl instance's context;
// allows direct command line access
board.repl.inject({
button1: button1,
button2: button2,
});
// Button Event API
// "hold" the button is pressed for specified time.
// defaults to 500ms (1/2 second)
// set
button1.on("hold", function() {
brightness = brightness+10
if (brightness>255) brightness = 255;
led.brightness(brightness);
console.log(brightness);
});
button2.on("hold", function() {
brightness = brightness-10
if (brightness<0) brightness = 0;
led.brightness(brightness);
console.log(brightness);
});
/*
// "down" the button is pressed
button1.on("down", function() {
console.log("down");
});
// "up" the button is released
button1.on("up", function() {
console.log("up");
});
*/
});