Chat
Welcome to Flux
Treat Flux like your intern. Tell it what you'd like to build and it'll get to work. You can also ask it questions, brainstorm ideas, and teach it your preferences. Learn More
Ready.
Cpp
#include Servo servo1; Servo servo2; Servo servo3; Servo servo4; Servo servo5; const int trigPin = 11; const int echoPin = 12; long duration; int distance; void setup() { servo1.attach(3); servo2.attach(5); servo3.attach(6); servo4.attach(9); servo5.attach(10); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { // Limpia el trigPin digitalWrite(trigPin, LOW); delayMicroseconds(2); // Establece el trigPin en HIGH por 10 microsegundos digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Lee el echoPin, devuelve el tiempo de viaje del sonido en microsegundos duration = pulseIn(echoPin, HIGH); // Calculando la distancia distance= duration*0.034/2; // Mueve los servos según la distancia if(distance < 10){ // Si el objeto está cerca, mueve los servos a una posición servo1.write(180); servo2.write(180); servo3.write(180); servo4.write(180); servo5.write(180); } else { // Si no hay objetos cerca, vuelve los servos a la posición inicial servo1.write(0); servo2.write(0); servo3.write(0); servo4.write(0); servo5.write(0); } delay(1000); // Delay de 1 segundo para no saturar el sensor }
Servo que viene incluida en el IDE de Arduino para poder usar el código tal cual.Reviews
Properties
Properties describe core aspects of the project.
Pricing & Availability
Distributor | Qty 1 |
|---|
Assets
No assets added.
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.
matrix9
matrix9
copilot
matrix9
copilot
matrix9
copilot
matrix9
copilot