Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2.  
  3. Servo servo1;
  4. Servo servo2;
  5. int x_key = A1;
  6. int y_key = A0;
  7. int x_pos;
  8. int y_pos;
  9. int servo1_pin = 10;
  10. int servo2_pin = 9;
  11. int initial_position = 90;
  12. int initial_position1 = 90;
  13.  
  14. void setup ( ) {
  15.   Serial.begin (9600) ;
  16.   servo1.attach (servo1_pin ) ;
  17.   servo2.attach (servo2_pin ) ;
  18.   servo1.write (initial_position);
  19.   servo2.write (initial_position1);
  20.   pinMode (x_key, INPUT) ;
  21.   pinMode (y_key, INPUT) ;
  22. }
  23.  
  24. void loop ( ) {
  25.   x_pos = analogRead (x_key) ;
  26.   x_pos = map(x_pos, 0, 1023, 0, 180);
  27.   y_pos = analogRead (y_key) ;
  28.   y_pos = map(y_pos, 0, 1023, 0, 90);
  29.  
  30.   if (x_pos < 70) {
  31.     if (initial_position < 10) { }
  32.     else {
  33.       initial_position = initial_position - 8;
  34.       servo1.write ( initial_position ) ;
  35.       delay (100) ;
  36.     }
  37.   }
  38.   if (x_pos > 100) {
  39.     if (initial_position > 180) {}
  40.     else {
  41.       initial_position = initial_position + 8;
  42.       servo1.write ( initial_position ) ;
  43.       delay (100) ;
  44.     }
  45.   }
  46.   if (y_pos < 35) {
  47.     if (initial_position1 < 0) { }
  48.     else {
  49.       initial_position1 = initial_position1 - 8;
  50.       servo2.write ( initial_position1 ) ;
  51.       delay (100) ;
  52.     }
  53.   }
  54.   if (y_pos > 50) {
  55.     if (initial_position1 > 89) {}
  56.     else {
  57.       initial_position1 = initial_position1 + 8;
  58.       servo2.write ( initial_position1 ) ;
  59.       delay (100) ;
  60.     }
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement