-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.js
More file actions
40 lines (34 loc) · 837 Bytes
/
Copy pathbutton.js
File metadata and controls
40 lines (34 loc) · 837 Bytes
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
var five = require('johnny-five');
var board = new five.Board();
var button;
var led;
board.on('ready', function() {
led = new five.Led(11);
// Create a new `button` hardware instance.
// This example allows the button module to
// create a completely default instance
button = new five.Button(2);
// Inject the `button` hardware into
// the Repl instance's context;
// allows direct command line access
board.repl.inject({
button: button,
led: led
});
// Button Event API
// "down" the button is pressed
button.on('down', function() {
console.log('down');
led.brightness(255);
});
button.on('hold', function() {
console.log('hold');
led.blink(500);
});
// "up" the button is released
button.on('up', function() {
console.log('up');
led.stop(); // Stops the blinking
led.brightness(0);
});
});