Skip to content

Instantly share code, notes, and snippets.

@fdciabdul
Created January 17, 2019 11:21
Show Gist options
  • Save fdciabdul/5282ab94016866f17c3f1bffe61ffcaf to your computer and use it in GitHub Desktop.
Save fdciabdul/5282ab94016866f17c3f1bffe61ffcaf to your computer and use it in GitHub Desktop.
#include <FastLED.h>
// set up stuff !
#define DATA_PIN 2
#define CLOCK_PIN 3
#define COLOR_ORDER GRB
#define CHIPSET LPD8806
#define NUM_LEDS 14
#define FRAMES_PER_SECOND 100
int incomingData = 0; // for incoming serial data
int cv=1.2; //color value multiplier
int red1=0;
int green1=0;
int blue1=0;
CRGB leds[NUM_LEDS]; // make an array for the leds
void setup() {
delay(3000); // sanity delay
Serial.begin(9600);
FastLED.addLeds<CHIPSET, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness( 55);
}
void loop(){
if (Serial.available() >0){
// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();
// look for the return. That's the end of your incoming string:
if (Serial.read() == '\r') {
// check to see which color is the higest value and increase by the color multiplier
if ((red > green) && (red > blue)) {
red=red*cv;
}
if ((blue > green) && (blue > red)) {
blue=blue*cv;
}
if ((green > red) && (green > blue)) {
green=green*cv;
}
//set the pixels in the stip to the colors we read in before
for(int ledStrip = 0; ledStrip < NUM_LEDS; ledStrip = ledStrip + 1) {
leds[ledStrip] = CRGB(red,green,blue);
// }
}
}
}
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment