回転式Webカメラを500円で作る@日曜プログラミング
日曜プログラミングってことで回転式Webカメラを500円で作っちゃいます。
USB circus cannon
楽天で500円で売ってたもの。
ネジ2個と後ろのカバーを外せばガワが簡単に取れます。
あとはカメラを固定するために両面テープを貼れば完成。
USBはハブを介さずに直接PCにつなげたほうが不具合がなくていい感じ。
circus cannonを動かすプログラムはこちら
http://moeten.info/flex/20081109_circusCannon/cannon.zip
とりあえず、MS-DOSプロンプトからコマンドを入れて動けばOK
cannon.exe 0
引数リスト
0 | ↑ |
1 | → |
2 | ↓ |
3 | ← |
4 | ファイアー |
WiiリモコンをFlashで使う方法
せっかくなのでWiiリモコンで操作
こんな感じにWiiリモコンで操作することができます。回転角度やx・y座標も取得することができます。
WiiリモコンをFlashで使う方法
初期設定としてWiiリモコンをBlueTooth端末としてパソコンに認識させます。
このときWiiリモコンの電池が入っているところの赤いボタンを押して認識させます。
最後にサーバーを起動。
WiiFlashServerはこちらからダウンロード
ちなみにWiiFlashはバランスボードにも対応しているので体重を測ったりもできます(^−^)
ソースコードはこちら
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" backgroundGradientColors="[0xffffff,0xcccccc]" width="762" height="463"> <mx:Script> <![CDATA[ import org.wiiflash.events.ButtonEvent; import flash.display.*; import flash.events.Event; import flash.events.MouseEvent; import org.wiiflash.Wiimote; //-- Wimote private var wiimote: Wiimote; private var camera:Camera; private function init():void{ trace( "init" ); camera = Camera.getCamera(); camera.addEventListener(Event.ACTIVATE, onReady ); //-- Creating the Wiimote wiimote = new Wiimote(); wiimote.addEventListener( Event.CONNECT, onWiimoteReady ); wiimote.connect(); } private function onReady(e:Event):void{ trace( "onReady" ); camera.setMode( 320 , 240 ,16 ); myVideo.attachCamera( camera ); } private function onWiimoteReady(e:Event):void{ wiimote.addEventListener(ButtonEvent.UP_PRESS , onUp ); wiimote.addEventListener(ButtonEvent.RIGHT_PRESS , onRight ); wiimote.addEventListener(ButtonEvent.DOWN_PRESS , onDown ); wiimote.addEventListener(ButtonEvent.LEFT_PRESS , onLeft ); wiimote.addEventListener(ButtonEvent.A_PRESS , onFire ); this.addEventListener( Event.ENTER_FRAME, onEnterFrame ); } private function onEnterFrame( e:Event ):void{ output.text = 'a: ' + wiimote.a + '\n' + 'b: ' + wiimote.b + '\n\n' + 'up: ' + wiimote.up + '\n' + 'down: ' + wiimote.down + '\n' + 'left: ' + wiimote.left + '\n' + 'right: ' + wiimote.right + '\n\n' + 'minus: ' + wiimote.minus + '\n' + 'home: ' + wiimote.home + '\n' + 'plus: ' + wiimote.plus + '\n\n' + '1: ' + wiimote.one + '\n' + '2: ' + wiimote.two + '\n\n' + 'x: ' + wiimote.sensorX + '\n' + 'y: ' + wiimote.sensorY + '\n' + 'z: ' + wiimote.sensorZ + '\n\n' + 'pitch: ' + Math.round( wiimote.pitch * 180 / Math.PI ) + '\n' + 'roll: ' + Math.round( wiimote.roll * 180 / Math.PI ) + '\n\n' + 'nunchuk: ' + wiimote.hasNunchuk + '\n\n' + 'ir1: ' + wiimote.ir.p1 + '\n' + 'ir2: ' + wiimote.ir.p2 + '\n' + 'bottomLeftKg: ' + wiimote.balanceBoard.bottomLeftKg + '\n' + 'bottomRightKg: ' + wiimote.balanceBoard.bottomRightKg + '\n' + 'topLeftKg: ' + wiimote.balanceBoard.topLeftKg + '\n' + 'topRightKg: ' + wiimote.balanceBoard.topRightKg + '\n' + 'centerOfGravity: ' + wiimote.balanceBoard.centerOfGravity + '\n' + 'totalKg: ' + wiimote.balanceBoard.totalKg + '\n'; } private function onUp(e:Event):void{ hts.send({"command":"up"}); } private function onRight(e:Event):void{ hts.send({"command":"right"}); } private function onDown(e:Event):void{ hts.send({"command":"down"}); } private function onLeft(e:Event):void{ hts.send({"command":"left"}); } private function onFire(e:Event):void{ hts.send({"command":"fire"}); } private function onClick(str:String):void{ hts.send({"command":str}); } ]]> </mx:Script> <mx:Style> Button { paddingLeft: 6; paddingRight: 5; paddingTop: 5; paddingBottom: 5; highlightAlphas: 0.58, 0.83; fillAlphas: 0.6, 0.61, 0.6, 0.65; fillColors: #ffffff, #666666, #ffffff, #eeeeee; fontSize:16; } </mx:Style> <mx:HTTPService id="hts" url="http://localhost/others/cannon/index.php" method="GET" resultFormat="text" fault="{trace('onFault')}"/> <mx:Canvas x="10" y="10" width="344" height="436" backgroundAlpha="0.5" backgroundColor="0x666666" dropShadowColor="0x000000" dropShadowEnabled="true" cornerRadius="10" borderColor="0x000000" borderStyle="solid" borderThickness="3" > <mx:VideoDisplay id="myVideo" width="320" height="240" x="10" y="10"/> <mx:Image x="78" y="38" source="@Embed('target.png')"/> <mx:Image x="10" y="10" source="@Embed('targetCover.png')"/> <mx:Canvas x="57" y="281" width="224" height="139"> <mx:Button x="0" y="57" label="←" left="10" verticalCenter="0" click="onClick('left')"/> <mx:Button x="78" y="110" label="↓" bottom="10" horizontalCenter="0" click="onClick('down')"/> <mx:Button x="161" y="57" label="→" right="10" verticalCenter="0" click="onClick('right')"/> <mx:Button x="78" y="10" label="↑" top="10" horizontalCenter="0" click="onClick('up')"/> <mx:Button x="78" y="57" label="FIRE!" verticalCenter="0" horizontalCenter="0" click="onClick('fire')"/> </mx:Canvas> <mx:Text text="{hts.lastResult}" x="10" y="255"/> </mx:Canvas> <mx:TextArea id="output" x="362" y="10" width="309" height="436"/> </mx:Application>