Hi folks! I just got my robot arm project to use a wii nunchuk for control! All was going well until I nicked my kitchen table. That's when I decided I needed slower/smoother servo movements. Excuse me for being a n00b though, I have a hard time with this programming stuff :S. I have an issue with compiling the program. I think the problem lies in the new library I installed. I replaced the servo library with the VarSpeedServo library for smoother movements. I haven't put in any of the new code yet. If someone could lend me a hand that would be spectacular! Thank you so much folks!
#include <VarSpeedServo.h>
#include <Wire.h>
#include "nunchuck_funcs.h"
#define ROTATION_SERVO 3
#define VERTICAL_SERVO1 9
#define VERTICAL_SERVO2 5
#define ROTATION_PINCE 6
#define POWER_PINCE 10
#define VITESSE 2
byte accx,accy,joyy,joyx,cbut,zbut;
VarSpeedServo servo_1, servo_2, servo_3, servo_4, servo_5;
void setup()
{
Serial.begin(19200);
nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake
Serial.print("WiiChuckDemo ready\n");
servo_1.attach(ROTATION_SERVO);
servo_2.attach(VERTICAL_SERVO1);
servo_3.attach(VERTICAL_SERVO2);
servo_4.attach(ROTATION_PINCE);
servo_5.attach(POWER_PINCE);
servo_1.write(90);
servo_2.write(60);
servo_3.write(90);
servo_4.write(170);
servo_5.write(180);
}
void loop()
{
nunchuck_get_data();
accx = nunchuck_accelx(); // ranges from approx 70 - 182
accy = nunchuck_accely(); // ranges from approx 65 - 173
joyy = nunchuck_joyy();
joyx = nunchuck_joyx();
cbut = nunchuck_cbutton();
zbut = nunchuck_zbutton();
if(joyx > 200) servo_1.write(constrain(servo_1.read()-VITESSE,0,180));
if(joyx < 50) servo_1.write(constrain(servo_1.read()+VITESSE,0,180));
if(joyy < 200) servo_2.write(constrain(servo_2.read()+VITESSE,60,180)); //swap
if(joyy > 50) servo_2.write(constrain(servo_2.read()-VITESSE,60,180)); //swap
if(accy < 170) servo_3.write(constrain(servo_3.read()-VITESSE,100,180)); //Changed here from > to <
if(accy > 110) servo_3.write(constrain(servo_3.read()+VITESSE,100,180)); //Changed here from < to >
if(accx > 150) servo_4.write(constrain(servo_4.read()+VITESSE,0,180)); //not used
if(accx < 80) servo_4.write(constrain(servo_4.read()-VITESSE,0,180)); //not used
if(cbut == 1) servo_5.write(constrain(servo_5.read()+VITESSE, 50, 180)); //CHANGED
if(zbut == 1) servo_5.write(constrain(servo_5.read()-VITESSE, 50, 180)); //CHANGED
//nunchuck_print_data();
Serial.print("Servo : ");
Serial.println(servo_5.read());
delay(10);
}