Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm controlling servo motor position with Blynk slider over PCA9685 and ESP8266 (NodeMCU). I want my servo runs slower than at default speed and i need a part of code (maybe function) which sets a custom speed.

Here is my code:

#define BLYNK_PRINT Serial       // THESE 3 LIBRARIES FOR USING BLYNK CLOUD
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include<Servo.h>    // SERVO MOTOR LIBRARY
#include <ESP8266WiFi.h>   //NODEMCU WIFI MODULE LIBRARY
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define MIN_PULSE_WIDTH 150// this is the 'minimum' pulse length count (out of 4096)
#define MIN_PULSE_WIDTH 2400 //

char auth[] = "**********************";  //AUTHENTICATION KEY PROVIDED BY BLYNK CLOUD
char ssid[] = "*********";   //WIFI SSID
char pass[] = "**************";  //WIFI PASSWORD

int  slider1;

void setup()
{
  Serial.begin(9600);  //TO BEGIN SERIAL MONITOR
  Blynk.begin(auth, ssid, pass);//TO BEGIN BLYNK CLOUD CONNECTION
  Wire.begin();                 // Wire must be started first
  pwm.begin();
  pwm.setPWMFreq(50);
}

void loop()
{
  Blynk.run();  //TO START PUBLISHING DATA TO BLYNK CLOUD
}

BLYNK_WRITE(V1) //THIS FUNCTION IS TO WRITE THE VALUES OF SERVO FROM BLYNK MOBILE INTERFACE
{
  int slider1 = param.asInt(); // assigning incoming value from pin V1 to a variable
  Serial.print("Slider1: ");
  Serial.println(slider1);
  slider1 = map(slider1, 0, 180, 128, 550);
  pwm.setPWM(1, 0, slider1);
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
454 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...