forked from rwaldron/johnny-five
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassic-controller.js
97 lines (75 loc) · 2.05 KB
/
classic-controller.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var five = require("../lib/johnny-five.js"),
board, nunchuk;
board = new five.Board();
// Setup for bread board
// Wire Color => Meaning => Arduino Pin Down
// Yellow => SCK => A04
// White => GND => Ground
// Red => 5v => 5v
// Green => SDA => A05
board.on("ready", function() {
// Create a new `Wii.Classic` hardware instance,
// specifically the RVL-005 device (classic controller).
var classicController = five.Wii.Classic({
freq: 100
});
// Nunchuk Event API
//
// "read" (nunchuk)
//
// Fired when the joystick detects a change in
// axis position.
//
// nunchuk.on( "read", function( err ) {
// });
// "change", "axischange" (joystick)
//
// Fired when the joystick detects a change in
// axis position.
//
nunchuk.joystick.left.on( "change", function( err, event ) {
console.log(
"Left joystick " + event.axis,
event.target[ event.axis ],
event.axis, event.direction
);
});
nunchuk.joystick.right.on( "change", function( err, event ) {
console.log(
"Right joystick " + event.axis,
event.target[ event.axis ],
event.axis, event.direction
);
});
// "down"
// aliases: "press", "tap", "impact", "hit"
//
// Fired when any nunchuk button is "down"
//
// "up"
// alias: "release"
//
// Fired when any nunchuk button is "up"
//
// "hold"
//
// Fired when any nunchuk button is in the "down" state for
// a specified amount of time. Defaults to 500ms
//
// To specify a custom hold time, use the "holdtime"
// option of the Nunchuk constructor.
//
[ "down", "up", "hold" ].forEach(function( type ) {
nunchuk.on( type, function( err, event ) {
console.log(
event.target.which + " is " + type,
{ isUp: event.target.isUp,
isDown: event.target.isDown
}
);
});
});
// Further reading
// http://media.pragprog.com/titles/msard/tinker.pdf
// http://lizarum.com/assignments/physical_computing/2008/wii_nunchuck.html
});