Library for 16 channel PWM servo driver PCA9685. v2
Fork of Adafruit-PWM-Servo-Driver by
Adafruit_PWMServoDriver.h@0:9d01b5d37adc, 2013-08-17 (annotated)
- Committer:
- syundo0730
- Date:
- Sat Aug 17 09:01:33 2013 +0000
- Revision:
- 0:9d01b5d37adc
- Child:
- 1:69033d5e289b
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
syundo0730 | 0:9d01b5d37adc | 1 | /*************************************************** |
syundo0730 | 0:9d01b5d37adc | 2 | This is a library for our Adafruit 16-channel PWM & Servo driver |
syundo0730 | 0:9d01b5d37adc | 3 | |
syundo0730 | 0:9d01b5d37adc | 4 | Pick one up today in the adafruit shop! |
syundo0730 | 0:9d01b5d37adc | 5 | ------> http://www.adafruit.com/products/815 |
syundo0730 | 0:9d01b5d37adc | 6 | |
syundo0730 | 0:9d01b5d37adc | 7 | These displays use I2C to communicate, 2 pins are required to |
syundo0730 | 0:9d01b5d37adc | 8 | interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4 |
syundo0730 | 0:9d01b5d37adc | 9 | |
syundo0730 | 0:9d01b5d37adc | 10 | Adafruit invests time and resources providing this open source code, |
syundo0730 | 0:9d01b5d37adc | 11 | please support Adafruit and open-source hardware by purchasing |
syundo0730 | 0:9d01b5d37adc | 12 | products from Adafruit! |
syundo0730 | 0:9d01b5d37adc | 13 | |
syundo0730 | 0:9d01b5d37adc | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. |
syundo0730 | 0:9d01b5d37adc | 15 | BSD license, all text above must be included in any redistribution |
syundo0730 | 0:9d01b5d37adc | 16 | ****************************************************/ |
syundo0730 | 0:9d01b5d37adc | 17 | |
syundo0730 | 0:9d01b5d37adc | 18 | /***************************** |
syundo0730 | 0:9d01b5d37adc | 19 | This program was ported from https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library. |
syundo0730 | 0:9d01b5d37adc | 20 | I also added some functions. |
syundo0730 | 0:9d01b5d37adc | 21 | Shundo Kishi |
syundo0730 | 0:9d01b5d37adc | 22 | *****************************/ |
syundo0730 | 0:9d01b5d37adc | 23 | |
syundo0730 | 0:9d01b5d37adc | 24 | #ifndef _ADAFRUIT_PWMServoDriver_H |
syundo0730 | 0:9d01b5d37adc | 25 | #define _ADAFRUIT_PWMServoDriver_H |
syundo0730 | 0:9d01b5d37adc | 26 | |
syundo0730 | 0:9d01b5d37adc | 27 | #include "mbed.h" |
syundo0730 | 0:9d01b5d37adc | 28 | #include <cmath> |
syundo0730 | 0:9d01b5d37adc | 29 | |
syundo0730 | 0:9d01b5d37adc | 30 | #define PCA9685_SUBADR1 0x2 |
syundo0730 | 0:9d01b5d37adc | 31 | #define PCA9685_SUBADR2 0x3 |
syundo0730 | 0:9d01b5d37adc | 32 | #define PCA9685_SUBADR3 0x4 |
syundo0730 | 0:9d01b5d37adc | 33 | |
syundo0730 | 0:9d01b5d37adc | 34 | #define PCA9685_MODE1 0x0 |
syundo0730 | 0:9d01b5d37adc | 35 | #define PCA9685_PRESCALE 0xFE |
syundo0730 | 0:9d01b5d37adc | 36 | |
syundo0730 | 0:9d01b5d37adc | 37 | #define LED0_ON_L 0x6 |
syundo0730 | 0:9d01b5d37adc | 38 | #define LED0_ON_H 0x7 |
syundo0730 | 0:9d01b5d37adc | 39 | #define LED0_OFF_L 0x8 |
syundo0730 | 0:9d01b5d37adc | 40 | #define LED0_OFF_H 0x9 |
syundo0730 | 0:9d01b5d37adc | 41 | |
syundo0730 | 0:9d01b5d37adc | 42 | #define ALLLED_ON_L 0xFA |
syundo0730 | 0:9d01b5d37adc | 43 | #define ALLLED_ON_H 0xFB |
syundo0730 | 0:9d01b5d37adc | 44 | #define ALLLED_OFF_L 0xFC |
syundo0730 | 0:9d01b5d37adc | 45 | #define ALLLED_OFF_H 0xFD |
syundo0730 | 0:9d01b5d37adc | 46 | |
syundo0730 | 0:9d01b5d37adc | 47 | |
syundo0730 | 0:9d01b5d37adc | 48 | class Adafruit_PWMServoDriver { |
syundo0730 | 0:9d01b5d37adc | 49 | public: |
syundo0730 | 0:9d01b5d37adc | 50 | Adafruit_PWMServoDriver(PinName sda, PinName scl, int addr = 0x80); //0b 1_000000_(R/W) <- default slave adress |
syundo0730 | 0:9d01b5d37adc | 51 | void i2c_probe(void); |
syundo0730 | 0:9d01b5d37adc | 52 | void begin(void); |
syundo0730 | 0:9d01b5d37adc | 53 | void setI2Cfreq(int freq); |
syundo0730 | 0:9d01b5d37adc | 54 | void reset(void); |
syundo0730 | 0:9d01b5d37adc | 55 | void setPWMFreq(float freq); |
syundo0730 | 0:9d01b5d37adc | 56 | void setPrescale(uint8_t prescale); |
syundo0730 | 0:9d01b5d37adc | 57 | void setPWM(uint8_t num, uint16_t on, uint16_t off); |
syundo0730 | 0:9d01b5d37adc | 58 | |
syundo0730 | 0:9d01b5d37adc | 59 | private: |
syundo0730 | 0:9d01b5d37adc | 60 | int _i2caddr; |
syundo0730 | 0:9d01b5d37adc | 61 | I2C i2c; |
syundo0730 | 0:9d01b5d37adc | 62 | |
syundo0730 | 0:9d01b5d37adc | 63 | uint8_t read8(char addr); |
syundo0730 | 0:9d01b5d37adc | 64 | void write8(char addr, char d); |
syundo0730 | 0:9d01b5d37adc | 65 | }; |
syundo0730 | 0:9d01b5d37adc | 66 | |
syundo0730 | 0:9d01b5d37adc | 67 | #endif |