Skip to content

Commit 7ddc2b9

Browse files
Merge pull request #9 from byrmeng/master
1.1.1
2 parents 2a538f4 + 0b1f843 commit 7ddc2b9

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
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.1.0
2+
version=1.1.1
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: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
*************************************************************************************************
33
@file Deneyap_Servo.cpp
44
@mainpage Deneyap Servo Arduino library source file
5-
@version v1.1.0
5+
@version v1.1.1
66
@date October 20, 2022
77
@brief Includes functions to drive servo motor for Deneyap Development Boards
88
*************************************************************************************************
99
*/
1010

1111
#include "Deneyap_Servo.h"
1212

13+
#ifndef CORE_DK_VERSION
14+
#define CORE_DK_VERSION 0 // fallback
15+
#endif
1316
/**
1417
* @brief attaches the given pin, channel, freq, resolution
1518
* @param @pin : servo pin
@@ -23,8 +26,14 @@ void Servo::attach(int pin, int channel, int freq, int resolution) {
2326
_channel = channel;
2427
_pin = pin;
2528
if(channel > 15) channel = 15;
29+
#if CORE_DK_VERSION <= 103013
30+
ledcSetup(_channel, freq, resolution);
31+
ledcAttachPin(pin, channel);
32+
ledcWrite(_channel, FIRSTDUTY);
33+
#else
2634
ledcAttachChannel(pin, freq, resolution, channel);
2735
ledcWriteChannel(_channel, FIRSTDUTY);
36+
#endif
2837
}
2938

3039
/**
@@ -36,15 +45,25 @@ void Servo::attach(int pin, int channel, int freq, int resolution) {
3645
void ESC::attach(int pin, int channel, int freq, int resolution) {
3746
_channel = channel;
3847
if(channel > 15) channel = 15;
48+
#if CORE_DK_VERSION <= 103013
49+
ledcSetup(_channel, freq, resolution);
50+
ledcAttachPin(pin, channel);
51+
ledcWrite(_channel, FIRSTDUTY);
52+
#else
3953
ledcAttachChannel(pin, freq, resolution, channel);
4054
ledcWriteChannel(_channel, FIRSTDUTY);
55+
#endif
4156
}
4257

4358
void Servo::write(int value) {
4459
if(value < SERVOMIN) value = SERVOMIN;
4560
if(value > SERVOMAX) value = SERVOMAX;
4661
int servoValue = (value - SERVOMIN) * (DUTYCYLEMAX - DUTYCYLEMIN) / (SERVOMAX - SERVOMIN) + DUTYCYLEMIN; // mapping to SERVOMIN-SERVOMAX values from DUTYCYLEMIN-DUTYCYLEMAX values
62+
#if CORE_DK_VERSION <= 103013
63+
ledcWrite(_channel, servoValue);
64+
#else
4765
ledcWriteChannel(_channel, servoValue); // _channel select servoValue(duty) to be set for selected channel
66+
#endif
4867
}
4968

5069
void Servo::writeMicroseconds(int value) {
@@ -58,11 +77,19 @@ void ESC::write(int value) {
5877
if(value < ESCMIN) value = ESCMIN;
5978
if(value > ESCMAX) value = ESCMAX;
6079
int escValue = (value - ESCMIN) * (ESCDUTYCYLEMAX - ESCDUTYCYLEMIN) / (ESCMAX - ESCMIN) + ESCDUTYCYLEMIN; // mapping to SERVOMIN-SERVOMAX values from DUTYCYLEMIN-DUTYCYLEMAX values
80+
#if CORE_DK_VERSION <= 103013
81+
ledcWrite(_channel, escValue);
82+
#else
6183
ledcWriteChannel(_channel, escValue); // _channel select servoValue(duty) to be set for selected channel
84+
#endif
6285
}
6386

6487
int Servo::read() {
88+
#if CORE_DK_VERSION <= 103013
89+
int dutyCycle = ledcRead(_channel);
90+
#else
6591
int dutyCycle = ledcRead(_pin);
92+
#endif
6693
int newDutyCycle = map(dutyCycle, DUTYCYLEMIN, DUTYCYLEMAX, SERVOMIN, SERVOMAX);
6794
if(newDutyCycle % 45 == 0){
6895
return newDutyCycle;

src/Deneyap_Servo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*****************************************************************************
33
@file Deneyap_Servo.h
44
@mainpage Deneyap Servo Arduino library header file
5-
@version v1.1.0
5+
@version v1.1.1
66
@date October 20, 2022
77
@brief This file contains all function prototypes and macros
88
for servo motor Arduino library for Deneyap Development Boards

0 commit comments

Comments
 (0)