Skip to content

Instantly share code, notes, and snippets.

@jwhendy
Last active April 7, 2022 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwhendy/64cd399100633c8b9edd to your computer and use it in GitHub Desktop.
Save jwhendy/64cd399100633c8b9edd to your computer and use it in GitHub Desktop.
#include "FastLED.h"
#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3
// blend() below can take two CRGB or CHSV colors
// CRGB color1 = CRGB(255, 0, 0);
// CRGB color2 = CRGB(0, 0, 255);
// the output of blend() needs to be CRGB to pass to
// showAnalogRGB() below
CRGB color_current;
CHSV color1 = CHSV(0, 255, 255);
CHSV color2 = CHSV(180, 255, 255);
void showAnalogRGB( const CRGB& rgb)
{
analogWrite(REDPIN, rgb.r );
analogWrite(GREENPIN, rgb.g );
analogWrite(BLUEPIN, rgb.b );
}
void setup()
{
Serial.begin(9600);
pinMode(REDPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
// prints a first "header" for easy .csv copy/paste from serial monitor
// to Excel/LibreOffice
Serial.println("r,g,b");
}
void loop()
{
// looks like the third parameter of blend is an int between 0-255 for
// what % of color2 to use (corresponding to 0-100%). To fiddle with steps/speed
// you could change what i stops at (< 255 or not all the way), the increment
// (use i = i+n instead of i++), or just play with the delay() at the end.
// You could also wrap in EVERY_N_MILLISECONDS(n){} if you need to multitask
for(int i = 0; i < 255; i++) {
color_current = blend(color1, color2, i);
showAnalogRGB(color_current);
// uncomment to capture the raw RGB values
/*
Serial.print(color_current.r);
Serial.print(",");
Serial.print(color_current.g);
Serial.print(",");
Serial.print(color_current.b);
Serial.println(",");
*/
// change to set the blend time
delay(20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment