16-channel I2C constant current LED sink driver

Fork of TLC59116 by Sille Van Landschoot

Committer:
sillevl
Date:
Thu Dec 03 07:57:50 2015 +0000
Revision:
0:52a1996ad711
Child:
1:c285b2c57b2e
initial commit

Who changed what in which revision?

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