Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more. Accepting essential orders - here's how.
0

RGB LEDs are very slow to change colors and affecting other
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RGB LEDs are very slow to change colors and affecting other

by nicnut on Wed Feb 19, 2020 10:21 pm

Hi,

I have been having a real hard time integrating this 24 channel 12 bit PWM LED driver into my project.

This product:

https://www.adafruit.com/product/1429

I made a video that will help a little bit. Here is a link:

https://www.youtube.com/watch?v=ApEM...ature=youtu.be

I will try again to explain what is going on, because it might be hard to tell from the video.

I am creating a MIDI controller. I have a Teensy 3.6. In the end it will have Analog sensors, Digital sensors, 4 Adafruit LED displays, like the ones in the video, and hopefully 17 RGB LEDs that are inside some button switches, that you can see in the video.

The RGB LEDs are connected to 2 PWM LED driver chained together.


Right now I have 5 RGB LEDs connected to 2 of these PWM LED boards that are chained together. Eventually I want to have 17 of them connected to 3 PWM LED boards.

I have been selecting USB type: MIDI when uploading my code in Arduino software. In the beginning of the video you can see that I am sending MIDI messages that are creating random musical pitches and they are triggering animations in the LED displays. This is working perfectly, the timing is perfectly in sync as far as I can see. While I am doing this the code that controls the RGB LEDs is not uploaded to the Teensy

These LED displays are connected to the SCL0 and the SDA0 pins on the Teensy.

When I upload the code that sends messages to the PWM LED driver it slows down the messages going to the LED displays that worked great before. And the messages going to the RGB LEDs are really slow, you can see in the 2nd half of the video that it takes a few seconds for them to respond to all their MIDI messages they have received to change colors. The PWM LED drivers are connected to:

#define data 28 //
#define clock 30
#define latch 29
#define oe -1 // not being used.

I don't want to upload all the code because it is so much, including all the different colors and all the LED animations. Also I don't have any analog or digital sensors connected right now. I'm just trying to get these LEDs and LED displays working, then I'll check the sensors after that.

If you want to see other parts of the code that I didn't upload let me know

Here are the libraries I'm using and the info for the LED driver


Code: Select all | TOGGLE FULL SIZE
    #include <Bounce.h>
    #include <Adafruit_NeoPixel.h>
    #include <Wire.h> // wire library for LED matrix

    #include "Adafruit_LEDBackpack.h"
    #include "Adafruit_GFX.h"

    #include "Adafruit_TLC5947.h"  // for LED breakout board

    // How many boards do you have chained?
    #define NUM_TLC5947 2       // how many breakout boards?

    #define data   28     // digital pins on the Teensy
    #define clock   30
    #define latch   29
    #define oe  -1  // set to -1 to not use the enable pin (its optional)  // for LED boards

    Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5947, clock, data, latch);


Here's my setup()


Code: Select all | TOGGLE FULL SIZE
   void setup() {

      //Serial.begin(9600);

     // Serial.println("TLC5947 test");     // commenting this out. Doesn't seem to matter if it's in or not.
      tlc.begin();
    //  if (oe >= 0) {
     //   pinMode(oe, OUTPUT);
      //  digitalWrite(oe, LOW);
      // }

      // wire 3.3V to AREF for 3.3V reference
      analogReference(DEFAULT);

      pinMode(0, INPUT_PULLUP);   // for button swithces
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
      pinMode(5, INPUT_PULLUP);
      pinMode(6, INPUT_PULLUP);
      pinMode(7, INPUT_PULLUP);
      pinMode(8, INPUT_PULLUP);
      pinMode(9, INPUT_PULLUP);
      pinMode(10, INPUT_PULLUP);
      pinMode(11, INPUT_PULLUP);
      pinMode(12, INPUT_PULLUP);
      pinMode(24, INPUT_PULLUP);
      pinMode(25, INPUT_PULLUP);
      pinMode(26, INPUT_PULLUP);
      pinMode(27, INPUT_PULLUP);

      // pinMode(ledPin28, OUTPUT);   // LED on digital pin 28
      // pinMode(ledPin29, OUTPUT);   // LED on digital pin 29
      // pinMode(ledPin30, OUTPUT);   // LED on digital pin 30
      // pinMode(ledPin31, OUTPUT);   // LED on digital pin 31
      // pinMode(ledPin32, OUTPUT);   // LED on digital pin 32
      // pinMode(ledPin33, OUTPUT);   // LED on digital pin 33

      usbMIDI.setHandleControlChange(myControlChange);
      setupLedDisplays();



    }



Here's my loop(). I noticed i have some variables in between setup() and Loop(), I included those.


Code: Select all | TOGGLE FULL SIZE
    // store previously sent values, to detect changes
    int previousA0 = -1;
    int previousA1 = -1;
    int previousA2 = -1;
    int previousA3 = -1;
    int previousA4 = -1;
    int previousA5 = -1;
    int previousA6 = -1;
    int previousA7 = -1;
    int previousA8 = -1;
    int previousA9 = -1;
    int previousA10 = -1;
    int previousA11 = -1;
    int previousA12 = -1;


    elapsedMillis msec = 0;



    void loop() {

      {

        button0.update();    //  this button code works, goes from 0 to 127 when pressed
        button1.update();
        button2.update();
        button3.update();
        button4.update();
        button5.update();
        button6.update();
        button7.update();
        button8.update();
        button9.update();
        button10.update();
        button11.update();
        button12.update();
        button24.update();
        button25.update();
        button26.update();
        button27.update();



        if (button0.fallingEdge()) {                               // this deals with reading the button swithces
          usbMIDI.sendControlChange(controllerD14, 127, channel);
        }

        if (button0.risingEdge()) {
          usbMIDI.sendControlChange(controllerD14, 0, channel);
        }

        if (button1.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD15, 127, channel);
        }

        if (button1.risingEdge()) {
          usbMIDI.sendControlChange(controllerD15, 0, channel);
        }

        if (button2.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD16, 127, channel);
        }

        if (button2.risingEdge()) {
          usbMIDI.sendControlChange(controllerD16, 0, channel);
        }

        if (button3.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD17, 127, channel);
        }

        if (button3.risingEdge()) {
          usbMIDI.sendControlChange(controllerD17, 0, channel);
        }

        if (button4.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD18, 127, channel);
        }

        if (button4.risingEdge()) {
          usbMIDI.sendControlChange(controllerD18, 0, channel);
        }

        if (button5.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD19, 127, channel);
        }

        if (button5.risingEdge()) {
          usbMIDI.sendControlChange(controllerD19, 0, channel);
        }

        if (button6.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD20, 127, channel);
        }

        if (button6.risingEdge()) {
          usbMIDI.sendControlChange(controllerD20, 0, channel);
        }

        if (button7.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD21, 127, channel);
        }

        if (button7.risingEdge()) {
          usbMIDI.sendControlChange(controllerD21, 0, channel);
        }

        if (button8.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD22, 127, channel);
        }

        if (button8.risingEdge()) {
          usbMIDI.sendControlChange(controllerD22, 0, channel);
        }

        if (button9.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD23, 127, channel);
        }

        if (button9.risingEdge()) {
          usbMIDI.sendControlChange(controllerD23, 0, channel);
        }

        if (button10.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD24, 127, channel);
        }

        if (button10.risingEdge()) {
          usbMIDI.sendControlChange(controllerD24, 0, channel);
        }

        if (button11.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD25, 127, channel);
        }

        if (button11.risingEdge()) {
          usbMIDI.sendControlChange(controllerD25, 0, channel);
        }

        if (button12.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD26, 127, channel);
        }

        if (button12.risingEdge()) {
          usbMIDI.sendControlChange(controllerD26, 0, channel);
        }

        if (button24.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD27, 127, channel);
        }

        if (button24.risingEdge()) {
          usbMIDI.sendControlChange(controllerD27, 0, channel);
        }

        /*

          if (button25.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD28, 127, channel);
          }

          if (button25.risingEdge()) {
          usbMIDI.sendControlChange(controllerD28, 0, channel);
          }

          if (button26.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD29, 127, channel);
          }

          if (button26.risingEdge()) {
          usbMIDI.sendControlChange(controllerD29, 0, channel);
          }

          if (button27.fallingEdge()) {
          usbMIDI.sendControlChange(controllerD30, 127, channel);
          }

          if (button27.risingEdge()) {
          usbMIDI.sendControlChange(controllerD30, 0, channel);
          }

        */

      }


      // only check the analog inputs 50 times per second,
      // to prevent a flood of MIDI messages
      if (msec >= 3) {               //  i changed this value to 10 from 20 for faster updates
        msec = 0;

        int n0 = map(analogRead(A0), 0, 1023, 0, 127);
        int n1 = map(analogRead(A1), 0, 1023, 0, 127);
        int n2 = map(analogRead(A2), 0, 1023, 0, 127);
        int n3 = map(analogRead(A3), 0, 1023, 0, 127);
        int n4 = map(analogRead(A4), 0, 1023, 0, 127);
        int n5 = map(analogRead(A5), 0, 1023, 0, 127);
        int n6 = map(analogRead(A6), 0, 1023, 0, 127);
        int n7 = map(analogRead(A7), 0, 1023, 0, 127);
        int n8 = map(analogRead(A8), 0, 1023, 0, 127);
        int n9 = map(analogRead(A9), 0, 1023, 0, 127);
        int n10 = map(analogRead(A14), 0, 1023, 0, 127);
        int n11 = map(analogRead(A15), 0, 1023, 0, 127);
        int n12 = map(analogRead(A16), 0, 1023, 0, 127);


        // only transmit MIDI messages if analog input changed
        if (n0 != previousA0) {
          previousA0 = n0;
          if (n0 < 2) n0 = 0;
          usbMIDI.sendControlChange(controllerA0, n0, channel);
        }

        if (n1 != previousA1) {
          previousA1 = n1;
          if (n1 < 2) n1 = 0;
          usbMIDI.sendControlChange(controllerA1, n1, channel);
        }

        if (n2 != previousA2) {
          previousA2 = n2;
          if (n2 < 2) n2 = 0;
          usbMIDI.sendControlChange(controllerA2, n2, channel);

        }
        if (n3 != previousA3) {
          previousA3 = n3;
          if (n3 < 2) n3 = 0;
          usbMIDI.sendControlChange(controllerA3, n3, channel);
        }

        if (n4 != previousA4) {
          previousA4 = n4;
          if (n4 < 2) n4 = 0;
          usbMIDI.sendControlChange(controllerA4, n4, channel);

        }

        if (n5 != previousA5) {
          previousA5 = n5;
          if (n5 < 2) n5 = 0;
          usbMIDI.sendControlChange(controllerA5, n5, channel);

        }

        if (n6 != previousA6) {
          previousA6 = n6;
          if (n6 < 2) n6 = 0;
          usbMIDI.sendControlChange(controllerA6, n6, channel);

        }

        if (n7 != previousA7) {
          previousA7 = n7;
          if (n7 < 2) n7 = 0;
          usbMIDI.sendControlChange(controllerA7, n7, channel);

        }

        if (n8 != previousA8) {
          previousA8 = n8;
          if (n8 < 2) n8 = 0;
          usbMIDI.sendControlChange(controllerA8, n8, channel);
        }

        if (n9 != previousA9) {
          previousA9 = n9;
          if (n9 < 3) n9 = 0;
          usbMIDI.sendControlChange(controllerA9, n9, channel);
        }

        if (n10 != previousA10) {
          previousA10 = n10;
          if (n10 < 3) n10 = 0;
          usbMIDI.sendControlChange(controllerA10, n10, channel);
        }

        if (n11 != previousA11) {
          previousA11 = n11;
          if (n11 < 3) n11 = 0;
          usbMIDI.sendControlChange(controllerA11, n11, channel);
        }

        if (n12 != previousA12) {
          previousA12 = n12;
          if (n12 < 3) n12 = 0;
          usbMIDI.sendControlChange(controllerA12, n12, channel);
        }



      }

      // MIDI Controllers should discard incoming MIDI messages.
      // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
      while (usbMIDI.read()) {
        // ignore incoming messages
      }
    }


