Thanks a lot
I try these 2 set of codes, but both codes don't work after updating the ESP32 Board to 3.0.5
Code 1
Error shown: Documents/Arduino/libraries/ESP32_Servo/src/ESP32_Servo.cpp:144:9: error: 'ledcSetup' was not declared in this scope
and more.....
#include <ESP32_Servo.h>
int servoPin = 18;
Servo myservo;
const int freq = 50;
const int ledChannel = 0;
const int resolution = 8;
const int dutyCycle = 26;
///////////////////////////
const int motor1Pin1 = 12;
const int motor1Pin2 = 13;
const int enable1Pin = 14;
const int freq2 = 30000;
const int ledChannel2 = 1;
const int resolution2 = 8;
const int dutyCycle2 = 200;
//////////()///////////////////
void setup(){
// ledcSetup(ledChannel,freq,resolution);
// ledcAttachPin(servoPin, ledChannel);
ledcAttachChannel(servoPin, freq, resolution, ledChannel);
myservo.attach(servoPin, 700, 7000);
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enable1Pin, OUTPUT);
// ledcSetup(ledChannel2,freq2,resolution2);
//ledcAttachPin(enable1Pin,ledChannel2);
ledcAttachChannel(enable1Pin, freq2, resolution2, ledChannel2);
}
void loop(){
ledcWrite(servoPin,dutyCycle);
ledcWrite(enable1Pin,dutyCycle2);
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
myservo.write(0);
delay(300);
myservo.write(80);
delay(300);
}
Code 2:
L298N DC Motor work but Servo has no response.
// Values for TowerPro SG90 small servos; adjust if needed
//Servo
#define COUNT_LOW 1638
#define COUNT_HIGH 7864
#define TIMER_WIDTH 16
#include "esp32-hal-ledc.h"
int servoPin = 18;
int servoFreq = 50;
int servoResolution = 8;
int servoChannel = 3;
int servoDutyCycle = 26;
// L298N
int motor1Pin1 = 12;
int motor1Pin2 = 13;
int enable1Pin = 14;
int dcFreq = 30000;
int dcResolution = 8;
int dcChannel = 0;
int dcDutyCycle = 200;
void setup() {
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enable1Pin, OUTPUT);
Serial.begin(9600);
ledcAttachChannel(servoPin, servoFreq, servoResolution, servoChannel); // pin, freq, resulution, channel
ledcAttachChannel(enable1Pin, dcFreq, dcResolution, dcChannel); // pin, freq, resulution, channel
}
void loop() {
Serial.println("Servo Turn");
//ledcWrite(servoChannel, servoDutyCycle);
for(int i=COUNT_LOW ; i < COUNT_HIGH ; i=i+100){
//ledcWrite(servoChannel, i); // sweep servo 1
ledcWrite(servoPin, i); // sweep servo 1
delay(30);
}
for (int i= COUNT_HIGH; i > COUNT_LOW ; i=i-100){
//ledcWrite(servoChannel, i); // sweep servo 1
ledcWrite(servoPin, i); // sweep servo 1
delay(30);
}
/////////////Control L298N, Different Direction, Different Speed
Serial.println("DC Motor Turn");
ledcWrite(enable1Pin, dcDutyCycle);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
delay(3000);
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
delay(3000);
}
Many Thanks Everyone again and hopefully the problem can be solved
Thanks