Go Down

Topic: TLC5940 Animations (Read 1 time) previous topic - next topic

Demonic69

Hi, I just thought I'd share a couple of simple animations I'm working on for my - soon to be born - son's bedroom light.
It's an 8x4 grid at the minute but could be expanded easily enough.
I'll be testing the animations tonight to see if they do as expected. Any suggestions on improving them would be greatly appreciated.
I think there must be a way to set the number of rows and columns so the animations could be a bit more dynamic.
It would be great if others could add to this, we could end up with a nice set of animations for simple projects.
These are written as functions and called from the main script.
The 1st is just a modification of the basic use script written by Alex Leone to run over 4 columns.
Code: [Select]
// Function to to send a wave effect up a 4*8 grid of LEDs, similar to the knight rider but using 4 columns

#ifndef TLC_WAVE_FUNCTION_H
#define TLC_WAVE_FUNCTION_H

#include "tlc_config.h"
#include "Tlc5940.h"
#include "Arduino.h"

void tlc_wave(void);

void tlc_wave(void) {
  int direction = 1;
  int c1[] = {
    0, 1, 2, 3, 4, 5, 6, 7  }; // Column 1
  int c2[] = {
    8, 9, 10, 11, 12, 13, 14, 15  }; // Column 2
  int c3[] = {
    16, 17, 18, 19, 20, 21, 22, 23  }; // Column 3
  int c4[] = {
    24, 25, 26, 27, 28, 29, 30, 31  }; // Column 4 Add more columns with matching values if required
  int edge = 1000; // I light all mine up at once, then dim the wave
  int cent = 0; // Centre of wave off
  int norm = 4000; // normal setting for LEDs, 0 if you're lightng the wave, 4000 if your're dimming it
  int rows = 8;

  for (int channel = 0; channel < rows; channel += direction) {

    /* Tlc.setAll() sets all the grayscale values to norm, but does not send
     them to the TLCs.  To actually send the data, call Tlc.update() */
    Tlc.setAll(norm);

    /* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for
     one channel (15 is OUT15 on the first TLC, if multiple TLCs are daisy-
     chained, then channel = 16 would be OUT0 of the second TLC, etc.).
     
     value goes from off (0) to always on (4095).
     
     Like Tlc.clear(), this function only sets up the data, Tlc.update()
     will send the data. */
    if (channel == 0) {
      direction = 1;
    }
    else {
      Tlc.set(c1[channel - 1], edge);
      Tlc.set(c2[channel - 1], edge);
      Tlc.set(c3[channel - 1], edge);
      Tlc.set(c4[channel - 1], edge);
    }
    Tlc.set(c1[channel], cent);
    Tlc.set(c2[channel], cent);
    Tlc.set(c3[channel], cent);
    Tlc.set(c4[channel], cent);
    if (channel != rows - 1) {
      Tlc.set(c1[channel + 1], edge);
      Tlc.set(c2[channel + 1], edge);
      Tlc.set(c3[channel + 1], edge);
      Tlc.set(c4[channel + 1], edge);
    }
    else {
      direction = -1;
    }

    /* Tlc.update() sends the data to the TLCs.  This is when the LEDs will
     actually change. */
    Tlc.update();

    delay(75);
  }

}

#endif


The next will dim a random LED from each column:
Code: [Select]
// Function to randomly dim 1 LED from each Column

#ifndef TLC_RANDOMDIM_FUNCTION_H
#define TLC_RANDOMDIM_FUNCTION_H

#include "tlc_config.h"
#include "Tlc5940.h"
#include "Arduino.h"

void tlc_RandomDim(void);

void tlc_RandomDim(void)
{
  int i;
  long randled1 = random(0, 7);
  long randled2 = random(8, 15);
  long randled3 = random(16, 23);
  long randled4 = random(24, 31);

  for (i=4000; i > 0; i = i - 1){
    Tlc.setAll(4000);
    Tlc.set(randled1, i);
    Tlc.set(randled2, i);
    Tlc.set(randled3, i);
    Tlc.set(randled4, i);
    Tlc.update();
  }
  for (i=0; i < 4000; i = i + 1){
    Tlc.setAll(4000);
    Tlc.set(randled1, i);
    Tlc.set(randled2, i);
    Tlc.set(randled3, i);
    Tlc.set(randled4, i);
    Tlc.update();
  }
}

#endif

Go Up