Controlar Servomotor con Arduino
0:28
Cpp
#include Servo servo1; Servo servo2; int pos1 = 0; int pos2 = 0; int step1 = 1; int step2 = 1; unsigned long previousMillis1 = 0; unsigned long previousMillis2 = 0; const unsigned long interval1 = 15; // Intervalo para servo1 (15 ms) const unsigned long interval2 = 30; // Intervalo para servo2 (30 ms) void setup() { // Asignar pines para los servomotores servo1.attach(9); servo2.attach(10); // Posicionar inicialmente los servos servo1.write(pos1); servo2.write(pos2); } void loop() { unsigned long currentMillis = millis(); // Actualizar el primer servo cada 15 ms if (currentMillis - previousMillis1 >= interval1) { previousMillis1 = currentMillis; pos1 += step1; if (pos1 >= 180 || pos1 = interval2) { previousMillis2 = currentMillis; pos2 += step2; if (pos2 >= 180 || pos2 <= 0) { step2 = -step2; // Cambiar dirección al alcanzar extremos } servo2.write(pos2); } }
millis() para actualizar cada servomotor en intervalos diferentes: servo1 se actualiza cada 15 ms y servo2 cada 30 ms. Cada servo se moverá de 0 a 180 grados y luego cambiará de dirección de manera independiente. Puedes ajustar los pines, los intervalos o la lógica de pasos según tus necesidades.Reviews
Efficient Aquamarine Time Machine
Properties
Properties describe core aspects of the project.
Pricing & Availability
Distributor | Qty 1 |
|---|
Controls
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.

AI-Powered Component Placement
Let AI place your components intelligently. AI Placement analyzes your schematic and positions components for optimal routing, signal integrity, and board density.
From Schematic to Layout in Seconds
Skip the tedious manual placement. AI Placement generates a starting layout you can refine, saving hours of repetitive work on every new design.
Works With Auto-Layout
Pair AI Placement with Auto-Layout for a complete AI-driven PCB design flow — from component placement through trace routing, all with one click.