Advertisement
Guest User

arduino led matrix

a guest
Jul 25th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include <Tlc5940.h>
  2. #include <Wire.h>
  3.  
  4. #define EXPANDER B0100000
  5.  
  6. static unsigned long timerDuration;
  7.  
  8. void setup(){
  9.   Tlc.init();
  10.   Wire.begin(EXPANDER);
  11.   timerDuration = micros() + 100;
  12. }
  13.  
  14. byte pattern[8][2] = {
  15.   {B10000011,B11001100},
  16.   {B10000010,B00001010},
  17.   {B10000010,B00001001},
  18.   {B10000010,B00001001},
  19.   {B10000011,B10001001},
  20.   {B10000010,B00001001},
  21.   {B10000010,B00001010},
  22.   {B11110011,B11001100}};
  23.  
  24. void loop(){
  25.   if((long)(micros() - timerDuration) >= 0){
  26.     timer_Tick();
  27.     timerDuration = micros() + 100;
  28.   }
  29. }
  30.  
  31. void sendByte(int adress, int data){
  32.   Wire.beginTransmission(EXPANDER);
  33.   Wire.write(data);
  34.   Wire.endTransmission();
  35. }
  36.  
  37. int counter = 0;
  38.  
  39. void timer_Tick(){
  40.   if(counter > 7){
  41.     counter = 0;
  42.   }
  43.  
  44.   sendByte(EXPANDER, 255);
  45.   Tlc.clear();
  46.  
  47.   for(int i = 0; i <= 1; i++){
  48.     for (byte pos = 0, mask = B10000000; mask > 0; mask >>= 1){
  49.       if (pattern[counter][i] & mask){
  50.         if(i == 0){
  51.           Tlc.set(pos, 4095);
  52.         }
  53.         else{
  54.           Tlc.set(pos + 8, 4095);
  55.         }
  56.       }
  57.       pos++;
  58.     }
  59.   }
  60.  
  61.   Tlc.update();
  62.   delay(1);
  63.   sendByte(EXPANDER, ~(1 << counter));
  64.  
  65.   counter++;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement