Advertisement
Guest User

Arduino Servo Nunchuck

a guest
Nov 12th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. //#include <WiiChuck.h>
  2. #include "WiiChuck.h"
  3. #include <Wire.h>
  4. #include <Servo.h>
  5.  
  6. WiiChuck chuck = WiiChuck();
  7. Servo mioServo;
  8. int led = 13;
  9.  
  10. void setup()
  11. {
  12.   Serial.begin(115200);
  13.   chuck.begin(); //inizializza il nunchuck
  14.   chuck.update();
  15.   mioServo.attach(9);
  16. }
  17.  
  18. void loop()
  19. {
  20.   chuck.update();
  21.   //Serial.print("Posizione su X: ");
  22.   int x = chuck.readJoyX();
  23.   x = x + 100;
  24.   //Serial.println(x);
  25.   int rotazione = map(x,3,200,0,179);
  26.   /*Serial.print("Rotazione: ");
  27.   Serial.println(rotazione);*/
  28.   mioServo.write(rotazione);
  29.   delay(15);
  30.  
  31.   //Serial.print("Z premuta: ");
  32.   int pulsanteZ = chuck.zPressedOpt(); // 0 se spento,1 se acceso
  33.  
  34.  // Serial.println(pulsanteZ);
  35.   int pulsanteC = chuck.cPressedOpt();// 0 se spento,1 se acceso
  36.   //Serial.print("C premuta: ");
  37. //  Serial.println(pulsanteC);
  38.   if( pulsanteC == 1 && pulsanteZ == 0)
  39.   {
  40.     digitalWrite(led,HIGH);
  41.   }
  42.   else if(pulsanteZ == 1 && pulsanteC == 0)
  43.   {
  44.     digitalWrite(led,LOW);
  45.   }  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement