controlling servo speed is really crude system i think. Your codes might change according to your servo type.
I did some projects about sg90 servo speed. I used for loop to change degree and i added delay in loop.
for example,
for(int x = 0; x<=180; x++) {
servo.write(x);
delay(100);
}
if you increase delay, your servo will turn slowly but low res.
some servos can move slowly by decreasing vcc voltage
seems like you didnt get what i want. i cant translate your example to my problem. i dont want the servo to move by itself. i want to control the angle with a slider and it should move slow all the time. help would be much apprechiated
hi, do you think something like this could work? (still not working properly)
regards
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxx";
char pass[] = "xxx";
Servo servo;
BLYNK_WRITE(V3)
{
servo.write(param.asInt());
}
const int targetPin = 4;
const int servoDuration = 10; // number of millisecs that servo is on
const int interval = 10; // number of milisecs when the servo is off
//------------ VARIABLES (will change)---------------------
byte targetservoState = servo.attach(4); // this variable is necesary to help arduino monitor the status of servo
//the initial condition (t=0) can be either run or stop
unsigned long currentMillis = 0; // stores the value of millis() in each iteration of loop()
unsigned long previousservoMillis = 0; // will store last time the servo was updated
//========== THE SETUP ==============================
void setup() {
// Debug console
Serial.begin(9600); //default comm speed between arduino and serial monitor. no need to change.
Serial.println("servoMillis.ino"); // so we know what sketch is running
pinMode(targetPin, OUTPUT);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}
//========== THE LOOP ==============================
void loop() {
Blynk.run();
currentMillis = millis(); // capture the latest value of millis()
// this is equivalent to noting the time from a clock
updateTargetservo(); //monitoring status of servo and do approproate actions
}
//------------ OTHER FUNCTIONS ---------------------
void updateTargetservo() {
if (targetservoState == servo.attach(0)) { //if the servo is OFF
Serial.println("detach()");
if ((unsigned long) currentMillis - previousservoMillis >= interval) {
targetservoState = servo.attach(4);
digitalWrite(targetPin, targetservoState);
// and save the time when we made the change
previousservoMillis += interval;
// NOTE: The previous line could alternatively be
// previousservoMillis = currentMillis
// Adding on the interval is a better way to ensure that succesive periods are identical
}
}
else { // i.e. if servoState is run (if the servo is ON)
Serial.println("servo.attach(4)");
if ((unsigned long) currentMillis - previousservoMillis >= servoDuration) {
targetservoState = servo.attach(0);
digitalWrite(targetPin, targetservoState);
// and save the time when we made the change
previousservoMillis += servoDuration;
// NOTE: The previous line could alternatively be
// previousservoMillis = currentMillis
// Adding on the duration is a better way to ensure that succesive periods are identical
}
}
}