-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpenServo.h
71 lines (61 loc) · 1.91 KB
/
OpenServo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* OpenServo Arduino/Wire Communication Library
*
* This library communicates with an OpenServo on the i2c bus using the
* OpenServo i2c API (http://www.openservo.com/APIGuide). You must create
* an instance of Wire to pass to the library. The library will grab and
* release the i2c bus during its communication cycles, but will not lock
* up the bus outside of the library, so you can use the Wire instance to
* communicate with other i2c devices on the bus, or send special commands
* to an OpenServo, should you find this library lacking in some way.
*
* Copyright 2012 Sterling Lewis Peet <[email protected]>
*
* This work is licensed under the Creative Commons
* Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of
* this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or
* send a letter to:
*
* Creative Commons
* 444 Castro Street, Suite 900
* Mountain View, California, 94041, USA.
*
* Other Licensing is available upon request.
*
*/
#ifndef OPENSERVO_H
#define OPENSERVO_H
#include <Wire.h>
// OpenServo registers & commands
#define OPENSERVO_POSITION 0x08
#define OPENSERVO_SEEK 0x10
#define OPENSERVO_PWM_ENABLE 0x82
#define OPENSERVO_PWM_DISABLE 0x83
// servo i2c address
#define DEFAULT_SERVO_ADDRESS 0x10
// Wire compatability macro
#if (ARDUINO >= 100)
#define OS_WRITE(X) Wire.write(X)
#define OS_READ() Wire.read()
#else
#define OS_WRITE(X) Wire.send(X)
#define OS_READ() Wire.recieve()
#endif
class OpenServo
{
public:
OpenServo(int address);
void setPosition(int pos);
unsigned int getPosition();
void enable();
void disable();
private:
//Wire _wire;
int _address;
//uint8_t _reverseSeek;
void _OpenServoWrite16(uint8_t reg, int data);
unsigned int _OpenServoRead16(uint8_t reg);
void _OpenServoCommand8(uint8_t reg);
void _OpenServoTransactionInit(uint8_t reg);
};
#endif