Skip to content

Instantly share code, notes, and snippets.

@TAUTIC
Created November 9, 2012 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TAUTIC/4048414 to your computer and use it in GitHub Desktop.
Save TAUTIC/4048414 to your computer and use it in GitHub Desktop.
TLC59282 Demo
/* TLC59282 Demo - See it in action here: http://youtu.be/REM6bI637JQ?hd=1
Copyright (c) 2012 Jayson Tautic - TAUTIC ELECTRONICS LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
const int sinPin = 4;
const int sclkPin = 5;
const int latPin = 6;
const int blankPin = 7;
void setup() {
pinMode(sinPin, OUTPUT);
pinMode(sclkPin, OUTPUT);
pinMode(latPin, OUTPUT);
pinMode(blankPin, OUTPUT);
//Set some pin defaults.
digitalWrite(blankPin, HIGH); //Turn off all outputs on TLC59282
digitalWrite(latPin, LOW);
digitalWrite(sclkPin, LOW);
digitalWrite(sinPin, LOW);
}
void loop() {
for (long y = 0; y < 0xFFFF; y++) {
writeTLC(y); //Send to the chip
delay(10); //wait .01 seconds - if we cycle too quickly, the LEDs wont get to full brightness
}
}
//We will handle all of our writing to the TLC59282 inside of this function.
void writeTLC(long val) {
//First we pulse the LAT pin
digitalWrite(latPin, HIGH);
digitalWrite(latPin, LOW);
//take BLANK pin low during the write
digitalWrite(blankPin, HIGH);
//Loop through the long and output the data to the TLC59282
for (int x=0; x < 16; x++) {
if (CHECK_BIT(val, x)) digitalWrite(sinPin, HIGH);
else digitalWrite(sinPin, LOW);
digitalWrite(sclkPin, HIGH);
digitalWrite(sclkPin, LOW);
}
//BLANK goes low again to enable the outputs
digitalWrite(blankPin, LOW);
//Last, pulse LAT pin once more.
digitalWrite(latPin, HIGH);
digitalWrite(latPin, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment