Advertisement
sprocket2cog

Ambient Light (arduino)

Oct 17th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <FastLED.h>
  2. // set up stuff !
  3. #define DATA_PIN     2
  4. #define CLOCK_PIN         3
  5. #define COLOR_ORDER GRB
  6. #define CHIPSET     LPD8806
  7. #define NUM_LEDS    14
  8. #define FRAMES_PER_SECOND 100
  9.  
  10. int incomingData = 0;    // for incoming serial data
  11. int cv=1.2; //color value multiplier
  12. int red1=0;
  13. int green1=0;
  14. int blue1=0;
  15.  
  16. CRGB leds[NUM_LEDS]; // make an array for the leds
  17.  
  18.  
  19. void setup() {
  20.   delay(3000); // sanity delay
  21.   Serial.begin(9600);
  22.   FastLED.addLeds<CHIPSET, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  23.   FastLED.setBrightness( 55);
  24. }
  25. void loop(){
  26.   if (Serial.available() >0){
  27.     // look for the next valid integer in the incoming serial stream:
  28.     int red = Serial.parseInt();
  29.     // do it again:
  30.     int green = Serial.parseInt();
  31.     // do it again:
  32.     int blue = Serial.parseInt();
  33.  
  34.     // look for the return. That's the end of your incoming string:
  35.     if (Serial.read() == '\r') {
  36.     // check to see which color is the higest value and increase by the color multiplier
  37.       if ((red > green) && (red > blue)) {
  38.        red=red*cv;
  39.    }
  40.       if ((blue > green) && (blue > red)) {
  41.        blue=blue*cv;
  42.    }
  43.       if ((green > red) && (green > blue)) {
  44.        green=green*cv;
  45.    }
  46.    //set the pixels in the stip to the colors  we read in before
  47.       for(int ledStrip = 0; ledStrip < NUM_LEDS; ledStrip = ledStrip + 1) {
  48.         leds[ledStrip] = CRGB(red,green,blue);
  49.      // }
  50.     }
  51.     }
  52.   }
  53.   FastLED.show();
  54.    FastLED.delay(1000 / FRAMES_PER_SECOND);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement