Teensy 3.2/LC and FastLED unexpected behaviour

Status
Not open for further replies.

chaosmoon

Active member
Hi,

I'm working on a tetrahedron frame running WS2812 ledstrips over the edges. An edge is 30 leds and i'm using 3 pins on the TeensyLC to each drive 2 edges = 60 leds per pin with FastLED 3.2.6
The Teensy and ledstrips are powered from an external 40A supply. I'm using a 74AHCT126 quad level-shifter to get the data lines to 5V.
For now i'm triggering functions via USB-MIDI but my intention is to move to OSC.

Basic stuff like fill.solid is working but i'm running into strange behaviour with i = (i +1) animated functions. I've tried to debug, re-write and re-name things as best as i can and also tested with a 3.2 to check if its a memory issue. The behaviour was the same.

Currently all works as expected except "edge5RunFunc()" which will trigger a clocked variable on edge 6 and light up a led on edge 1. Earlier on this was happening with "edge3RunFunc()". I'm pretty sure my code is far from optimal and hope someone with more experience can pick out any mistakes.

thanks for your time.

tetraPjrc.jpg

Code:
// 3 pins branch



#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();

#include <FastLED.h>
#define EDGE_1_2_PIN 2
#define EDGE_4_5_PIN 3
#define EDGE_6_3_PIN 4

#define NUM_LEDS 60
#define EDGE_LEDS 30
CRGB edgeArray12[NUM_LEDS];
CRGB edgeArray45[NUM_LEDS];
CRGB edgeArray63[NUM_LEDS];

byte ntHue = 0;
byte ntSat = 0;
byte ntBright = 0;

byte lastPixel = EDGE_LEDS - 1;
byte FPS = 200;

bool tetraFillActive = false;

unsigned long prevMillis = 0;
unsigned long currentMillis = 0;

unsigned long prevRun1Millis = 0;
bool edge1Run = false;
byte edge1Clock = 0;
byte velocity1Speed = 0;

unsigned long prevRun2Millis = 0;
bool edge2Run = false;
byte edge2Clock = 0;
byte velocity2Speed = 0; 

unsigned long prevRun3Millis = 0;
bool edge3Run = false;
byte edge3Clock = 0;
byte velocity3Speed = 0;

unsigned long prevRun4Millis = 0;
bool edge4Run = false;
byte edge4Clock = 0;
byte velocity4Speed = 0;

unsigned long prevRun5Millis = 0;
bool edge5Run = false;
byte edge5Clock = 0;
byte velocity5Speed = 0;

unsigned long prevRun6Millis = 0;
bool edge6Run = false;
byte edge6Clock = 0;
byte velocity6Speed = 0;



void setup() {
  FastLED.addLeds<NEOPIXEL, EDGE_1_2_PIN>(edgeArray12, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, EDGE_6_3_PIN>(edgeArray63, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, EDGE_4_5_PIN>(edgeArray45, NUM_LEDS);
  
  usbMIDI.begin();

  usbMIDI.setHandleNoteOn(inputNoteOn);
  usbMIDI.setHandleNoteOff(inputNoteOff);
  usbMIDI.setHandleControlChange(controlChangeInput);
  
  ntBright = 255;
  
  FastLED.clear();
  FastLED.show();

}

void loop() {
  while (usbMIDI.read());
  currentMillis = millis();
  edge1RunFunc();
  edge2RunFunc();
  edge3RunFunc();
  edge4RunFunc();
  edge5RunFunc();
  edge6RunFunc();      
  tetraFill();

  if (currentMillis - prevMillis > (1000 / FPS))
    { 
    FastLED.show();
    prevMillis = currentMillis; 
    }

}


void inputNoteOn(byte channel, byte note, byte velocity)
  { 
  if (note == 1)
    {
    ntHue = velocity*2;
    }

  if (note == 2)
    {
    ntSat = velocity*2;
    }

  if (note == 3)
    {
    ntBright = velocity*2;
    }
    
    
  if (note == 24)
    {
     fill_solid(edgeArray12,EDGE_LEDS, CHSV(ntHue,ntSat,ntBright));    
    }

  if (note == 25)
    {  
     fill_solid(edgeArray12+EDGE_LEDS,EDGE_LEDS, CHSV(ntHue,ntSat,ntBright));     
    }

  if (note == 26)
    {  
    fill_solid(edgeArray63+EDGE_LEDS,EDGE_LEDS, CHSV(ntHue,ntSat,ntBright));    
    }

  if (note == 27)
    {
    fill_solid(edgeArray45,EDGE_LEDS, CHSV(ntHue,ntSat,ntBright)); 
    }

  if (note == 28)
    {
    fill_solid(edgeArray45+EDGE_LEDS,EDGE_LEDS, CHSV(ntHue,ntSat,ntBright));   
    }

  if (note == 29)
    {  
    fill_solid(edgeArray63,EDGE_LEDS, CHSV(ntHue,ntSat,ntBright));     
    }

  if (note == 30)
    {
    tetraFillActive = true;      
    }

  if (note == 36) 
    {
    edge1Run = true;
    velocity1Speed = velocity;
    edge1Clock = 0;
    fill_solid(edgeArray12,EDGE_LEDS, CRGB::Black);
    edgeArray12[0] = CRGB::White;   
    } 

  if (note == 37) 
    {
    edge2Run = true;
    velocity2Speed = velocity;
    edge2Clock = (EDGE_LEDS+lastPixel);
    fill_solid(edgeArray12+EDGE_LEDS,EDGE_LEDS, CRGB::Black);
    edgeArray12[EDGE_LEDS+lastPixel] = CRGB::White;   
    } 

  if (note == 38) 
    {
    edge3Run = true;
    velocity3Speed = velocity;
    edge3Clock = (EDGE_LEDS);
    fill_solid(edgeArray63+EDGE_LEDS,EDGE_LEDS, CRGB::Black);
    edgeArray63[EDGE_LEDS] = CRGB::White;  
    }

  if (note == 39) 
    {
    edge4Run = true;
    velocity4Speed = velocity;
    edge4Clock = 0;
    fill_solid(edgeArray45,EDGE_LEDS, CRGB::Black);
    edgeArray45[0] = CRGB::White;   
    }          

  if (note == 40) 
    {
    edge5Run = true;
    velocity5Speed = velocity;
    edge5Clock = EDGE_LEDS;
    fill_solid(edgeArray45+EDGE_LEDS,EDGE_LEDS, CRGB::Black);
    edgeArray45[EDGE_LEDS] = CRGB::White;   
    }          
 
  if (note == 41) 
    {
    edge6Run = true;
    velocity6Speed = velocity;
    edge6Clock = 0;
    fill_solid(edgeArray63,EDGE_LEDS, CRGB::Black);
    edgeArray63[0] = CRGB::White;    
    }          
  }


void inputNoteOff(byte channel, byte note, byte velocity)
  {
  if (note == 24)
    {
     fill_solid(edgeArray12,EDGE_LEDS, CRGB::Black);       
    }
  
  if (note == 25)
    { 
     fill_solid(edgeArray12+EDGE_LEDS,EDGE_LEDS, CRGB::Black);     
    }

  if (note == 26)
    { 
    fill_solid(edgeArray63+EDGE_LEDS,EDGE_LEDS, CRGB::Black);    
    }

  if (note == 27)
    { 
     fill_solid(edgeArray45,EDGE_LEDS, CRGB::Black);     
    }

  if (note == 28)
    { 
     fill_solid(edgeArray45+EDGE_LEDS,EDGE_LEDS, CRGB::Black);      
    }
  
  if (note == 29)
    { 
    fill_solid(edgeArray63,EDGE_LEDS, CRGB::Black);    
    }

    if (note == 30)
    {   
    tetraFillActive = false;
    fill_solid(edgeArray12,EDGE_LEDS*2, CRGB::Black);
    fill_solid(edgeArray45,EDGE_LEDS*2, CRGB::Black);
    fill_solid(edgeArray63,EDGE_LEDS*2, CRGB::Black);    
    }
  } 
      
void edge1RunFunc()
  {
  if (edge1Run == true) 
    {
    if (currentMillis - prevRun1Millis >= velocity1Speed) 
      {
      edge1Clock = (edge1Clock + 1);
      prevRun1Millis = currentMillis;
      }
    edgeArray12[edge1Clock] = CRGB::White;
    edgeArray12[(edge1Clock-1)] = CRGB::Black;
    
    if (edge1Clock == lastPixel) 
      {
      edge1Run = false;
      edge1Clock = 0;
      fill_solid(edgeArray12,EDGE_LEDS, CRGB::Black);     
      }
    }
  }

void edge2RunFunc()
  {
  if (edge2Run == true) 
    {
    if (currentMillis - prevRun2Millis >= velocity2Speed) 
      {
      edge2Clock = (edge2Clock - 1);
      prevRun2Millis = currentMillis;
      }
    edgeArray12[edge2Clock] = CRGB::White;
    edgeArray12[(edge2Clock+1)] = CRGB::Black;
    
    if (edge2Clock == EDGE_LEDS) 
      {
      edge2Run = false;
      edge2Clock = (EDGE_LEDS+lastPixel);
      fill_solid(edgeArray12+EDGE_LEDS,EDGE_LEDS, CRGB::Black);      
      }
    }
  } 

void edge3RunFunc()
  {
  if (edge3Run == true) 
    {
    if (currentMillis - prevRun3Millis >= 10) 
      {
      edge3Clock = (edge3Clock + 1);
      prevRun3Millis = currentMillis;
      }
    edgeArray63[edge3Clock] = CRGB::White;
    edgeArray63[(edge3Clock-1)] = CRGB::Black;
    
    if (edge3Clock == lastPixel) 
      {
      edge3Run = false;
      edge3Clock = EDGE_LEDS;
      fill_solid(edgeArray63+EDGE_LEDS,EDGE_LEDS, CRGB::Black);
      
      }
    }
  }

void edge4RunFunc()
  {
  if (edge4Run == true) 
    {
    if (currentMillis - prevRun4Millis >= velocity4Speed) 
      {
      edge4Clock = (edge4Clock + 1);
      prevRun4Millis = currentMillis;
      }
    edgeArray45[edge4Clock] = CRGB::White;
    edgeArray45[(edge4Clock-1)] = CRGB::Black;
    
    if (edge4Clock == lastPixel) 
      {
      edge4Run = false;
      edge4Clock = 0;
      fill_solid(edgeArray45,EDGE_LEDS, CRGB::Black);     
      }
    }
  }

void edge5RunFunc()
  {
  if (edge5Run == true) 
    {
    if (currentMillis - prevRun5Millis >= velocity5Speed) 
      {
      edge5Clock = (edge5Clock + 1);
      prevRun5Millis = currentMillis;
      }
    edgeArray45[edge5Clock] = CRGB::White;
    edgeArray45[(edge5Clock-1)] = CRGB::Black;    
    if (edge5Clock == lastPixel) 
      {
      edge5Run = false;
      edge5Clock = EDGE_LEDS;
      fill_solid(edgeArray45+EDGE_LEDS,EDGE_LEDS, CRGB::Black);      
      }
    }
  }

void edge6RunFunc()
  {
  if (edge6Run == true) 
    {
    if (currentMillis - prevRun6Millis >= velocity6Speed) 
      {
      edge6Clock = (edge6Clock + 1);
      prevRun6Millis = currentMillis;
      }
    edgeArray63[edge6Clock] = CRGB::White;
    edgeArray63[(edge6Clock-1)] = CRGB::Black;    
    if (edge6Clock == lastPixel) 
      {
      edge6Run = false;
      edge6Clock = 0;
      fill_solid(edgeArray63,EDGE_LEDS, CRGB::Black);     
      }
    }
  }
 

void tetraFill()
  {
  if (tetraFillActive == true)
    {
    fill_solid(edgeArray12,EDGE_LEDS*2, CHSV(ntHue,ntSat,ntBright));
    fill_solid(edgeArray45,EDGE_LEDS*2, CHSV(ntHue,ntSat,ntBright));
    fill_solid(edgeArray63,EDGE_LEDS*2, CHSV(ntHue,ntSat,ntBright));   
    }  
  }

void controlChangeInput(byte channel, byte control, byte value)
  {
  
  }
 
Status
Not open for further replies.
Back
Top