Lets try a 4th time. Hi all.

fastled-support
gplus
(Matthew Banko) #1

Lets try a 4th time. Hi all. Having VERY hard time posting so this will be short except for the code. FastLED 3.01, IDE 1.57, OSX 10.10.3, Mega2560/UnoATA328, CTC-DRA-10-1 DMX shield, APA104 strip. Using code from FastLED community (works), Conceptinetics code for slave DMX, works but not with FastLED code. THANKS for any help!!!
Joe B

#include <Conceptinetics.h>
#include “FastLED.h” // FastLED library. Preferably the latest copy of FastLED 2.1.
#include <SoftwareSerial.h>

// Use qsuba for smooth pixel colouring and qsubd for non-smooth pixel colouring
#define qsubd(x, b) ((x>b)?wavebright:0) // Digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
#define qsuba(x, b) ((x>b)?x-b:0) // Analog Unsigned subtraction macro. if result <0, then => 0

#define LED_DT 5 // Serial data pin for WS2812 or WS2801.
#define ledPin 12
#define COLOR_ORDER GRB // Are they GRB for WS2812 and GBR for APA102
#define LED_TYPE WS2811 // What kind of strip are you using? WS2812, APA102. . .
#define NUM_LEDS 120
#define COOLING 80
#define SPARKING 20

#define DMX_SLAVE_CHANNELS 8
DMX_Slave dmx_slave ( DMX_SLAVE_CHANNELS );

// Number of LED’s.
struct CRGB leds[NUM_LEDS]; // Initialize our LED array.

uint8_t max_bright = 64; // Overall brightness definition. It can be changed on the fly.
int CurPatt = 0;
int CurSpeed = 4;
int CurBright = 4;
int UPDATES_PER_SECOND = 1000;

// Palette definitions
CRGBPalette16 currentPalette;
CRGBPalette16 gPal;
TBlendType currentBlending;
const TProgmemRGBPalette16 SALS_p PROGMEM =
{
CRGB::Orange,
CRGB::DarkRed,
CRGB::DarkRed,
CRGB::Orange,

CRGB::Orange,
CRGB::Orange,
CRGB::Orange,
CRGB::Orange,

CRGB::Orange,
CRGB::DarkRed,
CRGB::DarkRed,
CRGB::Orange,

CRGB::Black,
CRGB::Black,
CRGB::Black,
CRGB::Black

};
const TProgmemPalette16 RWB_p PROGMEM =
{
CRGB::Red,
CRGB::Gray, // ‘white’ is too bright compared to red and blue
CRGB::Blue,
CRGB::Black,

CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,

CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};
void setup() {
//Serial.begin(57600);
dmx_slave.enable ();
dmx_slave.setStartAddress (169);
pinMode ( ledPin, OUTPUT );

LEDS.addLeds<LED_TYPE, LED_DT,COLOR_ORDER>(leds, NUM_LEDS); // WS2812
FastLED.setBrightness(max_bright);
currentPalette = RainbowColors_p;
currentBlending = BLEND;
} // setup()

void loop()
{
dmx_slave.enable ();
if ( dmx_slave.getChannelValue (1) > 127 )
{
digitalWrite ( ledPin, HIGH );
}
else
{
digitalWrite ( ledPin, LOW );
}
dmx_slave.disable ();
if (CurBright != map(analogRead(A5),0,1023,1,150))
{
CurBright = map(analogRead(A5),0,1023,1,150);
};

if (CurSpeed != map(analogRead(A4),0,1023,1,20))
{
CurSpeed = map(analogRead(A4),0,1023,1,20);
};

if (CurPatt != map(analogRead(A3),0,1023,0,12))
{
CurPatt = map(analogRead(A3),0,1023,0,12);
}
if (CurPatt == 12)
{
random16_add_entropy(random());
Fire2012WithPalette();
FastLED.show(); // display this frame
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
else
{
RunManual();
static uint8_t startIndex = 0;
startIndex = startIndex + CurSpeed; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(30);
}
}

void RunManual()
{
switch (CurPatt)
{
case 0:
currentPalette = SALS_p;
break;
case 1:
currentPalette = RainbowColors_p;
break;
case 2:
currentPalette = RainbowStripeColors_p;
break;
case 3:
currentPalette = PartyColors_p;
break;
case 4:
currentPalette = HeatColors_p;
break;
case 5:
currentPalette = OceanColors_p;
break;
case 6:
currentPalette = ForestColors_p;
break;
case 7:
currentPalette = LavaColors_p;
break;
case 8:
currentPalette = CloudColors_p;
break;
case 9:
currentPalette = RWB_p;
break;
case 10:
SetupPurpleAndGreenPalette();
break;
case 11:
SetupBlackAndWhiteStripedPalette();
break;
}
}// end manual

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = CurBright;

for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}

void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;

currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}
void SetupBlackAndWhiteStripedPalette()
{
// ‘black out’ all 16 palette entries…
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;

}

void Fire2012WithPalette()
{
currentPalette = HeatColors_p;
static byte heat[NUM_LEDS];
for( int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
for( int k= NUM_LEDS - 1; k >= 2; k–) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
for( int j = 0; j < NUM_LEDS; j++) {
byte colorindex = scale8( heat[j], 200);
leds[j] = ColorFromPalette( currentPalette, colorindex);
}
}

(Daniel Garcia) #2

As I mentioned on your post on Arduino.cc - the APA104, like the WS2812 requires FastLED to disable interrupts while it is writing data out. Unfortunately, reading DMX data requires interrupts being enabled in order to catch data coming in, and since DMX has no error detection, this can result in DMX data that comes in while led data is being written out being corrupted.

The most ideal solution would be to replace your APA104’s with LEDs that don’t require disabling interrupts, for example, the APA102 or the LPD8806.

Another solution would be to make sure that any DMX data that has been read, after you called FastLED.show() (or FastLED.delay, which also calls FastLED.show()), is ignored, and wait for a completely new DMX frame to come in, it isn’t clear to me, however, that the Conceptinetics library makes this easy to do.

(Matthew Banko) #3

Thanks. I must have read the specs wrong on the 102/104. I didn’t know that the 104 needed to disable interrupts. I did find some code that grabs DMX data by frame. I need to go back and look at the specification again but it would seem that I could get the timing to work that way. I’ve just made an investment in the 104s and would hate to have to switch now. Thanks again, at least now I have a better idea of what the problem is.