I'm trying to make a robot to get information wireless from a wii nunchuck. I have wrote a code for the robot when the information travels to the arduino thru a cable. Here is the code for a wii nunchuck controlled robot were you need a wire:
#include <Wiichuck.h>
#include <Wire.h>
#include <Servo.h>
#include <AFMotor.h>
Wiichuck wii;
Servo vertServo;
const int vertServoPin = 1;
AF_DCMotor motor1(1, MOTOR12_64KHZ); //motor1 is connected to M1 port
AF_DCMotor motor2(2, MOTOR12_64KHZ); //motor2 is connected to M2 port
AF_DCMotor motor3(3, MOTOR34_64KHZ); //motor3 is connected to M3 port
void setup() {
Serial.begin(9600);
vertServo.attach(vertServoPin);
wii.init();
wii.calibrate(); // calibration
}
void loop() {
if (wii.poll()) {
int joyX = wii.joyX();
int joyY = wii.joyY();
if (joyX == 127.5 && joyY == 127.5) {
// turn servo right
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
}
if (joyY > 127.5 && joyX < 191.5) {
// turn servo up
motor1.setSpeed(192);
motor2.setSpeed(192);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(RELEASE);
}
if (joyX >= 191.5 && joyX <= 255) {
motor1.setSpeed(255);
motor2.setSpeed(255);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(RELEASE);
}
if (joyX < 127.5 && joyX > 64) {
motor1.setSpeed(255);
motor3.setSpeed(255);
motor1.run(FORWARD);
motor2.run(RELEASE);
motor3.run(FORWARD);
}
if (joyX <=0 && joyX <=64) {
if (joyX > 191.5 && joyX <= 255)
motor1.setSpeed(255);
motor3.setSpeed(255);
motor1.run(FORWARD);
motor2.run(RELEASE);
motor3.run(FORWARD);
}
if (joyY > 127.5 && joyY < 191.5) {
motor1.setSpeed(192);
motor2.setSpeed(192);
motor3.setSpeed(192);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
}
if (joyY > 191.5 && joyY <= 255){
motor1.setSpeed(255);
motor2.setSpeed(255);
motor3.setSpeed(255);
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
//add backwards
}
}
}
How can I make this wireless? I can maybe have a wireless wii nunchuck and connect the adapter to the arduino board. Then I don't need to change something in the code. I just need to power the adapter and connect the data outputs on the adapter to the analog pins that are alredy set to take data. Would this work?