TLC5940 Fadescope - variation


I’m trying to figure out how to modify the Fadescope example sketch that comes with the TLC5940 library, so that it fades random LEDs on and off, instead of running down the line sequentially. This is the code for the example sketch:

    A simple 1-d oscilliscope: scan all the channels, setting the PWM output
    value to 4x the analog pin 0 value (0 - 1024 * 4 = 4096).  The value will
    fade to zero as the channels keep scanning.

    See the BasicUse example for hardware setup.

    Alex Leone <acleone ~AT~>, 2009-02-03 */

#include "Tlc5940.h"
#include "tlc_fades.h"

// which analog pin to use
#define ANALOG_PIN      0

// how many millis to strobe over all the LEDs
#define SCOPE_PERIOD    (1000 * NUM_TLCS)
#define LED_PERIOD      SCOPE_PERIOD / (NUM_TLCS * 16)


void setup()

void loop()
  uint32_t lastMillis = millis();
  tlc_addFade(channel,                      // led channel
              analogRead(ANALOG_PIN) * 4,   // start fade value (0-4095)
              0,                            // end fade value (0-4095)
              lastMillis + 2,               // start millis
              lastMillis + (uint16_t)SCOPE_PERIOD / 4  // end millis
  if (channel++ == NUM_TLCS * 16) {
    channel = 0;
  uint32_t currentMillis;
  do {
    currentMillis = millis();
  } while (currentMillis - lastMillis <= LED_PERIOD);

Obviously it’s updating the channel variable with a random value, from 0 - 32 (I have two TLC5940’s daisy-chained) but what should be a simple change has me stumped.

Any help appreciated!

Remove these lines:-

if (channel++ == NUM_TLCS * 16) {
    channel = 0;

Replace them with

channel = random(31);

Add in the start up function

randomSeed(analogRead(1)); // you should have nothing connected to this

Thanks, that's exactly what I needed after a late night of soldering and coding something new!

Hi All,
I am also trying to adapt the FadeScope example to a project, but not having much luck getting it up and running with my modifications.

I would like to change “TLC_CHANNEL_TYPE channel;” in some way or form, instead of reading all pins, I would like to have an array to cycle through only chosen pins and not necessarily all pins.

Thanks for any advice and a merry Xmas