Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define pitchPin 9 //Pin for pitch servo/stepper (up/down)
- #define yawPin 10 //Pin for yaw servo/stepper
- #define rotateDelay 10 //milliseconds per degree
- #include <Servo.h>
- Servo pitchServo;
- Servo yawServo;
- int pitch = 0;
- int yaw = 0;
- void setup() {
- Serial.begin(9600); //Comment
- pitchServo.attach(pitchPin); //Set up servos
- yawServo.attach(yawPin);
- pitchServo.write(0); //Set up servo positions
- yawServo.write(0);
- Serial.println(F("Initialized, starting program. \n Please use degrees, \n from 0 to 360 for yaw and from 0 to 180 for pitch.")); //F() stores the string in flash memory, to save RAM
- }
- void loop() {
- Serial.println("Enter Pitch: ");
- while (!Serial.available()) {} //Wait until pitch is recieved
- pitch = Serial.parseInt();
- pitch = constrain(pitch, 0, 180);
- Serial.print("Pitch: ");
- Serial.println(pitch);
- Serial.println("Enter Yaw: ");
- while (!Serial.available()) {} //Wait until yaw is recieved
- yaw = Serial.parseInt();
- yaw = constrain(yaw, 0, 360);
- Serial.print("Yaw: ");
- Serial.println(yaw);
- //Rotate the servos
- rotate(pitch, yaw);
- Serial.println(F("Rotation Successful"));
- }
- void rotate(int pitch, int yaw) { //This is a function so switching to stepper motors is easier lol
- Serial.println(F("Rotating pitch..."));
- pitchServo.write(pitch);
- delay(pitch * rotateDelay + 100); //Let servo rotate
- Serial.println(F("Rotating yaw..."));
- yawServo.write(yaw);
- delay(yaw * rotateDelay + 100);
- }
Advertisement
Add Comment
Please, Sign In to add comment