Show Posts
Pages: [1]
1  Using Arduino / LEDs and Multiplexing / Re: TLC5940 with adjustable speed, help on: October 08, 2012, 12:10:32 pm
I'm working on adding additional patterns to this and changing them by pushing a button, and still keep the pot, but one thing that I'll need to change is this:
Code:
void loop()
{
  ledSpeed = analogRead(potPin);
  if ((millis() - changeTime) > ledSpeed) {
    changeLights();
    changeTime = millis();
 }
}
The changeLights() part in the above, how would I change this and where would I put it so that turning the pot changes speed on all patterns?  In other words, if my first pattern looks like this:
Code:
void changeLights(){
  static int dir = 1;
  static int channel = 1;

     Tlc.clear();
     if (channel == 1) dir = 1;
     if (channel == 14) dir = -1;
     Tlc.set(channel - 1, 1000);
     Tlc.set(channel, 4095);
     Tlc.set(channel + 1, 1000);
     Tlc.update();
    channel += dir;
}
Would that part to change speed still be in the loop section, or would it be in the void changeLights() section?
2  Using Arduino / LEDs and Multiplexing / Re: TLC5940 with adjustable speed, help on: September 27, 2012, 03:33:19 pm
Also that function will take a certain amount of time to run, if your delay is shorter than this then you won't see any change in speed. To gt round this add a fixed number to your analogue input reading.

I tried this but I'm guessing it's not what you meant, because it didn't seem to be any different:
Code:
int ledSpeed = 100;  // speed of led chase
3  Using Arduino / LEDs and Multiplexing / Re: TLC5940 with adjustable speed, help on: September 27, 2012, 07:40:19 am
Thanks Mike, it's working now.  There is one minor issue though.  When I turn the pot, most of the speed changes happen at the end of the pot that makes it go fastest rather than gradually and evenly change speed.  How can I fix this?  I am using a B100K pot.
4  Using Arduino / LEDs and Multiplexing / Re: TLC5940 with adjustable speed, help on: September 26, 2012, 10:03:31 am
It is your 'for' statement that is doing this. Remove it and replace it with a structure that only changes one of the light states any time it is entered. To do this you need a  'state variable' one that shows where you are up to in your sequence. You used the loop variable i for this but now you no longer have a for loop you will have to replace it with a variable you declare as static in the loop function.
A static variable is one that is initialised only once the first time it is encountered and after that it's value remains the same.

Is there an example of this?  I searched but didn't see anything that might help.  I may have missed something though.
5  Using Arduino / LEDs and Multiplexing / Re: TLC5940 with adjustable speed, help on: September 25, 2012, 08:29:07 am
Tried this, but it still reacts the same way:

Code:
#include "Tlc5940.h"

int potPin = 0;  // pot to change speed
int ledSpeed;  // speed of led chase
unsigned long changeTime;

void setup()
{
  changeTime = millis();
  Tlc.init();
}

void loop()
{
  ledSpeed = analogRead(potPin);
  if ((millis() - changeTime) > ledSpeed) {
    changeLights();
    changeTime = millis();
 }
}

void changeLights(){
  int direction = 1;
  for (int channel = 0; channel < NUM_TLCS * 12; channel += direction) {
    Tlc.clear();
    if (channel == 0) {
      direction = 1;
    } else {
      Tlc.set(channel - 1, 1000);
    }
    Tlc.set(channel, 4095);
    if (channel != NUM_TLCS * 12 - 1) {
      Tlc.set(channel + 1, 1000);
    } else {
      direction = -1;
    }
    Tlc.update();
 }
}
6  Using Arduino / LEDs and Multiplexing / Re: TLC5940 with adjustable speed, help on: September 21, 2012, 08:13:37 am
Revised code is below, but it didn't change anything, the LEDs still flash rapidly and turning the pot does nothing.

Code:
#include "Tlc5940.h"

int potPin = 0;  // pot to change speed
int ledSpeed;  // speed of led chase
unsigned long changeTime;

void setup()
{
  changeTime = millis();
  Tlc.init();
}

void loop()
{
  if ((millis() - changeTime) > ledSpeed) {
    changeTime = millis();
  ledSpeed = analogRead(potPin);
  int direction = 1;
  for (int channel = 0; channel < NUM_TLCS * 12; channel += direction) {
    Tlc.clear();
    if (channel == 0) {
      direction = 1;
    } else {
      Tlc.set(channel - 1, 1000);
    }
    Tlc.set(channel, 4095);
    if (channel != NUM_TLCS * 12 - 1) {
      Tlc.set(channel + 1, 1000);
    } else {
      direction = -1;
    }
    Tlc.update();
  }
 }
}
7  Using Arduino / LEDs and Multiplexing / TLC5940 with adjustable speed, help on: September 19, 2012, 03:08:38 am
I am using Arduino Duemilanove with two TLC5940's hooked up to 24 LEDs.  I modified the Basic Use (Knight Rider) example slightly to the following:

Code:
#include "Tlc5940.h"

void setup()
{
  Tlc.init();
}

void loop()
{
  int direction = 1;
  for (int channel = 0; channel < NUM_TLCS * 12; channel += direction) {
    Tlc.clear();
    if (channel == 0) {
      direction = 1;
    } else {
      Tlc.set(channel - 1, 1000);
    }
    Tlc.set(channel, 4095);
    if (channel != NUM_TLCS * 12 - 1) {
      Tlc.set(channel + 1, 1000);
    } else {
      direction = -1;
    }
    Tlc.update();
    delay(75);
  }
}

It works fine, but I want to add a pot to change the speed without using delay.  Here's what I came up with:

Code:
#include "Tlc5940.h"

int potPin = 0;  // pot to change speed
int ledSpeed;  // speed of led chase
unsigned long changeTime;

void setup()
{
  Tlc.init();
}

void loop()
{
  ledSpeed = analogRead(potPin);
  int direction = 1;
  for (int channel = 0; channel < NUM_TLCS * 12; channel += direction) {
    Tlc.clear();
    if (channel == 0) {
      direction = 1;
    } else {
      Tlc.set(channel - 1, 1000);
    }
    Tlc.set(channel, 4095);
    if (channel != NUM_TLCS * 12 - 1) {
      Tlc.set(channel + 1, 1000);
    } else {
      direction = -1;
    }
    Tlc.update();
    if ((millis() - changeTime) > ledSpeed) {
    changeTime = millis();
  }
 }
}

When I upload and run this, the LEDs just flash very quickly and the pot doesn't do anything when turned. 
Pages: [1]