Arduino Servo Control Code
0:31
Cpp
#include Servo servo1; Servo servo2; // Posiciones iniciales y objetivo int pos1 = 0; int pos2 = 0; int target1 = 180; int target2 = 180; // Velocidades de movimiento (en ms entre pasos) // Ajusta estos valores para cambiar la velocidad (cuanto mayor el delay, menor la velocidad) int speed1 = 10; // Velocidad para servo1 int speed2 = 20; // Velocidad para servo2 void setup() { // Conecta los servomotores a los pines 9 y 10 servo1.attach(9); servo2.attach(10); // Posiciones iniciales servo1.write(pos1); servo2.write(pos2); } void loop() { // Mover servo1 hacia target1 if (pos1 < target1) { for (int i = pos1; i <= target1; i++) { servo1.write(i); delay(speed1); } } else if (pos1 > target1) { for (int i = pos1; i >= target1; i--) { servo1.write(i); delay(speed1); } } pos1 = target1; // Mover servo2 hacia target2 if (pos2 < target2) { for (int i = pos2; i <= target2; i++) { servo2.write(i); delay(speed2); } } else if (pos2 > target2) { for (int i = pos2; i >= target2; i--) { servo2.write(i); delay(speed2); } } pos2 = target2; // Espera un segundo en las posiciones objetivo delay(1000); // Intercambiar los objetivos para volver a la posición opuesta target1 = (target1 == 180) ? 0 : 180; target2 = (target2 == 180) ? 0 : 180; }
Ready.
Reviews
Inspect
Ethnic Jade Liquid Breathing Apparatus
Controls
Properties
Availability & Pricing
| Distributor | Qty 1 | |
|---|---|---|
Assets
Welcome 👋
Flux helps you build PCBs faster with an AI teammate!
Create your account to collaborate, stay updated, fork your own version, and get instant answers from our AI agent.