Here's part of the code that controls or sends messages to change the RGB LED colors. I'm not going to include all of it, but you should get the idea.


Code: Select all | TOGGLE FULL SIZE
    void myControlChange(byte channel, byte control, byte value) // for LEDs, MIDI output

    {

      if (channel == MIDIchannel                 // going to try eliminating 2nd write
          && control == ledcontroller15
          && value == 0)


        tlc.setLED(0, 0, 0, 0);    //off
      tlc.write();
    //  tlc.write();


      if (channel == MIDIchannel
          && control == ledcontroller15
          && value == 10)


        tlc.setLED(0, 246, 84, 106);  //light pink
      tlc.write();
     // tlc.write();


      if (channel == MIDIchannel
          && control == ledcontroller15
          && value == 20)


        tlc.setLED(0, 0, 0, 255);        //blue
      tlc.write();
     // tlc.write();

      if (channel == MIDIchannel
          && control == ledcontroller15
          && value == 30)


        tlc.setLED(0, 90, 0, 255);        //lavender
      tlc.write();
     // tlc.write();



If you want to see other parts of the code let me know.

I already tried having the LED displays and the LED drivers on the same data and clock pins, but that didn't work.

Thank you and I hope this can get resolved.

Quick reply to this message

nicnut
 
Posts: 99
Joined: Thu Jun 23, 2011 12:17 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by adafruit_support_bill on Thu Feb 20, 2020 6:52 am

Hard to say looking at fragments. But one obvious optimization is to have only one "tlc.write();" at the end of the loop.

A further optimization would be to call it only if there has been a change.

adafruit_support_bill
 
Posts: 76695
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LEDs are very slow to change colors and affecting ot

by nicnut on Thu Feb 20, 2020 3:28 pm

I posted the same thing on the Teensy forum. Someone there said it's because the library to control this LED driver board uses software SPI, which, if I understand correctly, uses interupts that slow down the code. It would be better to use hardware SPI aparently.

Here is the thread. There is some good info there if anyone is having a similar issue:

https://forum.pjrc.com/threads/59605-Te ... post230540

There is also a library that might be a work around for this at: https://github.com/ramonaoptics/TLC5947

I am going to try and figure this out. I'll let you know what happens. If you have any other ideas please post them!

thank you.

nicnut
 
Posts: 99
Joined: Thu Jun 23, 2011 12:17 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by nicnut on Sun Feb 23, 2020 2:51 pm

Does anyone know of a library, or some example code that uses the hardware SPI of a board?

I think the problem in the timing issues I am having is because the Adafruit library to control TLC5947 breakout board uses software SPI, which has interrupts and is slowing everything down.

Please let me know.

People from Adafruit, maybe you can come up with some example code of how to use this board with hardware SPI? I think it would be almost necessary to use this break out board.

Thank you.

nicnut
 
Posts: 99
Joined: Thu Jun 23, 2011 12:17 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by adafruit_support_bill on Sun Feb 23, 2020 3:25 pm

the Adafruit library to control TLC5947 breakout board uses software SPI, which has interrupts and is slowing everything down.

The Adafruit_TLC5947 library does not use interrupts. It is a just very simple implementation of software SPI for the TLC5947: https://github.com/adafruit/Adafruit_TL ... LC5947.cpp

And yes, software SPI is slower than hardware SPI - assuming that the device implementation of the protocol is compatible with the hardware SPI implementation on the processor. But there is no formal protocol standard for SPI, so not all "SPI" devices are compatible with hardware SPI on all processors.

The Adafruit library is written to be compatible with as many processors as possible. We have no plans to optimize it for specific processors.

You may be able to find another library optimized for use with the Teensy. But judging from the fragments of code posted, I think there is some room for optimization in what you have now.

adafruit_support_bill
 
Posts: 76695
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LEDs are very slow to change colors and affecting ot

by nicnut on Sun Feb 23, 2020 4:25 pm

Hi,

Thank you for the reply. I'm very new at this and didn't even realize there was a difference between hardware and software SPI until a few days ago.

I think my code, except for the part that deals with the 12-bit PWM LED Driver, is pretty solid.

I don't know if you watched the video I made:

https://www.youtube.com/watch?v=ApEMP2U ... e=youtu.be

It shows how the timing is off once I integrate the code to control the LEDs, but is running great without that code.

It makes sense that you have to make a simple implementation of example code, as there's lots of different micro controllers out there. I see your point.

I am using a Teensy 3.6. Is there any kind of resource that you can think of for me to figure out how to implement hardware SPI? I've never dealt with this and honestly I don't know what I can do beyond cutting and pasting, changing a few variables and pin numbers. I feel like I'm way over my head on trying to resolve this issue.

thank you. Nick

nicnut
 
Posts: 99
Joined: Thu Jun 23, 2011 12:17 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by adafruit_support_bill on Sun Feb 23, 2020 4:50 pm

I think my code, except for the part that deals with the 12-bit PWM LED Driver, is pretty solid.

Solid and optimal are not necessarily the same. If you post some more of your code we may be able to help you optimize it.

adafruit_support_bill
 
Posts: 76695
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LEDs are very slow to change colors and affecting ot

by nicnut on Sun Feb 23, 2020 5:10 pm

Ok well thank you for taking a look. It's a lot of code, but maybe you can see something.

In Teensyduino you have to select USB type: MIDI for the code to verify. The board is a Teensy 3.6.

In looking at your library is see the function updateLeds()

Would that be better than tlc.write() ?

Let me know if you spot something.


Code: Select all | TOGGLE FULL SIZE

/* USB MIDI AnalogControlChange Example

   You must select MIDI from the "Tools > USB Type" menu
   http://www.pjrc.com/teensy/td_midi.html

   This example code is in the public domain.

   Nick Demopoulos March 2018
*/

#include <Bounce.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h> // wire library for LED matrix

#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

#include "Adafruit_TLC5947.h"  // for LED breakout board

// How many boards do you have chained?
#define NUM_TLC5947 2       // how many breakout boards?

#define data   18     // digital pins on the Teensy
#define clock   19
#define latch   29
#define oe  -1  // set to -1 to not use the enable pin (its optional)  // for LED boards

Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5947, clock, data, latch);

// the MIDI channel number to send messages
const int channel = 1;
const int MIDIchannel = 1;   // this will only apply to midi channel 1


// the MIDI continuous controller for each analog input
const int controllerA0 = 1; //  control change 1, ribbon
const int controllerA1 = 2; //control change 2
const int controllerA2 = 3; //control change 3
const int controllerA3 = 4; // control change 4
const int controllerA4 = 5; // control change 5
const int controllerA5 = 6; // control change 6
const int controllerA6 = 7; // control change 7
const int controllerA7 = 8; // control change 8
const int controllerA8 = 9; // control change 9  last ribbon
const int controllerA9 = 10; // control change 10 joystick
const int controllerA10 = 11; // joystick
const int controllerA11 = 12; // control change 12
const int controllerA12 = 13; // control change 13  joystick

const int controllerD14 = 14; // toggle, control change 14
const int controllerD15 = 15; //  Button, control change 15
const int controllerD16 = 16; //
const int controllerD17 = 17;
const int controllerD18 = 18;  //
const int controllerD19 = 19;
const int controllerD20 = 20;
const int controllerD21 = 21;
const int controllerD22 = 22;
const int controllerD23 = 23;
const int controllerD24 = 24;
const int controllerD25 = 25;
const int controllerD26 = 26;
const int controllerD27 = 27;




// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5);  // which is appropriate for good
Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5);  // to rapid touch, you can
Bounce button7 = Bounce(7, 5);  // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);
Bounce button12 = Bounce(12, 5);  // goes out of order because other pins double as analog inputs

Bounce button24 = Bounce(24, 5);
Bounce button25 = Bounce(25, 5);
Bounce button26 = Bounce(26, 5);
Bounce button27 = Bounce(27, 5);

//const int ledPin28 = 28;    // digital pin 28 For LED
//const int ledPin29 = 29;    // digital pin 29 For LED
//const int ledPin30 = 30;    // digital pin 30 For LED
//const int ledPin31 = 31;    // digital pin 29 For LED
//const int ledPin32 = 32;    // digital pin 29 For LED
//const int ledPin33 = 33;    // digital pin 29 For

const int ledcontroller15 = 15;    // midi control change 15
const int ledcontroller16 = 16;    // midi control change 16
const int ledcontroller17 = 17;    // midi control change 15
const int ledcontroller18 = 18;    // midi control change 16
const int ledcontroller19 = 19;    // midi control change 15
const int ledcontroller20 = 20;    // midi control change 16
const int ledcontroller23 = 23;    // midi control change 16

const int numMatrixControllers = 5;
const int firstMatrixController = 76;


// led matrix
Adafruit_7segment matrix = Adafruit_7segment();
// Adafruit_7segment matrix1 = Adafruit_7segment();
Adafruit_8x16matrix matrix2 = Adafruit_8x16matrix();

void setup() {

  //Serial.begin(9600);

  // Serial.println("TLC5947 test");     // commenting this out. Doesn't seem to matter if it's in or not.
  tlc.begin();
  //  if (oe >= 0) {
  //   pinMode(oe, OUTPUT);
  //  digitalWrite(oe, LOW);
  // }

  // wire 3.3V to AREF for 3.3V reference
  analogReference(DEFAULT);

  pinMode(0, INPUT_PULLUP);   // for button swithces
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(24, INPUT_PULLUP);
  pinMode(25, INPUT_PULLUP);
  pinMode(26, INPUT_PULLUP);
  pinMode(27, INPUT_PULLUP);


  usbMIDI.setHandleControlChange(myControlChange);
  setupLedDisplays();


}

// store previously sent values, to detect changes
int previousA0 = -1;
int previousA1 = -1;
int previousA2 = -1;
int previousA3 = -1;
int previousA4 = -1;
int previousA5 = -1;
int previousA6 = -1;
int previousA7 = -1;
int previousA8 = -1;
int previousA9 = -1;
int previousA10 = -1;
int previousA11 = -1;
int previousA12 = -1;


elapsedMillis msec = 0;



void loop() {

  {

    button0.update();    //  this button code works, goes from 0 to 127 when pressed
    button1.update();
    button2.update();
    button3.update();
    button4.update();
    button5.update();
    button6.update();
    button7.update();
    button8.update();
    button9.update();
    button10.update();
    button11.update();
    button12.update();
    button24.update();
    button25.update();
    button26.update();
    button27.update();



    if (button0.fallingEdge()) {                               // this deals with reading the button swithces
      usbMIDI.sendControlChange(controllerD14, 127, channel);
    }

    if (button0.risingEdge()) {
      usbMIDI.sendControlChange(controllerD14, 0, channel);
    }

    if (button1.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD15, 127, channel);
    }

    if (button1.risingEdge()) {
      usbMIDI.sendControlChange(controllerD15, 0, channel);
    }

    if (button2.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD16, 127, channel);
    }

    if (button2.risingEdge()) {
      usbMIDI.sendControlChange(controllerD16, 0, channel);
    }

    if (button3.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD17, 127, channel);
    }

    if (button3.risingEdge()) {
      usbMIDI.sendControlChange(controllerD17, 0, channel);
    }

    if (button4.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD18, 127, channel);
    }

    if (button4.risingEdge()) {
      usbMIDI.sendControlChange(controllerD18, 0, channel);
    }

    if (button5.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD19, 127, channel);
    }

    if (button5.risingEdge()) {
      usbMIDI.sendControlChange(controllerD19, 0, channel);
    }

    if (button6.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD20, 127, channel);
    }

    if (button6.risingEdge()) {
      usbMIDI.sendControlChange(controllerD20, 0, channel);
    }

    if (button7.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD21, 127, channel);
    }

    if (button7.risingEdge()) {
      usbMIDI.sendControlChange(controllerD21, 0, channel);
    }

    if (button8.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD22, 127, channel);
    }

    if (button8.risingEdge()) {
      usbMIDI.sendControlChange(controllerD22, 0, channel);
    }

    if (button9.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD23, 127, channel);
    }

    if (button9.risingEdge()) {
      usbMIDI.sendControlChange(controllerD23, 0, channel);
    }

    if (button10.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD24, 127, channel);
    }

    if (button10.risingEdge()) {
      usbMIDI.sendControlChange(controllerD24, 0, channel);
    }

    if (button11.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD25, 127, channel);
    }

    if (button11.risingEdge()) {
      usbMIDI.sendControlChange(controllerD25, 0, channel);
    }

    if (button12.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD26, 127, channel);
    }

    if (button12.risingEdge()) {
      usbMIDI.sendControlChange(controllerD26, 0, channel);
    }

    if (button24.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD27, 127, channel);
    }

    if (button24.risingEdge()) {
      usbMIDI.sendControlChange(controllerD27, 0, channel);
    }

    /*

      if (button25.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD28, 127, channel);
      }

      if (button25.risingEdge()) {
      usbMIDI.sendControlChange(controllerD28, 0, channel);
      }

      if (button26.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD29, 127, channel);
      }

      if (button26.risingEdge()) {
      usbMIDI.sendControlChange(controllerD29, 0, channel);
      }

      if (button27.fallingEdge()) {
      usbMIDI.sendControlChange(controllerD30, 127, channel);
      }

      if (button27.risingEdge()) {
      usbMIDI.sendControlChange(controllerD30, 0, channel);
      }

    */

  }


  // only check the analog inputs 50 times per second,
  // to prevent a flood of MIDI messages
  if (msec >= 3) {               //  i changed this value to 10 from 20 for faster updates
    msec = 0;

    int n0 = map(analogRead(A0), 0, 1023, 0, 127);
    int n1 = map(analogRead(A1), 0, 1023, 0, 127);
    int n2 = map(analogRead(A2), 0, 1023, 0, 127);
    int n3 = map(analogRead(A3), 0, 1023, 0, 127);
  //  int n4 = map(analogRead(A4), 0, 1023, 0, 127);   //commented this out for SCL0 and SDA0
  //  int n5 = map(analogRead(A5), 0, 1023, 0, 127);
    int n6 = map(analogRead(A6), 0, 1023, 0, 127);
    int n7 = map(analogRead(A7), 0, 1023, 0, 127);
    int n8 = map(analogRead(A8), 0, 1023, 0, 127);
    int n9 = map(analogRead(A9), 0, 1023, 0, 127);
    int n10 = map(analogRead(A14), 0, 1023, 0, 127);
    int n11 = map(analogRead(A15), 0, 1023, 0, 127);
    int n12 = map(analogRead(A16), 0, 1023, 0, 127);


    // only transmit MIDI messages if analog input changed
    if (n0 != previousA0) {
      previousA0 = n0;
      if (n0 < 2) n0 = 0;
      usbMIDI.sendControlChange(controllerA0, n0, channel);
    }

    if (n1 != previousA1) {
      previousA1 = n1;
      if (n1 < 2) n1 = 0;
      usbMIDI.sendControlChange(controllerA1, n1, channel);
    }

    if (n2 != previousA2) {
      previousA2 = n2;
      if (n2 < 2) n2 = 0;
      usbMIDI.sendControlChange(controllerA2, n2, channel);

    }
    if (n3 != previousA3) {
      previousA3 = n3;
      if (n3 < 2) n3 = 0;
      usbMIDI.sendControlChange(controllerA3, n3, channel);
    }

/*

    if (n4 != previousA4) {
      previousA4 = n4;
      if (n4 < 2) n4 = 0;
      usbMIDI.sendControlChange(controllerA4, n4, channel);

    }

    if (n5 != previousA5) {
      previousA5 = n5;
      if (n5 < 2) n5 = 0;
      usbMIDI.sendControlChange(controllerA5, n5, channel);

    }

    */

    if (n6 != previousA6) {
      previousA6 = n6;
      if (n6 < 2) n6 = 0;
      usbMIDI.sendControlChange(controllerA6, n6, channel);

    }

    if (n7 != previousA7) {
      previousA7 = n7;
      if (n7 < 2) n7 = 0;
      usbMIDI.sendControlChange(controllerA7, n7, channel);

    }

    if (n8 != previousA8) {
      previousA8 = n8;
      if (n8 < 2) n8 = 0;
      usbMIDI.sendControlChange(controllerA8, n8, channel);
    }

    if (n9 != previousA9) {
      previousA9 = n9;
      if (n9 < 3) n9 = 0;
      usbMIDI.sendControlChange(controllerA9, n9, channel);
    }

    if (n10 != previousA10) {
      previousA10 = n10;
      if (n10 < 3) n10 = 0;
      usbMIDI.sendControlChange(controllerA10, n10, channel);
    }

    if (n11 != previousA11) {
      previousA11 = n11;
      if (n11 < 3) n11 = 0;
      usbMIDI.sendControlChange(controllerA11, n11, channel);
    }

    if (n12 != previousA12) {
      previousA12 = n12;
      if (n12 < 3) n12 = 0;
      usbMIDI.sendControlChange(controllerA12, n12, channel);
    }



  }

  // MIDI Controllers should discard incoming MIDI messages.
  // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
  while (usbMIDI.read()) {
    // ignore incoming messages
  }
}



void myControlChange(byte channel, byte control, byte value) // for LEDs, MIDI output

