Dear techies,
Complete newb here !
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 ++ ;
 }