Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by BAM ( 8 years ago )
#include <Wire>
#include "Nunchuk.h"
#include <Servo>

Servo myservo1;  // create servo object to control a servo

int pos1 = 0;

void setup() {
    myservo1.attach(9);  // attaches the servo on pin 9 to the servo object
    Serial.begin(9600);
    Wire.begin();
    nunchuk_init_power(); // A1 and A2 is power supply
    nunchuk_init();
 Serial.println("Starting");
}

void loop() {

    if (nunchuk_read()) {
        Serial.print("joyX: ");
        Serial.print(nunchuk_joystickX());
        Serial.print(", joyY: ");
        Serial.print(nunchuk_joystickY());
        Serial.print(", accX: ");
        Serial.print(nunchuk_accelX());
        Serial.print(", accY: ");
        Serial.print(nunchuk_accelY());
        Serial.print(", buttonZ: ");
        Serial.print(nunchuk_buttonZ());
        Serial.print(", buttonC: ");
        Serial.println(nunchuk_buttonC());
        // magic goes here
        pos1 = map(nunchuk_joystickX(),-128,128,0,180);
        myservo1.write(pos1); 
    } else {
  Serial.println("_");
 }
    delay(10);
}

 

Revise this Paste

Your Name: Code Language: