ServoEasing
LightweightServo.h
Go to the documentation of this file.
1 /*
2  * LightweightServo.h
3  *
4  * Copyright (C) 2019-2020 Armin Joachimsmeyer
5  * armin.joachimsmeyer@gmail.com
6  *
7  * This file is part of ServoEasing https://github.com/ArminJo/ServoEasing.
8  *
9  * ServoEasing is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  * See the GNU General Public License for more details.
18 
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
21  *
22  */
23 
24 #ifndef _LIGHTWEIGHT_SERVO_H
25 #define _LIGHTWEIGHT_SERVO_H
26 
27 #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
28 
29 #define VERSION_LIGHTWEIGHT_SERVO "1.1.0"
30 #define VERSION_LIGHTWEIGHT_SERVO_MAJOR 1
31 #define VERSION_LIGHTWEIGHT_SERVO_MINOR 1
32 
33 #include <stdint.h>
34 
35 /*
36  * Activating this saves 70 bytes program space. You must then use the init functions initLightweightServoPin*() manually.
37  */
38 //#define DISABLE_SERVO_TIMER_AUTO_INITIALIZE
39 #define ISR1_COUNT_FOR_20_MILLIS 40000 // you can modify this if you have servos which accept a higher rate
40 
41 /*
42  * Lightweight servo library
43  * Uses timer1 and Pin 9 + 10 as output
44  */
45 void initLightweightServoPin9And10();
46 void initLightweightServoPin9(); // Disables Pin 10!
47 void initLightweightServoPin10(); // Disables Pin 9!
48 void initLightweightServoPin9_10(bool aUsePin9, bool aUsePin10);
49 void deinitLightweightServoPin9_10(bool aUsePin9, bool aUsePin10);
50 
51 void setLightweightServoPulseMicrosFor0And180Degree(int aMicrosecondsForServo0Degree, int a180DegreeValue);
52 void setLightweightServoRefreshRate(unsigned int aRefreshPeriodMicroseconds);
53 
54 int writeLightweightServo(int aDegree, bool aUsePin9, bool aUpdateFast = false);
55 void writeMicrosecondsLightweightServo(int aMicroseconds, bool aUsePin9, bool aUpdateFast = false);
56 
57 void write9(int aDegree, bool aUpdateFast = false); // setLightweightServoPulsePin9 Channel A
58 void writeMicroseconds9(int aMicroseconds, bool aUpdateFast = false);
59 void writeMicroseconds9Direct(int aMicroseconds);
60 
61 void write10(int aDegree, bool aUpdateFast = false); // setLightweightServoPulsePin10 Channel B
62 void writeMicroseconds10(int aMicroseconds, bool aUpdateFast = false);
63 void writeMicroseconds10Direct(int aMicroseconds);
64 
65 // convenience functions
66 int DegreeToMicrosecondsLightweightServo(int aDegree);
67 int MicrosecondsToDegreeLightweightServo(int aMicroseconds);
68 
69 #endif // AVR_ATmega328
70 
71 /*
72  * Version 1.1.0 - 11/2020
73  * - Improved API.
74  */
75 
76 #endif // _LIGHTWEIGHT_SERVO_H