adafruit TLC5947 and SAM D21 Library
adafruit TLC5947 and SAM D21 Xplained pro Library
adafruit offered a good breakout based on TLC5947 chip , you can find it from here
adafruit "as always" offer a decent library to control TLC5947 using arduino , you can check it out from here
but if you are like me and you want to control it using Atmel studio and ASF4 , so you need to write the code by your self.
so I decided to re-write the adafruit library to work with Atmel studio and with any xplained pro series board
first you need to go to atmel start and setup your own configuration , I did it for you if you have SAMD21 Xplained pro board, you will find the atmel start project in my github.
then you need to import the library to your project , to do that go to the project solution explorer , right click on the project and select add then select an existing file and select adafruit_TLC5947 .h and adafruit_TLC5947 .c
connection :
you can change the connection depend on your board and application , for my example code the connection will be :
clk >> pb07
din >> pb06
lat >> pb03
OE >> pb02
now all you need is to include the library to your main file using
#include <Adafruit_TLC5947.h>
and here's the library reference , if you are familiar with adafruit's library so it will not be that difficult to you to understand it
- void setTLC5947(uint16_t n,uint16_t clk,uint16_t data,uint16_t latch,uint16_t Blink);
set the pins that you want to use it to control TLC5947
where:
n: number of device you have .
clk: clock pin .
data : data input (din) pin .
latch: lat pin .
Blink: enable pin (OE).
- bool tlc5947_begin(void);
start the tlc5947
- void tlc5947_setPWM(uint16_t chan, uint16_t pwm);
set the pwm value for a specific channel
where
chan : number of channel (0-23)
pwm : pwm value (from 0 - 4095)
- void tlc5947_setLED(uint16_t lednum, uint16_t r, uint16_t g, uint16_t b);
control an RGB led using this command , remember you need to have a common anode RGB led
where
lednum : the led number you want to control(0-7)
r : red color value(0-4095);
g : green color value(0-4095);
b : blue color value(0-4095);
- void tlc5947_write(void);
update the values to TLC5947 , you need to call it everytime you want to change the LED /PWM output.
- void tlc5947_enable(bool en);
enable / disable the device
en = true : enable the device output
en = false: disable the device output
hint: I recommended you to disable the device before update the values using (tlc5947_write)and then enable it , that's will eliminate any led flicker
example :
tlc5947_enable(false);
tlc5947_write();
tlc5947_enable(true);
and finally , here's some photos and videos for the library test
Post a Comment