This is a library for our Adafruit 16-channel PWM & Servo driver Pick one up today in the adafruit shop! ------> http://www.adafruit.com/products/815 These displays use I2C to communicate, 2 pins are required to interface. Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, check license.txt for more information All text above must be included in any redistribution
Adafruit_PWMServoDriver.h@0:ed0c8a6481fd, 2013-08-17 (annotated)
- Committer:
- bxd
- Date:
- Sat Aug 17 06:59:05 2013 +0000
- Revision:
- 0:ed0c8a6481fd
Version 0, untested.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bxd | 0:ed0c8a6481fd | 1 | /*************************************************** |
bxd | 0:ed0c8a6481fd | 2 | This is a library for our Adafruit 16-channel PWM & Servo driver |
bxd | 0:ed0c8a6481fd | 3 | |
bxd | 0:ed0c8a6481fd | 4 | Pick one up today in the adafruit shop! |
bxd | 0:ed0c8a6481fd | 5 | ------> http://www.adafruit.com/products/815 |
bxd | 0:ed0c8a6481fd | 6 | |
bxd | 0:ed0c8a6481fd | 7 | These displays use I2C to communicate, 2 pins are required to |
bxd | 0:ed0c8a6481fd | 8 | interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4 |
bxd | 0:ed0c8a6481fd | 9 | |
bxd | 0:ed0c8a6481fd | 10 | Adafruit invests time and resources providing this open source code, |
bxd | 0:ed0c8a6481fd | 11 | please support Adafruit and open-source hardware by purchasing |
bxd | 0:ed0c8a6481fd | 12 | products from Adafruit! |
bxd | 0:ed0c8a6481fd | 13 | |
bxd | 0:ed0c8a6481fd | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. |
bxd | 0:ed0c8a6481fd | 15 | BSD license, all text above must be included in any redistribution |
bxd | 0:ed0c8a6481fd | 16 | |
bxd | 0:ed0c8a6481fd | 17 | Ported to mbed by Brian Dickman, mbed.org user bxd. |
bxd | 0:ed0c8a6481fd | 18 | |
bxd | 0:ed0c8a6481fd | 19 | Note: you are responsible for creating the I2C object, and setting |
bxd | 0:ed0c8a6481fd | 20 | frequency if desired. |
bxd | 0:ed0c8a6481fd | 21 | ****************************************************/ |
bxd | 0:ed0c8a6481fd | 22 | |
bxd | 0:ed0c8a6481fd | 23 | #ifndef _ADAFRUIT_PWMServoDriver_H |
bxd | 0:ed0c8a6481fd | 24 | #define _ADAFRUIT_PWMServoDriver_H |
bxd | 0:ed0c8a6481fd | 25 | |
bxd | 0:ed0c8a6481fd | 26 | #include "mbed.h" |
bxd | 0:ed0c8a6481fd | 27 | |
bxd | 0:ed0c8a6481fd | 28 | |
bxd | 0:ed0c8a6481fd | 29 | #define PCA9685_SUBADR1 0x2 |
bxd | 0:ed0c8a6481fd | 30 | #define PCA9685_SUBADR2 0x3 |
bxd | 0:ed0c8a6481fd | 31 | #define PCA9685_SUBADR3 0x4 |
bxd | 0:ed0c8a6481fd | 32 | |
bxd | 0:ed0c8a6481fd | 33 | #define PCA9685_MODE1 0x0 |
bxd | 0:ed0c8a6481fd | 34 | #define PCA9685_PRESCALE 0xFE |
bxd | 0:ed0c8a6481fd | 35 | |
bxd | 0:ed0c8a6481fd | 36 | #define LED0_ON_L 0x6 |
bxd | 0:ed0c8a6481fd | 37 | #define LED0_ON_H 0x7 |
bxd | 0:ed0c8a6481fd | 38 | #define LED0_OFF_L 0x8 |
bxd | 0:ed0c8a6481fd | 39 | #define LED0_OFF_H 0x9 |
bxd | 0:ed0c8a6481fd | 40 | |
bxd | 0:ed0c8a6481fd | 41 | #define ALLLED_ON_L 0xFA |
bxd | 0:ed0c8a6481fd | 42 | #define ALLLED_ON_H 0xFB |
bxd | 0:ed0c8a6481fd | 43 | #define ALLLED_OFF_L 0xFC |
bxd | 0:ed0c8a6481fd | 44 | #define ALLLED_OFF_H 0xFD |
bxd | 0:ed0c8a6481fd | 45 | |
bxd | 0:ed0c8a6481fd | 46 | |
bxd | 0:ed0c8a6481fd | 47 | class Adafruit_PWMServoDriver { |
bxd | 0:ed0c8a6481fd | 48 | public: |
bxd | 0:ed0c8a6481fd | 49 | Adafruit_PWMServoDriver(I2C *i2c, uint8_t addr = 0x40); |
bxd | 0:ed0c8a6481fd | 50 | void begin(void); |
bxd | 0:ed0c8a6481fd | 51 | void reset(void); |
bxd | 0:ed0c8a6481fd | 52 | void setPWMFreq(float freq); |
bxd | 0:ed0c8a6481fd | 53 | void setPWM(uint8_t num, uint16_t on, uint16_t off); |
bxd | 0:ed0c8a6481fd | 54 | |
bxd | 0:ed0c8a6481fd | 55 | private: |
bxd | 0:ed0c8a6481fd | 56 | I2C *_i2c; |
bxd | 0:ed0c8a6481fd | 57 | uint8_t _i2caddr; |
bxd | 0:ed0c8a6481fd | 58 | |
bxd | 0:ed0c8a6481fd | 59 | uint8_t read8(uint8_t addr); |
bxd | 0:ed0c8a6481fd | 60 | void write8(uint8_t addr, uint8_t d); |
bxd | 0:ed0c8a6481fd | 61 | }; |
bxd | 0:ed0c8a6481fd | 62 | |
bxd | 0:ed0c8a6481fd | 63 | #endif |