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);
}
}