Library for 16 channel PWM servo driver PCA9685. v2

Dependents:   totoV1-2

Fork of Adafruit-PWM-Servo-Driver by Shundo Kishi

Committer:
fixair
Date:
Tue Nov 14 18:06:44 2017 +0000
Revision:
3:07497eda12c2
Parent:
1:69033d5e289b
test spd15

Who changed what in which revision?

UserRevisionLine numberNew 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:
fixair 3:07497eda12c2 50 //Adafruit_PWMServoDriver(PinName sda, PinName scl, int addr = 0x41); //0b 1_000000_(R/W) <- default slave adress
fixair 3:07497eda12c2 51 Adafruit_PWMServoDriver(PinName sda, PinName scl, int addr);
syundo0730 0:9d01b5d37adc 52 void i2c_probe(void);
syundo0730 0:9d01b5d37adc 53 void begin(void);
syundo0730 0:9d01b5d37adc 54 void setI2Cfreq(int freq);
syundo0730 0:9d01b5d37adc 55 void reset(void);
syundo0730 0:9d01b5d37adc 56 void setPWMFreq(float freq);
syundo0730 0:9d01b5d37adc 57 void setPrescale(uint8_t prescale);
syundo0730 0:9d01b5d37adc 58 void setPWM(uint8_t num, uint16_t on, uint16_t off);
syundo0730 1:69033d5e289b 59 void setDuty(uint8_t num, uint16_t duty);
syundo0730 0:9d01b5d37adc 60
syundo0730 0:9d01b5d37adc 61 private:
fixair 3:07497eda12c2 62 I2C *i2c;
syundo0730 0:9d01b5d37adc 63 int _i2caddr;
syundo0730 0:9d01b5d37adc 64
syundo0730 0:9d01b5d37adc 65 uint8_t read8(char addr);
syundo0730 0:9d01b5d37adc 66 void write8(char addr, char d);
syundo0730 0:9d01b5d37adc 67 };
syundo0730 0:9d01b5d37adc 68
syundo0730 0:9d01b5d37adc 69 #endif