16-channel I2C constant current LED sink driver

Fork of TLC59116 by Sille Van Landschoot

Committer:
sillevl
Date:
Sat Dec 19 10:41:07 2015 +0000
Revision:
1:c285b2c57b2e
Parent:
0:52a1996ad711
Child:
2:daabe2fe9b1d
add constructor that accepts I2C object

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 0:52a1996ad711 1 #include "TLC59116.h"
sillevl 0:52a1996ad711 2
sillevl 1:c285b2c57b2e 3 TLC59116::TLC59116(I2C &_i2c, int _address): i2c(_i2c), address(_address)
sillevl 1:c285b2c57b2e 4 {
sillevl 1:c285b2c57b2e 5 initialize();
sillevl 1:c285b2c57b2e 6 }
sillevl 0:52a1996ad711 7
sillevl 0:52a1996ad711 8 TLC59116::TLC59116(PinName sda, PinName scl, int _address): i2c(sda, scl), address(_address)
sillevl 0:52a1996ad711 9 {
sillevl 1:c285b2c57b2e 10 initialize();
sillevl 1:c285b2c57b2e 11 }
sillevl 1:c285b2c57b2e 12
sillevl 1:c285b2c57b2e 13 void TLC59116::initialize()
sillevl 1:c285b2c57b2e 14 {
sillevl 0:52a1996ad711 15 // oscillator set to normal mode
sillevl 0:52a1996ad711 16 enable();
sillevl 0:52a1996ad711 17 // enable individual brightness and group dimming
sillevl 0:52a1996ad711 18 setOutputState(0xFF,0xFF,0xFF,0xFF);
sillevl 0:52a1996ad711 19 }
sillevl 0:52a1996ad711 20
sillevl 0:52a1996ad711 21 void TLC59116::enable()
sillevl 0:52a1996ad711 22 {
sillevl 0:52a1996ad711 23 // should readout register state first
sillevl 0:52a1996ad711 24 setRegister(0,0);
sillevl 0:52a1996ad711 25 }
sillevl 0:52a1996ad711 26
sillevl 0:52a1996ad711 27 void TLC59116::disable()
sillevl 0:52a1996ad711 28 {
sillevl 0:52a1996ad711 29 // should readout register state first
sillevl 0:52a1996ad711 30 setRegister(0,1 << 4);
sillevl 0:52a1996ad711 31 }
sillevl 0:52a1996ad711 32
sillevl 0:52a1996ad711 33 void TLC59116::setOutputState(int ledout0, int ledout1, int ledout2, int ledout3)
sillevl 0:52a1996ad711 34 {
sillevl 0:52a1996ad711 35 setRegister(0x14,ledout0);
sillevl 0:52a1996ad711 36 setRegister(0x15,ledout1);
sillevl 0:52a1996ad711 37 setRegister(0x16,ledout2);
sillevl 0:52a1996ad711 38 setRegister(0x17,ledout3);
sillevl 0:52a1996ad711 39 }
sillevl 0:52a1996ad711 40
sillevl 0:52a1996ad711 41 void TLC59116::setChannel(int led, float brightness)
sillevl 0:52a1996ad711 42 {
sillevl 0:52a1996ad711 43 char data[] = {NO_AUTO_INCREMENT + 0x02 + led, brightness * 255.0};
sillevl 0:52a1996ad711 44 i2c.write(address, data, 2);
sillevl 0:52a1996ad711 45 }
sillevl 0:52a1996ad711 46
sillevl 0:52a1996ad711 47
sillevl 0:52a1996ad711 48 void TLC59116::setBrightness(float brightness)
sillevl 0:52a1996ad711 49 {
sillevl 0:52a1996ad711 50 setRegister(GRPPWM, brightness * 255.0);
sillevl 0:52a1996ad711 51 }
sillevl 0:52a1996ad711 52
sillevl 0:52a1996ad711 53 void TLC59116::setRegister(int reg, int value)
sillevl 0:52a1996ad711 54 {
sillevl 0:52a1996ad711 55 char data[] = {NO_AUTO_INCREMENT + reg, value};
sillevl 0:52a1996ad711 56 i2c.write(address, data, 2);
sillevl 0:52a1996ad711 57 }
sillevl 0:52a1996ad711 58
sillevl 0:52a1996ad711 59 void TLC59116::setRegisters(int reg, char* value, int length, int mode)
sillevl 0:52a1996ad711 60 {
sillevl 0:52a1996ad711 61 // not implemented yet
sillevl 0:52a1996ad711 62 }