Hello again!
Some deadlines shifted and I found myself with a bit of free time on my hands - so I went ahead and wrote that I believe to be MCVEs.
I tried to keep the code as uniform as possible between the four sketches, but naturally there will be small discrepancies.
#include <FastLED.h>
#define DATA_PIN 4
#define NUM_LEDS 7
// Little under 60Hz
#define FRAME_MS 17
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.show();
}
void loop() {
static uint32_t ts = 0;
static int anim_counter = 0;
uint32_t now = millis();
if(now > ts){
ts = now + FRAME_MS;
CRGB val;
switch((anim_counter/256)){
case 0: // RED
val = CRGB(anim_counter % 255, 0, 0);
break;
case 1: // GREEN
val = CRGB(0, anim_counter % 255, 0);
break;
case 2: // BLUE
val = CRGB(0, 0, anim_counter % 255);
break;
}
if(++anim_counter >= 768)anim_counter = 0;
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = val;
}
FastLED.show();
}
}
#include <FastLED.h>
#define DATA_PIN 4
#define NUM_LEDS 7
// Little under 60Hz
#define FRAME_MS 17
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.show();
}
void loop() {
static uint32_t ts = 0;
static int anim_counter = 0;
uint32_t now = millis();
if(now > ts){
ts = now + FRAME_MS;
CHSV val;
switch((anim_counter/256)){
case 0: // RED
val = CHSV(0, 255, anim_counter % 255);
break;
case 1: // GREEN
val = CHSV(96, 255, anim_counter % 255);
break;
case 2: // BLUE
val = CHSV(160, 255, anim_counter % 255);
break;
}
if(++anim_counter >= 768)anim_counter = 0;
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = val;
}
FastLED.show();
}
}
#include <Adafruit_NeoPixel.h>
#define DATA_PIN 4
#define NUM_LEDS 7
// Little under 60Hz
#define FRAME_MS 17
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, DATA_PIN, NEO_RGB + NEO_KHZ800);
void setup() {
strip.begin();
// strip.setBrightness(50);
strip.show();
}
void loop() {
static uint32_t ts = 0;
static int anim_counter = 0;
uint32_t now = millis();
if(now > ts){
ts = now + FRAME_MS;
byte red = 0;
byte green = 0;
byte blue = 0;
switch((anim_counter/256)){
case 0: // RED
red = anim_counter % 255;
break;
case 1: // GREEN
green = anim_counter % 255;
break;
case 2: // BLUE
blue = anim_counter % 255;
break;
}
if(++anim_counter >= 768)anim_counter = 0;
for(int i = 0; i < NUM_LEDS; i++){
strip.setPixelColor(i, red, green, blue);
}
strip.show();
}
}
#include <Adafruit_NeoPixel.h>
#include <hsv2rgb.h>
#define DATA_PIN 4
#define NUM_LEDS 7
// Little under 60Hz
#define FRAME_MS 17
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, DATA_PIN, NEO_RGB + NEO_KHZ800);
void setup() {
strip.begin();
// strip.setBrightness(50);
strip.show();
}
void loop() {
static uint32_t ts = 0;
static int anim_counter = 0;
uint32_t now = millis();
if(now > ts){
ts = now + FRAME_MS;
CRGB val;
switch((anim_counter/256)){
case 0: // RED
val = CHSV(0, 255, anim_counter % 255);
break;
case 1: // GREEN
val = CHSV(96, 255, anim_counter % 255);
break;
case 2: // BLUE
val = CHSV(160, 255, anim_counter % 255);
break;
}
if(++anim_counter >= 768)anim_counter = 0;
for(int i = 0; i < NUM_LEDS; i++){
strip.setPixelColor(i, val.red, val.green, val.blue);
}
strip.show();
}
}
All four sketches were compiled using Arduino IDE 1.8.3 on Win10.
I compiled using Spence Konde's ATTinyCore v1.2.2, Neopixel v1.1.8 and FastLED v3.2.1.
The sketches expects a string of seven (configurable) Neopixels and will display a simple color chase where Red, Green and Blue will fade from black to full brightness consecutively. It runs at around 60Hz, but I didn't check how many cycles are going to waste. Might do that sometime...
Here's the results:
FastLED RGB: 3560 byte flash
FastLED HSV: 3894 byte flash
Adafruit RGB: 2796 byte flash
Adafruit HSV: 3200 byte flash
(Note: Adafruit HSV uses the hsv2rgb lib from FastLED since Adafruit's lib does not support HSV ootb.)
Adafruit comes out 764 bytes ahead of FastLED in RGB mode and 694 bytes in HSV mode.
The difference between RGB and HSV modes is 334 bytes for FastLED and 404 bytes for Adafruit.
This discrepancy is probably due to the fact that the CRGB class is used in both sketches for FastLED, but only introduced into the sketch in HSV mode for Adafruit, thus increasing the binary size by a larger margin for that case.
I think I will try to refactor the hsv2rgb code from FastLED into the Adafruit lib and leave out the CRGB/CHSV classes since they're not really needed in that case.
But I will definitely switch this project over to using Adafruit in order to save the 700 bytes of flash because it really is a lot on a Tiny85...
Cheers,
Shuzz