#include <Servo.h>
const int servo1 = 3; // first servo
const int servo2 = 10; // second servo
const int joyH = 3; // L/R Parallax Thumbstick
const int joyV = 4; // U/D Parallax Thumbstick
int servoVal1; // variable to read the value from the analog pin
int servoVal2;
int servoVal3; // variable to read the value from the analog pin
int servoVal4;
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();
servoVal3 = analogRead(joyV);
servoVal4 = analogRead(joyV);
servoVal3 = map(servoVal3, 0, 1023,1000, 1750); // scale it to use it with the servo (result between 0 and 180)
servoVal4 = map(servoVal4, 0, 1023, 1250, 1750); // scale it to use it with the servo (result between 70 and 180)
// Read the horizontal joystick value (value between 0 and 1023)
servoVal1 = analogRead(joyH);
servoVal2 = analogRead(joyH);
servoVal1 = map(servoVal1, 0, 1023,1000, 1750); // scale it to use it with the servo (result between 0 and 180)
servoVal2 = map(servoVal2, 0, 1023, 1250, 1750); // scale it to use it with the servo (result between 70 and 180)
myservo2.write(servoVal1); // sets the servo position according to the scaled value
myservo1.write(servoVal2);
delay(15); // waits for the servo to get there
}
/**
* Display joystick values
*/
void outputJoystick(){
Serial.print(analogRead(joyH));
Serial.print ("---");
Serial.print(analogRead(joyV));
Serial.println ("----------------");
}
this is the new code i came up with to run the robot to make zero point turns, the issue is now that i cant figure out how to make the bot run in parallel when moving forwards and backwards, any ideas?