{

  if (channel == MIDIchannel                 // going to try eliminating 2nd write
      && control == ledcontroller15
      && value == 0)


    tlc.setLED(0, 0, 0, 0);    //off
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 10)


    tlc.setLED(0, 246, 84, 106);  //light pink
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 20)


    tlc.setLED(0, 0, 0, 255);        //blue
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 30)


    tlc.setLED(0, 90, 0, 255);        //lavender
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 40)


    tlc.setLED(0, 255, 0, 255);        //pink
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 50)


    tlc.setLED(0, 255, 0, 0);        //red
  tlc.write();
  //  tlc.write();



  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 60)


    tlc.setLED(0, 255, 128, 0);        //orange
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 70)



    tlc.setLED(0, 255, 255, 0);      // yellow
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 80)


    tlc.setLED(0, 0, 255, 0);        // green
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 90)


    tlc.setLED(0, 50, 255, 50);        //light green
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 100)


    tlc.setLED(0, 0, 255, 90);        //turquoise
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 110)


    tlc.setLED(0, 0, 180, 255);        //light blue
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 120)



    tlc.setLED(0, 0, 255, 180);   //   aqua turquoise
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller15
      && value == 127)

    tlc.setLED(0, 255, 255, 255);    // white
  tlc.write();
  //  tlc.write();

  /////// new 16

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 0)


    tlc.setLED(1, 0, 0, 0);    //off
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 10)


    tlc.setLED(1, 246, 84, 106);  //light pink
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 20)


    tlc.setLED(1, 0, 0, 255);        //blue
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 30)


    tlc.setLED(1, 90, 0, 255);        //lavender
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 40)


    tlc.setLED(1, 255, 0, 255);        //pink
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 50)


    tlc.setLED(1, 255, 0, 0);        //red
  tlc.write();
  // tlc.write();



  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 60)


    tlc.setLED(1, 255, 128, 0);        //orange
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 70)


    tlc.setLED(1, 255, 255, 0);      // yellow
  tlc.write();
  ////  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 80)


    tlc.setLED(1, 0, 255, 0);        // green
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 90)


    tlc.setLED(1, 50, 255, 50);        //light green
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 100)


    tlc.setLED(1, 0, 255, 90);        //turquoise
  tlc.write();
  //   tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 110)


    tlc.setLED(1, 0, 180, 255);        //light blue
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 120)

    tlc.setLED(1, 0, 255, 180);   //   aqua turquoise
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller16
      && value == 127)

    tlc.setLED(1, 255, 255, 255);    // white
  tlc.write();
  //  tlc.write();

  ////////   17

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 0)


    tlc.setLED(2, 0, 0, 0);    //off
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 10)


    tlc.setLED(2, 246, 84, 106);  //light pink
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 20)


    tlc.setLED(2, 0, 0, 255);        //blue
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 30)


    tlc.setLED(2, 90, 0, 255);        //lavender
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 40)


    tlc.setLED(2, 255, 0, 255);        //pink
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 50)


    tlc.setLED(2, 255, 0, 0);        //red
  tlc.write();
  // tlc.write();



  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 60)


    tlc.setLED(2, 255, 128, 0);        //orange
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 70)



    tlc.setLED(2, 255, 255, 0);      // yellow
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 80)


    tlc.setLED(2, 0, 255, 0);        // green
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 90)


    tlc.setLED(2, 50, 255, 50);        //light green
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 100)


    tlc.setLED(2, 0, 255, 90);        //turquoise
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 110)


    tlc.setLED(2, 0, 180, 255);        //light blue
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 120)

    tlc.setLED(2, 0, 255, 180);   //   aqua turquoise
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller17
      && value == 127)

    tlc.setLED(2, 255, 255, 255);    // white
  tlc.write();
  //  tlc.write();

  /////   new 18

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 0)


    tlc.setLED(3, 0, 0, 0);    //off
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 10)


    tlc.setLED(3, 246, 84, 106);  //light pink
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 20)


    tlc.setLED(3, 0, 0, 255);        //blue
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 30)


    tlc.setLED(3, 90, 0, 255);        //lavender
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 40)


    tlc.setLED(3, 255, 0, 255);        //pink
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 50)


    tlc.setLED(3, 255, 0, 0);        //red
  tlc.write();
  //  tlc.write();



  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 60)


    tlc.setLED(3, 255, 128, 0);        //orange
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 70)


    tlc.setLED(3, 255, 255, 0);      // yellow
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 80)


    tlc.setLED(3, 0, 255, 0);        // green
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 90)


    tlc.setLED(3, 50, 255, 50);        //light green
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 100)


    tlc.setLED(3, 0, 255, 90);        //turquoise
  tlc.write();
  //  tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 110)


    tlc.setLED(3, 0, 180, 255);        //light blue
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 120)

    tlc.setLED(3, 0, 255, 180);   //   aqua turquoise
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller18
      && value == 127)

    tlc.setLED(3, 255, 255, 255);    // white
  tlc.write();
  // tlc.write();

  ////////// 23

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 0)


    tlc.setLED(8, 0, 0, 0);    //off
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 10)


    tlc.setLED(8, 246, 84, 106);  //light pink
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 20)


    tlc.setLED(8, 0, 0, 255);        //blue
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 30)


    tlc.setLED(8, 90, 0, 255);        //lavender
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 40)


    tlc.setLED(8, 255, 0, 255);        //pink
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 50)


    tlc.setLED(8, 255, 0, 0);        //red
  tlc.write();
  //  tlc.write();



  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 60)


    tlc.setLED(8, 255, 128, 0);        //orange
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 70)


    tlc.setLED(8, 255, 255, 0);      // yellow
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 80)


    tlc.setLED(8, 0, 255, 0);        // green
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 90)


    tlc.setLED(8, 50, 255, 50);        //light green
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 100)


    tlc.setLED(8, 0, 255, 90);        //turquoise
  tlc.write();
  // tlc.write();

  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 110)


    tlc.setLED(8, 0, 180, 255);        //light blue
  tlc.write();
  // tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 120)

    tlc.setLED(8, 0, 255, 180);   //   aqua turquoise
  tlc.write();
  //  tlc.write();


  if (channel == MIDIchannel
      && control == ledcontroller23
      && value == 127)

    tlc.setLED(8, 255, 255, 255);    // white
  tlc.write();
  // tlc.write();



}




nicnut
 
Posts: 99
Joined: Thu Jun 23, 2011 12:17 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by chemdoc77 on Sun Feb 23, 2020 7:38 pm

The FastLED library uses hardware SPI. See:

https://github.com/FastLED/FastLED/wiki ... it-banging

chemdoc77
 
Posts: 145
Joined: Mon Jan 28, 2013 9:32 am

Re: RGB LEDs are very slow to change colors and affecting ot

by adafruit_support_bill on Sun Feb 23, 2020 7:57 pm

You have numerous calls to sendControlChange within your loop. sendControlChange appears to be mapped to myControlChange. And within myControlChange, you have lots of calls to tlc.write().

As I suggested in my very first response above, you only need one call to tlc.write() in your loop. All the rest are redundant. You can't really pin the blame on the driver if you are not using it efficiently.

adafruit_support_bill
 
Posts: 76695
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LEDs are very slow to change colors and affecting ot

by nicnut on Sun Feb 23, 2020 8:26 pm

Hi chemdoc,

Ok I'll try FastLED library. THank You.

to Adafruit_support_bill: This code is for a midi controller. So when a midi message is received it might trigger one of many things. There isn't going to be rainbow or color wheels or anything like that. One midi control change message changes one LED to a color. THat's why there are so many messages. I am writing out what happens for each possibility.

The Teensy is barely using any ram or memory. I'm pretty sure it can handle it. For the LED displays, the 7 segment display and the 8 X 16 matrix, there's like hundreds of messages and it reads them fine. Pretty much instantaneously. You can see it in the beginning of the video.

I don't think that's the issue, and if it is then how would you achieve what I am describing?

Thank You.

nicnut
 
Posts: 99
Joined: Thu Jun 23, 2011 12:17 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by adafruit_support_bill on Sun Feb 23, 2020 8:49 pm

I don't think that's the issue, and if it is then how would you achieve what I am describing?

At most, you only need to call tlc.write() once per iteration of your loop. As a practical matter, there is no need to call it more frequently than once every 10 or 20 milliseconds.

Your code goes to the trouble of throttling response to MIDI messages:
Code: Select all | TOGGLE FULL SIZE
  // only check the analog inputs 50 times per second,
  // to prevent a flood of MIDI messages
  if (msec >= 3) {               //  i changed this value to 10 from 20 for faster updates

But each MIDI message (not to mention button activity) can potentially trigger multiple LED updates. So why would you not make any attempt to suppress totally redundant LED updates?

adafruit_support_bill
 
Posts: 76695
Joined: Sat Feb 07, 2009 10:11 am

Re: RGB LEDs are very slow to change colors and affecting ot

by nicnut on Sun Feb 23, 2020 9:48 pm

Hi Adafruit_Support_bill,

Is it possible to create an array or something, then have changes written to the array and have the whole thing sent to tlc.write(), so every change is reflected in that and it only gets sent once whenever there is a change?

I'm pretty novice programmer, but this seems like one possible method.

Also, I found this thread in the Teensy Forum:

https://forum.pjrc.com/threads/42214-Ne ... PI-library

This person altered the Adafruit_TLC5947 library to be SPI hardware. He noticed the same kind of slowness that I think I am describing and he altered the library and example code so he could do:
SPIwrite() instead of tlc.write

and said it was faster.

My brain is about to melt, so I am going to put this down for a bit and revisit it tomorrow.

Thank you for your help and input.

nicnut
 
Posts: 99
Joined: Thu Jun 23, 2011 12:17 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by Duke9 on Sun Feb 23, 2020 11:32 pm

That's exactly how I would do (and have done) it assuming enough RAM, buffer all of the intermediate changes in an array and then blast the entire array out periodically.

Duke9
 
Posts: 35
Joined: Wed Jul 20, 2016 3:22 pm

Re: RGB LEDs are very slow to change colors and affecting ot

by adafruit_support_bill on Mon Feb 24, 2020 6:45 am

Is it possible to create an array or something, then have changes written to the array and have the whole thing sent to tlc.write(),

That is precisely what the library does. As I have been saying: you do not need to call tlc.write more than once per loop iteration.

You may make it marginally faster by using hardware SPI. But the fastest code of all is the code you don't have to execute!

adafruit_support_bill
 
Posts: 76695
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.