Advertisement
RuiViana

JoyStick_Control

Nov 16th, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <VarSpeedServo.h>
  2. VarSpeedServo servo_base;
  3. VarSpeedServo servo_inclinacao;
  4. int pino_x = A4; //Pino ligado ao X do joystick
  5. int pino_y = A5; //Pino ligado ao Y do joystick
  6. int val_x;   //Armazena o valor do eixo X
  7. int val_y;   //Armazena o valor do eixo Y
  8. int ServoX = 0;
  9. int ServoY = 0;
  10. //----------------------------
  11. void setup()
  12. {
  13.   Serial.begin(9600);
  14.   servo_base.attach(7, 1, 180);
  15.   servo_inclinacao.attach(8, 1, 180);
  16. }
  17. //----------------------------
  18. void loop()
  19. {
  20.   val_x = analogRead(pino_x);
  21.   Serial.print("val_x ");    Serial.println(val_x);
  22.   if (val_x > 750)
  23.   {
  24.     ServoX = ServoX + 10;
  25.     if (ServoX >= 180 ) ServoX = 180;
  26.   }
  27.  
  28.   if (val_x < 300)
  29.   {
  30.     ServoX = ServoX - 10;
  31.     if (ServoX <= 0 ) ServoX = 0;
  32.   }
  33.   Serial.print("ServoX ");    Serial.println(ServoX);
  34.   servo_base.slowmove(ServoX, 60);
  35.  
  36.    val_y = analogRead(pino_y);
  37.   Serial.print("val_y ");    Serial.println(val_y);
  38.   if (val_y > 750)
  39.   {
  40.     ServoY = ServoY + 10;
  41.     if (ServoY >= 180 ) ServoY = 180;
  42.   }
  43.  
  44.   if (val_y < 300)
  45.   {
  46.     ServoY  = ServoY - 10;
  47.     if (ServoY <= 0 ) ServoY = 0;
  48.   }
  49.   Serial.print("ServoY ");    Serial.println(ServoY);
  50.   servo_inclinacao.slowmove(ServoY, 60);
  51.   delay(30);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement