Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Robotica para todos
- // Autor: Juan Manoel
- // Projeto: Braço robotico DIY
- #include <Servo.h>
- const int servo1 = 3;
- const int servo2 = 5;
- const int servo3 = 6;
- const int servo4 = 9;
- const int joyH = 3;
- const int joyV = 4;
- const int joyX = 1;
- const int joyY = 2;
- int servoVal;
- Servo myservo1;
- Servo myservo2;
- Servo myservo3;
- Servo myservo4;
- void setup() {
- myservo1.attach(servo1);
- myservo2.attach(servo2);
- myservo3.attach(servo3);
- myservo4.attach(servo4);
- Serial.begin(9600);
- }
- void loop(){
- outputJoystick();
- servoVal = analogRead(joyH);
- servoVal = map(servoVal, 0, 1023, 0, 180);
- myservo1.write(servoVal);
- servoVal = analogRead(joyV);
- servoVal = map(servoVal, 0, 1023, 70, 180);
- myservo2.write(servoVal);
- servoVal = analogRead(joyX);
- servoVal = map(servoVal, 0, 1023, 70, 180);
- myservo3.write(servoVal);
- servoVal = analogRead(joyY);
- servoVal = map(servoVal, 0, 1023, 70, 180);
- myservo4.write(servoVal);
- delay(15);
- }
- void outputJoystick(){
- Serial.print(analogRead(joyH));
- Serial.print ("---");
- Serial.print(analogRead(joyV));
- Serial.println ("----------------");
- Serial.print(analogRead(joyX));
- Serial.println ("----------------");
- Serial.print(analogRead(joyY));
- Serial.println ("----------------");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement