Hola buena tarde.
Necesito ayuda con un programa, requiero que un servomotor inicie desde los 90° y realice un recorrido de los 50° hasta los 130° con un delay. Todo esto lo estoy realizando con un una variables de velocidad y una de ángulo controladas con dos potenciometro. Espero que me puedan ayudar, gracias.
//Incluimos la libreria servo
#include <Servo.h>
//Iniciamos el Servo
Servo servo1;
int potpin = 0; // grados
int val; // variable to read the value from the analog pin
int potenciometra = 5; //velocidad
int val2; // variable to read the value from the analog pin
int velocidad;
int servol;
void setup()
{
//Le decimos donde esta conectado
//servol.write(0);
servo1.attach(11);
pinMode(servol, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//Le mandamos que escriba 0º
servo1.write(0);
//Que espere 2.5 seg
delay(velocidad);
//Le mandamos que escriba 180º
servo1.write(val);
// Que espere otros 2.5 seg
delay(velocidad);
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
val2= analogRead(potenciometra); // reads the value of the potentiometer (value between 0 and 1023)
velocidad= map(val2, 0, 1023, 0, 2000);
digitalWrite(servol, HIGH);
Serial.print ( "grados=");
Serial.print (val);
Serial.print (" velocidad=");
Serial.println (velocidad);
}