PCA9532 I2C LED Dimmer. Library files only, no mbed.lib or main.cpp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCA9532.h Source File

PCA9532.h

00001 /* mbed PCF9532 LED Driver Library
00002  *
00003  * Copyright (c) 2010, cstyles (http://mbed.org)
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  */
00023 
00024 #ifndef PCA9532_H
00025 #define PCA9532_H
00026 
00027 #include "mbed.h"
00028 
00029 /*
00030  * register names
00031  */
00032  
00033 #define PCA9532_REG_INPUT0 0
00034 #define PCA9532_REG_INPUT1 1
00035 #define PCA9532_REG_PSC0   2
00036 #define PCA9532_REG_PWM0   3
00037 #define PCA9532_REG_PSC1   4
00038 #define PCA9532_REG_PWM1   5
00039 #define PCA9532_REG_LS0    6
00040 #define PCA9532_REG_LS1    7
00041 #define PCA9532_REG_LS2    8
00042 #define PCA9532_REG_LS3    9
00043 
00044 /*
00045  LED modes
00046  */
00047  
00048 #define MODE_OFF  0
00049 #define MODE_ON   1
00050 #define MODE_PWM0 2
00051 #define MODE_PWM1 3
00052 
00053 class PCA9532 {
00054 
00055 public:
00056 
00057     /*
00058      * Constructor
00059      * Pass the I2C pins being used, and the address
00060      * The address bottom bit will be replaced by R/W bit
00061      */
00062     PCA9532(PinName sda, PinName scl, int addr);
00063 
00064     /*
00065      * SetLed(int led, int mode)
00066      * Set the  LED (0-15) into the specified mode (0-3) (OFF, On, PWM0, PWM1)
00067      */
00068     int SetLed  (int led, int mode);
00069 
00070     /*
00071      * SetMode(int mask, int mode)
00072      * Set the LED specified in the mask to the given mode
00073      */     
00074     int SetMode (int mask, int mode);
00075 
00076     /*
00077      * SetDuty(int channel, float duty)
00078      * Set the duty cycle (0.0-1.0) of the specified PWM channel (0|1)
00079      */     
00080     int Duty (int channel, float duty);
00081 
00082     /*
00083      * SetPeriod(int channel, float duty)
00084      * Set the period (0.0-1.0) of the specified PWM channel (0|1)
00085      */     
00086     int Period (int channel, float period);
00087 
00088 protected:
00089 
00090     void _write(int reg, int data);
00091     int _read(int reg);
00092     int _addr;
00093     I2C _i2c;
00094 
00095 };
00096 
00097 
00098 #endif