Results 1 to 4 of 4
  1. #1
    Wii Coder
    ChumLee's Avatar

    Badge

    Join Date
    Apr 2011
    Location
    'Murica
    Posts
    5,387
    Points
    7,610
         User Info     Contact     Gamer ID
    Join Date
    Apr 2011
    Location
    'Murica
    Posts
    5,387
    Points
    7,610
    Gamer IDs

    Gamertag: TERR0Rx9

    Contact info:

    Youtube Channel: http://www.youtube.com/user/HAXZingTERR0R

    Default Wii Nunchuk + Arduino

    This was inspired by Mr. Ownership and PvtRyan. Even though it's pretty simple, I think it's really cool. I hooked up the Wii's Nunchuk controller to my Arduino and programmed it so you can switch between lighting up different LEDs or controlling a servo motor dependent on the tilt of the controller. The LEDs are controlled by the x-axis tilt and the servo is controlled by the y-axis orientation. I think it's really neat even though it's not super practical or anything.



    To do this, I hooked up the Nunchuk's positive voltage pin to 3.3 volts and it's ground to ground of course. And with the library I'm using, I connected the clock to A5 and data to A4. Then I connected the servo to digital pin 3, and then the LEDs to digital pins 4-10.





    *Note* I know I should have connected those LEDs up to some resistors, but I really didn't feel like it. lol

    Here's the Nunchuk's library that I used: https://github.com/GabrielBianconi/ArduinoNunchuk

    And here's the code:
    Code:
    #include <Wire.h>
    #include <ArduinoNunchuk.h>
    #include <Servo.h>
    
    ArduinoNunchuk nunchuk = ArduinoNunchuk();
    Servo servo;
    int servWrite;
    int ledPin = 7;
    int calibrate = 0;
    int switchState = 0;
    
    void setup(){
      Serial.begin(19200);
      servo.attach(3);
      nunchuk.init();
      for(int i = 4; i < 11; i++){
        pinMode(i, OUTPUT); 
      }
      while(calibrate == 0){
        servo.write(90);
        digitalWrite(ledPin, HIGH);
        delay(5000); 
        calibrate = 1;
      }
    }
    
    void loop(){
      while(calibrate == 1){
        nunchuk.update();
        if(nunchuk.zButton == 1 && switchState == 0){
          switchState = 1;
        }
        else if(nunchuk.zButton == 1 && switchState == 1){
          switchState = 0;
        }
        if(switchState == 0){
          for(int i = 4; i < 11; i++){
            digitalWrite(i, LOW); 
          }
          ledPin = map(nunchuk.accelX, 300, 600, 4, 10);
          digitalWrite(ledPin, HIGH);
          Serial.print(nunchuk.accelX);
          delay(10); 
        }
        if(switchState == 1){
          servWrite = map(nunchuk.accelY, 275, 600, 0, 180);
          servo.write(servWrite);
          Serial.print(nunchuk.accelY);
          delay(10); 
        }
      }
    }
    In the code, there's a 5 second "calibration" delay in the beginning so you could adjust the servo's head to the position of half way through it's rotation if necessary. After that you would tilt the controller sideways to control the LEDs or you could switch to controlling the servo by pressing Z and moving the controller up and down.

    4 Not allowed! Not allowed!


  2. #2
    Nintendo Section Moderator PvtRyan's Avatar

    Badge

    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,586
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,586
    Gamer IDs

    PSN ID: gamer_pvtryan Steam ID: pvtryan_cl Wii Code: PvtRyan

    Contact info:

    Youtube Channel: http://www.youtube.com/xPvtRyanx

    Default Wii Nunchuk + Arduino

    good job there chum,you just inspired me to make some stuff in my shop class c: keep up the good work!

    look up fritzing. it helps make nice schematics even with Arduino.

    1 Not allowed! Not allowed!
    Last edited by PvtRyan; 03-31-2014 at 01:14 AM.


    PS4 Profile:

  3. #3
    Diehard
    1337
    Diabz's Avatar
    Join Date
    Dec 2009
    Posts
    192
    Points
    763
         User Info     Contact     Gamer ID
    Join Date
    Dec 2009
    Posts
    192
    Points
    763

    Default

    fvgvffvfv4fv4v45v5fvf5vfv5fv5fv5f22344)

    0 Not allowed! Not allowed!

  4. #4
    Frozenbit.io Vintage's Avatar
    Join Date
    Aug 2011
    Location
    Behind you
    Posts
    4,256
    Points
    6,291
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Location
    Behind you
    Posts
    4,256
    Points
    6,291

    Default

    That would be really sweet if you did that to your christmas lights on your house.

    0 Not allowed! Not allowed!

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 02:22 PM.
Powered by vBulletin®
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.