Go Down

Topic: Making a joystick control for two servos to hold position (Read 3566 times) previous topic - next topic

Robin2

That shouldn't make any difference.

What pin is the Joystick wiper connected to - indeed what pins are all the joystick connection on?

I just tested my code. It works fine. When the pot is in the centre nothing happens - turn it one way and the servo starts moving. Turn it back to centre and the servo stays at its last position. Turn it the other way and the servo reverses.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

msdhillon

I have x axis of axis connected to A0, y axis of joystick connected to A1, servo 1 connected to pin 7, servo 2 connected to pin 6.

I will try it again.

msdhillon

It Works !!!
It Works!!!

I just changed the dead zone values from 200 to 550. Now it works.

Apparently the middle value of the joystick on the x axis is around 214 while on the y axis is around 515 which is wierd. It should both be around 515. So when I changed the lower limit to 200 and upper limit to 550 it started working.

Thanks very much. Now I will try to understand what is happening in the code and learn something from it. :)

Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

raschemmel

Would you mind posting the revised code for others to benefit from ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

msdhillon

Sure I would love to.
It is not my code. Kudos to Robin2 fro providing me the code.

Code: [Select]
#include <Servo.h>

#define mainArm 0
#define jib 1
#define bucket 2
#define slew 3

Servo servo[4];      //code used for attaching upto 4 servos

byte angle[4] = {90, 90, 90, 90};       // middle point for servo angle

byte potPin[4] = {A0, A1, A2, A3};  // input pins to attach your potentiometers
byte servoPin[4] = {7, 6, 10, 9};    // input pins to attach servos

void setup() {

  Serial.begin(9600);
  Serial.println("Starting DiggerCode.ino");


  for (byte n = 0; n < 4; n++) {
    servo[n].attach(servoPin[n]);
  }
}

void loop() {
  readPotentiometers();
  moveServos();
  delay(10);
}

void readPotentiometers() {
  int potVal;
  for (byte n = 0; n < 4; n++) {
    potVal = analogRead(potPin[n]);
   
    if (potVal < 200) {         // dead zone for the joystick I used is 200 to 550.
      angle[n] += 1;
      if (angle[n] > 170) {
        angle[n] = 170;
      }
    }
   
    if (potVal > 550) {         // deadzone upper value
      angle[n] -= 1;
      if (angle[n] < 10) {
        angle[n] = 10;
      }
    }

  }
}

void moveServos() {
  for (byte n = 0; n < 4; n++) {
    servo[n].write(angle[n]);
  }
}


Courtesy: Robin2

zoomkat

The old discussion.

http://forum.arduino.cc/index.php/topic,157967.0.html
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Robin2

@Zoomkat's link is not  the one I contributed to.

I have now found it (courtesy of Google) Excavator control project

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

adam_lumpkins

It worked fine for me I just used A2,A3 pins and ~10,~9  "i left the code as is" works Fine on UNO

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy