Hi guys,
was playing with servos, I used this code:
#include <Servo.h>
const int servo1 = 6; // first servo
const int servo2 = 7; // second servo
const int joyH = A0; // L/R Parallax Thumbstick
const int joyV = A1; // U/D Parallax Thumbstick
int servoVal1; // variable to read the value from the analog pin
int servoVal2;
Servo myservo1; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
void setup() {
// Servo
myservo1.attach(servo1); // attaches the servo
myservo2.attach(servo2); // attaches the servo
// Inizialize Serial
Serial.begin(9600);
}
void loop(){
// Display Joystick values using the serial monitor
outputJoystick();
// Read the horizontal joystick value (value between 0 and 1023)
servoVal1 = analogRead(joyH);
servoVal1 = map(servoVal1, 0, 1023, 90, 180); // scale it to use it with the servo (result between 0 and 180)
myservo1.write(servoVal1); // sets the servo position according to the scaled value
// Read the horizontal joystick value (value between 0 and 1023)
servoVal2 = analogRead(joyV);
servoVal2 = map(servoVal2, 0, 1023, 0, 90); // scale it to use it with the servo (result between 70 and 180)
myservo2.write(servoVal2); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
I want to get next - when I move joy to the right, 1st servo goes from 90 to 180 degrees, and when I move joy to the left, 2nd servo goes to other side, from 90 to 0 degree.
I tried to change servoval2 to read same as servoval1, and changed map for both of them, but then they move at the same time at same directions.
I would be very grateful for some help…