Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <VarSpeedServo.h>
- VarSpeedServo servo_base;
- VarSpeedServo servo_inclinacao;
- int pino_x = A4; //Pino ligado ao X do joystick
- int pino_y = A5; //Pino ligado ao Y do joystick
- int val_x; //Armazena o valor do eixo X
- int val_y; //Armazena o valor do eixo Y
- int ServoX = 0;
- int ServoY = 0;
- //----------------------------
- void setup()
- {
- Serial.begin(9600);
- servo_base.attach(7, 1, 180);
- servo_inclinacao.attach(8, 1, 180);
- }
- //----------------------------
- void loop()
- {
- val_x = analogRead(pino_x);
- Serial.print("val_x "); Serial.println(val_x);
- if (val_x > 750)
- {
- ServoX = ServoX + 10;
- if (ServoX >= 180 ) ServoX = 180;
- }
- if (val_x < 300)
- {
- ServoX = ServoX - 10;
- if (ServoX <= 0 ) ServoX = 0;
- }
- Serial.print("ServoX "); Serial.println(ServoX);
- servo_base.slowmove(ServoX, 60);
- val_y = analogRead(pino_y);
- Serial.print("val_y "); Serial.println(val_y);
- if (val_y > 750)
- {
- ServoY = ServoY + 10;
- if (ServoY >= 180 ) ServoY = 180;
- }
- if (val_y < 300)
- {
- ServoY = ServoY - 10;
- if (ServoY <= 0 ) ServoY = 0;
- }
- Serial.print("ServoY "); Serial.println(ServoY);
- servo_inclinacao.slowmove(ServoY, 60);
- delay(30);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement