Advertisement
AndyGrawell

CameraMount2 - working

Jun 28th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. uint8_t X_potPin = A0;
  4. uint8_t X_servoPin = 9;
  5. int X_ledPin = 3;
  6.  
  7. uint8_t Y_potPin = A1;
  8. uint8_t Y_servoPin = 10;
  9. int Y_ledPin = 5;
  10.  
  11. int X_potVal;
  12. int OLD_X_potVal;
  13. int Y_potVal;
  14. int OLD_Y_potVal;
  15.  
  16. boolean usePot = true;
  17. boolean sendValues = true;
  18.  
  19. Servo X_servo;
  20. Servo Y_servo;
  21.  
  22. void setup() {
  23.   Serial.begin(9600);
  24.   Serial.println("CameraOperator 2.0");
  25.   X_servo.attach(X_servoPin);
  26.  
  27.   Y_servo.attach(Y_servoPin);
  28. }
  29.  
  30. void loop() {
  31.   if (usePot == true) {
  32.     X_potVal = analogRead(X_potPin);
  33.     X_potVal = map(X_potVal, 0, 1023,0,180);
  34.     X_servo.write(X_potVal);
  35.    
  36.     Y_potVal = analogRead(Y_potPin);
  37.     Y_potVal = map(Y_potVal, 0, 1023,0,180);
  38.     Y_servo.write(Y_potVal);
  39.   }
  40.   if (sendValues == true) {
  41.     if (OLD_X_potVal != X_potVal) {
  42.       Serial.print("X: ");
  43.       Serial.println(X_potVal);
  44.     }
  45.     OLD_X_potVal = X_potVal;
  46.     if (OLD_Y_potVal != Y_potVal) {
  47.       Serial.print("       Y: ");
  48.       Serial.println(Y_potVal);
  49.     }
  50.     OLD_Y_potVal = Y_potVal;
  51.   }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement