Skip to content

Commit ab4eb34

Browse files
Merge pull request #7 from byrmeng/master
1.1.0
2 parents 0ba0eeb + 7e7f8cd commit ab4eb34

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Deneyap Servo
2-
version=1.0.7
2+
version=1.1.0
33
author=Turkish Technnology Team Foundation (T3) <[email protected]>
44
maintainer=Turkish Technnology Team Foundation (T3) <[email protected]>
55
sentence=Arduino library to drive servo motors

src/Deneyap_Servo.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
void Servo::attach(int pin, int channel, int freq, int resolution) {
2424
_channel = channel;
25+
_pin = pin;
2526
if(channel > 15) channel = 15;
26-
ledcSetup(_channel, freq, resolution);
27-
ledcAttachPin(pin, channel);
28-
ledcWrite(_channel, FIRSTDUTY);
27+
ledcAttachChannel(pin, freq, resolution, channel);
28+
ledcWriteChannel(_channel, FIRSTDUTY);
2929
}
3030

3131
/**
@@ -34,12 +34,18 @@ void Servo::attach(int pin, int channel, int freq, int resolution) {
3434
* @retval None
3535
**/
3636

37+
void ESC::attach(int pin, int channel, int freq, int resolution) {
38+
_channel = channel;
39+
if(channel > 15) channel = 15;
40+
ledcAttachChannel(pin, freq, resolution, channel);
41+
ledcWriteChannel(_channel, FIRSTDUTY);
42+
}
43+
3744
void Servo::write(int value) {
3845
if(value < SERVOMIN) value = SERVOMIN;
3946
if(value > SERVOMAX) value = SERVOMAX;
4047
int servoValue = (value - SERVOMIN) * (DUTYCYLEMAX - DUTYCYLEMIN) / (SERVOMAX - SERVOMIN) + DUTYCYLEMIN; // mapping to SERVOMIN-SERVOMAX values from DUTYCYLEMIN-DUTYCYLEMAX values
41-
ledcWrite(_channel, servoValue); // _channel select servoValue(duty) to be set for selected channel
42-
//delay(DELAYMS);
48+
ledcWriteChannel(_channel, servoValue); // _channel select servoValue(duty) to be set for selected channel
4349
}
4450

4551
void Servo::writeMicroseconds(int value) {
@@ -49,31 +55,26 @@ void Servo::writeMicroseconds(int value) {
4955
this->write(value);
5056
}
5157

52-
void ESC::attach(int pin, int channel, int freq, int resolution) {
53-
_channel = channel;
54-
if(channel > 15) channel = 15;
55-
ledcSetup(_channel, freq, resolution);
56-
ledcAttachPin(pin, channel);
57-
ledcWrite(_channel, FIRSTDUTY);
58+
void ESC::write(int value) {
59+
if(value < ESCMIN) value = ESCMIN;
60+
if(value > ESCMAX) value = ESCMAX;
61+
int escValue = (value - ESCMIN) * (ESCDUTYCYLEMAX - ESCDUTYCYLEMIN) / (ESCMAX - ESCMIN) + ESCDUTYCYLEMIN; // mapping to SERVOMIN-SERVOMAX values from DUTYCYLEMIN-DUTYCYLEMAX values
62+
ledcWriteChannel(_channel, escValue); // _channel select servoValue(duty) to be set for selected channel
5863
}
5964

6065
int Servo::read() {
61-
int dutyCycle = ledcRead(_channel);
62-
int newDutyCycle = map(dutyCycle, DUTYCYLEMIN, DUTYCYLEMAX, SERVOMIN, SERVOMAX) + 1;
63-
if(newDutyCycle % 45 == 0) newDutyCycle--;
64-
return map(newDutyCycle, SERVOMIN, SERVOMAX, 0, 180);
66+
int dutyCycle = ledcRead(_pin);
67+
int newDutyCycle = map(dutyCycle, DUTYCYLEMIN, DUTYCYLEMAX, SERVOMIN, SERVOMAX);
68+
if(newDutyCycle % 45 == 0){
69+
return newDutyCycle;
70+
} else {
71+
return newDutyCycle + 1;
72+
}
6573
}
6674

67-
int Servo::readMicroseconds() {
75+
int Servo::readMicroseconds() {
6876
this->read();
6977
}
70-
void ESC::write(int value) {
71-
if(value < ESCMIN) value = ESCMIN;
72-
if(value > ESCMAX) value = ESCMAX;
73-
int escValue = (value - ESCMIN) * (ESCDUTYCYLEMAX - ESCDUTYCYLEMIN) / (ESCMAX - ESCMIN) + ESCDUTYCYLEMIN; // mapping to SERVOMIN-SERVOMAX values from DUTYCYLEMIN-DUTYCYLEMAX values
74-
ledcWrite(_channel, escValue); // _channel select servoValue(duty) to be set for selected channel
75-
//delay(DELAYMS);
76-
}
7778

7879
/*void Servo360::attach(int pin, int channel, int freq, int resolution) {
7980
_360channel = channel;
@@ -107,4 +108,4 @@ int Servo360::read() {
107108
108109
int Servo360::readMicroseconds() {
109110
this->read();
110-
}*/
111+
}*/

src/Deneyap_Servo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
#define SERVOMIN 0
2424
#define SERVOMAX 180
25-
#define DUTYCYLEMIN 100
26-
#define DUTYCYLEMAX 500
25+
#define DUTYCYLEMIN 97
26+
#define DUTYCYLEMAX 521
2727

2828
#define SERVO360MIN 0
2929
#define SERVO360MAX 360
@@ -42,6 +42,7 @@ class Servo {
4242
int readMicroseconds();
4343
private:
4444
int _channel;
45+
int _pin;
4546
};
4647

4748
class ESC {
@@ -62,4 +63,4 @@ class ESC {
6263
private:
6364
int _360channel;
6465
};*/
65-
#endif /* _DENEYAPSERVO_H_ */
66+
#endif /* _DENEYAPSERVO_H_ */

0 commit comments

Comments
 (0)