Advertisement
RuiViana

So_Eixo_X

Nov 16th, 2016
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 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 val_x;   //Armazena o valor do eixo X
  6. int ServoX = 0;
  7.  
  8. //----------------------------
  9. void setup()
  10. {
  11.   Serial.begin(9600);
  12.   servo_base.attach(7, 1, 180);
  13. }
  14. //----------------------------
  15. void loop()
  16. {
  17.   val_x = analogRead(pino_x);
  18.   Serial.print("val_x ");    Serial.println(val_x);
  19.   if (val_x > 750)
  20.   {
  21.     ServoX ++;
  22.     if (ServoX >= 180 ) ServoX = 180;
  23.   }
  24.  
  25.   if (val_x < 300)
  26.   {
  27.     ServoX --;
  28.     if (ServoX <= 0 ) ServoX = 0;
  29.   }
  30.   Serial.print("ServoX ");    Serial.println(ServoX);
  31.   servo_base.slowmove(ServoX, 60);
  32.   delay(30);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement