2016年4月29日金曜日

Johnny-Fiveでマイコン制御3 - Wiiヌンチャク

  




○使用部品
Wiiヌンチャク

○Wiiヌンチャク制御用端子
Arduino A2、A3、A4、A5
Raspberry Pi 3、4(または2)、5、6

○基本回路/プログラム
◇Arduino
・配線
アダプタ
Arduino
-
A2
+
A3
d
A4
c
A5

◇Raspberry Pi
・配線
アダプタ
Raspberry Pi()
-
6
+
4
d
3
c
5
※物理的なピン番号で表記しています。
 
・プログラム
var raspi = require('raspi-io');
var five = require("johnny-five"),
board, nunchuk;
board = new five.Board({
io: new raspi()
});
board.on("ready", function() {
// Create a new `nunchuk` hardware instance.
nunchuk = new five.Wii.Nunchuk({
freq: 50
});
nunchuk.joystick.on("change", function(event) {
console.log(
"joystick " + event.axis,
event.target[event.axis],
event.axis, event.direction
);
});
nunchuk.accelerometer.on("change", function(event) {
console.log(
"accelerometer " + event.axis,
event.target[event.axis],
event.axis, event.direction
);
});
["down", "up", "hold"].forEach(function(type) {
nunchuk.on(type, function(event) {
console.log(
event.target.which + " is " + type,
{
isUp: event.target.isUp,
isDown: event.target.isDown
}
);
});
});
});
view raw nunchuk_pi.js hosted with ❤ by GitHub


APIの詳細は、Arduinoのプログラムを参照してください。

0 件のコメント:

コメントを投稿