daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 90 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 && initial_position < 10) {
  31.     else {
  32.       initial_position = initial_position - 8;
  33.       servo1.write ( initial_position ) ;
  34.       delay (100) ;
  35.     }
  36.   } if (x_pos > 100 && initial_position > 180 ) {
  37.     else {
  38.       initial_position = initial_position + 8;
  39.       servo1.write ( initial_position ) ;
  40.       delay (100) ;
  41.     }
  42.   }
  43.  
  44.   if (y_pos < 35 && initial_position1 < 0) {
  45.     else {
  46.       initial_position1 = initial_position1 - 8;
  47.       servo2.write ( initial_position1 ) ;
  48.       delay (100) ;
  49.     }
  50.   }
  51.   if (y_pos > 50 && initial_position1 > 80) {
  52.     else {
  53.       initial_position1 = initial_position1 + 8;
  54.       servo2.write ( initial_position1 ) ;
  55.       delay (100) ;
  56.     }
  57.   }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top