极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4147|回复: 0

USBHOST WII雞腿的搖桿

[复制链接]
发表于 2012-12-27 08:43:08 | 显示全部楼层 |阅读模式
請問!
       關於USB HOST 怎麼去抓到雞腿的上下左右?

  1. #include <Wii.h>
  2. USB Usb;
  3. BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
  4. /* You can create the instance of the class in two ways */
  5. WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
  6. //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote

  7. bool printAngle;

  8. void setup() {
  9.   Serial.begin(115200);
  10.   if (Usb.Init() == -1) {
  11.     Serial.print(F("\r\nOSC did not start"));
  12.     while(1); //halt
  13.   }
  14.   Serial.print(F("\r\nWiimote Bluetooth Library Started"));
  15. }
  16. void loop() {
  17.   Usb.Task();
  18.   if(Wii.wiimoteConnected) {
  19.     if(Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
  20.       Serial.print(F("\r\nHOME"));  
  21.       Wii.disconnect(); // Disconnect the Wiimote - it will establish the connection again since the Wiimote automatically reconnects
  22.     }
  23.     else {
  24.       if(Wii.getButtonClick(LEFT)) { // 左
  25.         Wii.setAllOff();
  26.         Wii.setLedOn(LED1);
  27.         Serial.print(F("\r\nLeft"));
  28.       }
  29.       if(Wii.getButtonClick(RIGHT)) {// 又
  30.         Wii.setAllOff();
  31.         Wii.setLedOn(LED3);
  32.         Serial.print(F("\r\nRight"));
  33.       }
  34.       if(Wii.getButtonClick(DOWN)) {  // 下
  35.       
  36.         Wii.setAllOff();
  37.         Wii.setLedOn(LED4);
  38.         Serial.print(F("\r\nDown"));
  39.       }      
  40.       if(Wii.getButtonClick(UP)) {  // 上
  41.         Wii.setAllOff();
  42.         Wii.setLedOn(LED2);         
  43.         Serial.print(F("\r\nUp"));
  44.       }

  45.       if(Wii.getButtonClick(PLUS))
  46.         Serial.print(F("\r\nPlus"));
  47.       if(Wii.getButtonClick(MINUS))   // -
  48.         Serial.print(F("\r\nMinus"));

  49.       if(Wii.getButtonClick(ONE))
  50.         Serial.print(F("\r\nOne"));
  51.       if(Wii.getButtonClick(TWO))
  52.         Serial.print(F("\r\nTwo"));

  53.       if(Wii.getButtonClick(A)) {
  54.         printAngle = !printAngle;
  55.         Serial.print(F("\r\nA"));
  56.       }      
  57.       if(Wii.getButtonClick(B)) {
  58.         Wii.setRumbleToggle();
  59.         Serial.print(F("\r\nB"));
  60.       }
  61.     }
  62.     if(printAngle) {
  63.       Serial.print(F("\r\nPitch: "));
  64.       Serial.print(Wii.getPitch());
  65.       Serial.print(F("\tRoll: "));
  66.       Serial.print(Wii.getRoll());
  67.       if(Wii.motionPlusConnected) {
  68.         Serial.print(F("\tYaw: "));
  69.         Serial.print(Wii.getYaw());
  70.       }      
  71.       if(Wii.nunchuckConnected) {
  72.         Serial.print(F("\tNunchuck Pitch: "));
  73.         Serial.print(Wii.nunchuckPitch);
  74.         Serial.print(F("\tNunchuck Roll: "));
  75.         Serial.print(Wii.nunchuckRoll);
  76.       }
  77.     }
  78.   }
  79.   if(Wii.nunchuckConnected) {
  80.     if(Wii.getButtonClick(Z))
  81.       Serial.print(F("\r\nZ"));
  82.     if(Wii.getButtonClick(C))
  83.       Serial.print(F("\r\nC"));
  84.     if(Wii.getAnalogHat(HatX) > 137 ||  Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) {
  85.       Serial.print(F("\r\nHatX: "));
  86.       Serial.print(Wii.getAnalogHat(HatX));
  87.       Serial.print(F("\tHatY: "));
  88.       Serial.print(Wii.getAnalogHat(HatY));
  89.     }
  90.   }
  91. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-20 01:19 , Processed in 0.038732 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表