Skip to content

Commit ea03647

Browse files
author
Nathan Seidle
committed
Initial push. Mostly working. Needs writeMicro and overloaded attach.
1 parent 0f4fd34 commit ea03647

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

libraries/Servo/keywords.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#######################################
2+
# Syntax Coloring Map
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
#######################################
10+
# Methods and Functions (KEYWORD2)
11+
#######################################
12+
13+
attach KEYWORD2
14+
write KEYWORD2
15+
detach KEYWORD2
16+
read KEYWORD2
17+
18+
writeMicroseconds KEYWORD2
19+
attached KEYWORD2
20+
21+
#######################################
22+
# Instances (KEYWORD2)
23+
#######################################
24+
25+
#######################################
26+
# Constants (LITERAL1)
27+
#######################################
28+

libraries/Servo/library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Servo
2+
version=1.0.0
3+
author=SparkFun Electronics
4+
maintainer=SparkFun Electronics <sparkfun.com>
5+
sentence=Allows control of standard PWM based servos
6+
paragraph=
7+
category=Device Control
8+
url=http://www.arduino.cc/en/Reference/Servo
9+
architectures=apollo3

libraries/Servo/src/Servo.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
3+
Copyright (c) 2015 Arduino LLC. All rights reserved.
4+
Copyright (c) 2019 SparkFun Electronics
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
#include "Servo.h"
26+
#include "Arduino.h"
27+
28+
//Constructor
29+
Servo::Servo()
30+
{
31+
}
32+
33+
//Assign global var
34+
void Servo::attach(uint8_t pinNumber)
35+
{
36+
_servoPinNumber = pinNumber;
37+
_servoPadNumber = ap3_gpio_pin2pad(pinNumber);
38+
}
39+
40+
void Servo::write(uint8_t servoPosition)
41+
{
42+
_servoPosition = servoPosition;
43+
if (_servoPosition > 180)
44+
_servoPosition = 180; //Bounds check
45+
46+
uint16_t newServoPosition = map(servoPosition, 0, 180, 0, 1023);
47+
48+
servoWrite(_servoPadNumber, newServoPosition); // This and the above write should both produce 1.5 ms wide pulses, though using different resolutions
49+
}
50+
51+
void Servo::writeMicroseconds(uint8_t servoPosition)
52+
{
53+
54+
servoWrite(_servoPadNumber, newServoPosition); // This and the above write should both produce 1.5 ms wide pulses, though using different resolutions
55+
}
56+
57+
void Servo::detach(void)
58+
{
59+
_servoPinNumber = NULL;
60+
_servoPadNumber = NULL;
61+
pinMode(_servoPinNumber, INPUT); //Will stop PWM output
62+
}
63+
64+
uint8_t Servo::read(void)
65+
{
66+
return (_servoPosition);
67+
}
68+
69+
bool Servo::attached(uint8_t pinNumber)
70+
{
71+
if (_servoPinNumber == pinNumber)
72+
return (true);
73+
return (false);
74+
}

libraries/Servo/src/Servo.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright (c) 2019 SparkFun Electronics
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
23+
// ToDo: Make TwoWire a library (under "libraries") to get syntax highlighting
24+
25+
#ifndef _AP3_SERVO_H_
26+
#define _AP3_SERVO_H_
27+
28+
#include "Arduino.h"
29+
30+
class Servo
31+
{
32+
public:
33+
Servo();
34+
void attach(uint8_t pinNumber);
35+
void write(uint8_t servoPosition);
36+
void detach(void);
37+
uint8_t read(void);
38+
bool attached(uint8_t pinNumber);
39+
40+
private:
41+
uint8_t _servoPadNumber = NULL;
42+
uint8_t _servoPinNumber = NULL;
43+
uint8_t _servoPosition;
44+
};
45+
46+
#endif // _AP3_SERVO_H_

0 commit comments

Comments
 (0)