Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <WiiChuck.h>
- #include "WiiChuck.h"
- #include <Wire.h>
- #include <Servo.h>
- WiiChuck chuck = WiiChuck();
- Servo mioServo;
- int led = 13;
- void setup()
- {
- Serial.begin(115200);
- chuck.begin(); //inizializza il nunchuck
- chuck.update();
- mioServo.attach(9);
- }
- void loop()
- {
- chuck.update();
- //Serial.print("Posizione su X: ");
- int x = chuck.readJoyX();
- x = x + 100;
- //Serial.println(x);
- int rotazione = map(x,3,200,0,179);
- /*Serial.print("Rotazione: ");
- Serial.println(rotazione);*/
- mioServo.write(rotazione);
- delay(15);
- //Serial.print("Z premuta: ");
- int pulsanteZ = chuck.zPressedOpt(); // 0 se spento,1 se acceso
- // Serial.println(pulsanteZ);
- int pulsanteC = chuck.cPressedOpt();// 0 se spento,1 se acceso
- //Serial.print("C premuta: ");
- // Serial.println(pulsanteC);
- if( pulsanteC == 1 && pulsanteZ == 0)
- {
- digitalWrite(led,HIGH);
- }
- else if(pulsanteZ == 1 && pulsanteC == 0)
- {
- digitalWrite(led,LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement