Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo motor1; // Objek Servo untuk motor 1
- Servo motor2; // Objek Servo untuk motor 2
- Servo motor3; // Objek Servo untuk motor 3
- Servo motor4; // Objek Servo untuk motor 4
- // -------------------------------------------
- // Program Mengontrol Kecepatan Motor DC Drone
- // www.ardukode.blogspot.com
- // -------------------------------------------
- int throttle = 0; // Nilai throttle dari joystick atau remote control
- int pitch = 0; // Nilai pitch dari joystick atau remote control
- int roll = 0; // Nilai roll dari joystick atau remote control
- int yaw = 0; // Nilai yaw dari joystick atau remote control
- void setup() {
- motor1.attach(9); // Hubungkan motor 1 ke pin 9
- motor2.attach(10); // Hubungkan motor 2 ke pin 10
- motor3.attach(11); // Hubungkan motor 3 ke pin 11
- motor4.attach(12); // Hubungkan motor 4 ke pin 12
- }
- void loop() {
- // Baca nilai throttle, pitch, roll, dan yaw dari joystick atau remote control
- // Hitung kecepatan motor berdasarkan nilai throttle, pitch, roll, dan yaw
- int speed1 = throttle + pitch + roll + yaw;
- int speed2 = throttle - pitch + roll - yaw;
- int speed3 = throttle + pitch - roll - yaw;
- int speed4 = throttle - pitch - roll + yaw;
- // Batasi kecepatan motor
- speed1 = constrain(speed1, 0, 255);
- speed2 = constrain(speed2, 0, 255);
- speed3 = constrain(speed3, 0, 255);
- speed4 = constrain(speed4, 0, 255);
- // Kontrol kecepatan motor
- motor1.write(speed1);
- motor2.write(speed2);
- motor3.write(speed3);
- motor4.write(speed4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement