Just looked at your rainbow code:
for(j=0; j<256*10; j++) { // 5 cycles of all colors on wheel
for(i=0; i< NUM_LEDS; i++) {
c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}
showStrip();
delay(SpeedDelay);
}
If we strip out the chaff, we see:
for(j=0; j<2560; j++)
{
.
.
.
delay(SpeedDelay);
}
With SpeedDelay == 10mS, 2560 is 25.6-seconds.
You can't block like this and expect other stuff to run on time. ¯_(ツ)_/¯
You might try something like:
void rainbowCycle( void )
{
byte
i;
static int
cycle = 0;
byte *c;
static unsigned long
timeRainbow == millis();
if( (millis() - timeRainbow) < 10 )
return;
timeRainbow = millis();
// 5 cycles of all colors on wheel
for(i=0; i< NUM_LEDS; i++)
{
c = Wheel(((i * 256 / NUM_LEDS) + cycle) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}//for
cycle++;
if( cycle == 2560 )
cycle = 0;
showStrip();
}//
but that rainbow code is pretty computationally and bandwidth heavy. Would be interesting to see if there's enough cycles in one of these things to do it.
itg123
January 18, 2019, 6:52am
22
Sorry This is dragging on. Its not compiling now.
#include "FastLED.h"
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];
#define PIN 4
#define NUM_LEDS_PER_STRIP 3
CRGB redLeds[NUM_LEDS_PER_STRIP];
CRGB greenLeds[NUM_LEDS_PER_STRIP];
#define STRB_STATE_A 0
#define STRB_STATE_B 1
#define STRB_STATE_C 2
#define STRB_STATE_D 3
#define WAIT_TIME 10 //mS
void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<NEOPIXEL, 2>(redLeds, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 3>(greenLeds, NUM_LEDS_PER_STRIP);
}
//change
void Strobes( void )
{
static int
strobeState = STRB_STATE_A;
static unsigned long
strobeDelay = 0,
strobeTimer = millis();
unsigned long
timeNow;
timeNow = millis();
if( (timeNow - strobeTimer) < strobeDelay )
return;
strobeTimer = timeNow;
switch( strobeState )
{
case STRB_STATE_A:
redLeds[0] = CRGB::White;
redLeds[1] = CRGB::Red;
redLeds[2] = CRGB::Red;
greenLeds[0] = CRGB::White;
greenLeds[1] = CRGB::Green;
greenLeds[2] = CRGB::Green;
strobeDelay = 100; //100mS
strobeState = STRB_STATE_B;
break;
case STRB_STATE_B:
// clear our current dot before we move on
redLeds[0] = CRGB::Black;
greenLeds[0] = CRGB::Black;
strobeDelay = 50; //50mS
strobeState = STRB_STATE_C;
break;
case STRB_STATE_C:
redLeds[0] = CRGB::White;
greenLeds[0] = CRGB::White;
strobeDelay = 50; //50mS
strobeState = STRB_STATE_D;
break;
case STRB_STATE_D:
redLeds[0] = CRGB::Black;
greenLeds[0] = CRGB::Black;
strobeDelay = 1000; //1000mS
strobeState = STRB_STATE_A;
break;
default:
strobeTimer = millis();
strobeDelay = 0;
strobeState = STRB_STATE_A;
break;
}//switch
FastLED.show();
}//Strobes
void loop() {
Strobes();
rainbowCycle();
}
void rainbowCycle( void )
{
byte
i;
static int
cycle = 0;
byte *c;
static unsigned long
timeRainbow == millis();
if( (millis() - timeRainbow) < 10 )
return;
timeRainbow = millis();
// 5 cycles of all colors on wheel
for(i=0; i< NUM_LEDS; i++)
{
c = Wheel(((i * 256 / NUM_LEDS) + cycle) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}//for
cycle++;
if( cycle == 2560 )
cycle = 0;
showStrip();
}//
//Keep
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
I had a boo-boo in rainbowCycle():
.
.
.
static unsigned long
timeRainbow == millis();
.
.
.
Just remove one of the '=' signs there.
But it appears you've also removed Wheel but still try to call it:
.
.
.
for(i=0; i< NUM_LEDS; i++)
{
c = Wheel(((i * 256 / NUM_LEDS) + cycle) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}//for
.
.
.
itg123
January 19, 2019, 1:45am
24
I guess I clipped the wheel portion off by mistake. Everything is working now. Still sitting at 105% of storage space (6370 bytes of available 6012). Ill play with the rainbowcycle and see if there is a way to clean things up a bit.
As always, thanks for the help.
#include "FastLED.h"
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];
#define PIN 4
#define NUM_LEDS_PER_STRIP 3
CRGB redLeds[NUM_LEDS_PER_STRIP];
CRGB greenLeds[NUM_LEDS_PER_STRIP];
#define STRB_STATE_A 0
#define STRB_STATE_B 1
#define STRB_STATE_C 2
#define STRB_STATE_D 3
#define WAIT_TIME 10 //mS
void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<NEOPIXEL, 2>(redLeds, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 3>(greenLeds, NUM_LEDS_PER_STRIP);
}
//change
void Strobes( void )
{
static int
strobeState = STRB_STATE_A;
static unsigned long
strobeDelay = 0,
strobeTimer = millis();
unsigned long
timeNow;
timeNow = millis();
if( (timeNow - strobeTimer) < strobeDelay )
return;
strobeTimer = timeNow;
switch( strobeState )
{
case STRB_STATE_A:
redLeds[0] = CRGB::White;
redLeds[1] = CRGB::Red;
redLeds[2] = CRGB::Red;
greenLeds[0] = CRGB::White;
greenLeds[1] = CRGB::Green;
greenLeds[2] = CRGB::Green;
strobeDelay = 100; //100mS
strobeState = STRB_STATE_B;
break;
case STRB_STATE_B:
// clear our current dot before we move on
redLeds[0] = CRGB::Black;
greenLeds[0] = CRGB::Black;
strobeDelay = 50; //50mS
strobeState = STRB_STATE_C;
break;
case STRB_STATE_C:
redLeds[0] = CRGB::White;
greenLeds[0] = CRGB::White;
strobeDelay = 50; //50mS
strobeState = STRB_STATE_D;
break;
case STRB_STATE_D:
redLeds[0] = CRGB::Black;
greenLeds[0] = CRGB::Black;
strobeDelay = 1000; //1000mS
strobeState = STRB_STATE_A;
break;
default:
strobeTimer = millis();
strobeDelay = 0;
strobeState = STRB_STATE_A;
break;
}//switch
FastLED.show();
}//Strobes
void loop() {
Strobes();
rainbowCycle();
}
void rainbowCycle( void )
{
byte
i;
static int
cycle = 0;
byte *c;
static unsigned long
timeRainbow = millis();
if( (millis() - timeRainbow) < 10 )
return;
timeRainbow = millis();
// 5 cycles of all colors on wheel
for(i=0; i< NUM_LEDS; i++)
{
c = Wheel(((i * 256 / NUM_LEDS) + cycle) & 255);
setPixel(i, *c, *(c+1), *(c+2));
}//for
cycle++;
if( cycle == 2560 )
cycle = 0;
showStrip();
}//
//
byte * Wheel(byte WheelPos) {
static byte c[3];
if(WheelPos < 85) {
c[0]=WheelPos * 3;
c[1]=255 - WheelPos * 3;
c[2]=0;
} else if(WheelPos < 170) {
WheelPos -= 85;
c[0]=255 - WheelPos * 3;
c[1]=0;
c[2]=WheelPos * 3;
} else {
WheelPos -= 170;
c[0]=0;
c[1]=WheelPos * 3;
c[2]=255 - WheelPos * 3;
}
return c;
}//wheel
//Keep
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
itg123
January 19, 2019, 2:09am
25
Found a workaround in the mean time. You can load the micronucleus bootloader to the digispark and increase the memory from 6012 bytes to 6714 bytes.
Sweet fix. So it's all good now?
itg123
January 19, 2019, 4:18am
27
I think so. Thanks again for all of your help and pretty much fixing the sketch multiple times.
I really appreciate it.
Ian