Fading LEDstrip Dotstar

Dear techies,

Complete newb here ! :slight_smile:

I have purchased a Adafruit Dotstar LEDstrip (https://www.adafruit.com/products/2242)
But there is unfortunately few tutorials for how to program it, so I have encountered some problems.

I want the LED strip to fade nicely from orange to blue back to orange.
I have made a code, look below, but Im not satisfied.

  • It doesn’t make a perfect fading. Fx. from orange to blue it blinks at the end, making a hard shift
  • From orange to blue it becomes purple for a small period, and doesnt look nice

Thanks on beforehand !

#include <Adafruit_DotStar.h>
#include <SPI.h>         // COMMENT OUT THIS LINE FOR GEMMA OR TRINKET
#define NUMPIXELS 244 // Number of LEDs in strip
#define DATAPIN    4
#define CLOCKPIN   5
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);

void setup() {

#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
  clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif

  strip.begin(); // Initialize pins for output
  strip.show();  // Turn all LEDs off ASAP
}

uint32_t color = 0xFF0000;     
int j = 0;
int i = 0;
int red = 0;
int green = 0;
int blue = 0;
int time = 0;
int newtime = 0;
float oldred = 0;
float oldgreen = 0;
float oldblue = 0;

void loop() {

  strip.setBrightness(30);
  
  if ( time == 0)
    {
      red = 255;
      green = 100;
      blue = 0;
      i = 0;
    }
    
  if ( time == 1)
    {
      red = 0;
      green = 0;
      blue = 255;
      i = 0;
    }
    
  if ( time == 2)
    {
      red = 255;
      green = 100;
      blue = 0;
      i = 0;
    }    
        
     int r = red-oldred;
     int g = green-oldgreen;
     int b = blue-oldblue;
  
  while ( j < 100 ) 
  { 
    while (i < 244)
    {       
      strip.setPixelColor(i,oldred, oldgreen, oldblue);   
    i++;
    }
    i = 0;
    oldred = oldred + (r/100);
    oldgreen = oldgreen + (g/100);
    oldblue = oldblue + (b/100);
    strip.show();      
    delay(50);
    j++; 
  }
    j = 0;
    oldred = red;
    oldgreen = green;
    oldblue = blue;
    time ++ ;
  }