Advertisement
atuline

A FastLED US flag

Feb 25th, 2015
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. // A flag
  2.  
  3. #include "FastLED.h"
  4.  
  5. #define LED_PIN     12
  6. #define CLK_PIN     11
  7. #define NUM_LEDS    20
  8. #define BRIGHTNESS  64
  9. #define LED_TYPE    APA102
  10. #define COLOR_ORDER BGR
  11. CRGB leds[NUM_LEDS];
  12.  
  13. int indexspeed = 2;
  14. int indexinc = 25;
  15. uint8_t updates_per_second = 100;
  16.  
  17. CRGBPalette16 currentPalette;
  18. TBlendType    currentBlending;
  19.  
  20.  
  21. void setup() {
  22.   delay( 1000 ); // power-up safety delay
  23.   FastLED.addLeds<LED_TYPE, LED_PIN, CLK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  24.   FastLED.setBrightness(BRIGHTNESS);
  25.   SetupFlagPalette();
  26. }
  27.  
  28.  
  29. void loop() {
  30.   static uint8_t startIndex = 0;
  31.   startIndex = startIndex + indexspeed; /* motion speed */
  32.   FillLEDsFromPaletteColors(startIndex);
  33.   FastLED.show();
  34.   FastLED.delay(1000 / updates_per_second);
  35. }
  36.  
  37. void FillLEDsFromPaletteColors(uint8_t colorIndex) {
  38.   for( int i = 0; i < NUM_LEDS; i++) {
  39.     leds[i] = ColorFromPalette(currentPalette, colorIndex, 255, currentBlending);
  40.     colorIndex += indexinc;     // How quickly we change colours
  41.   }
  42. }
  43.  
  44.  
  45. // This function sets up a palette of red white and blue.
  46. void SetupFlagPalette() {
  47.  
  48.   CRGB red    = CRGB::Red;
  49.   CRGB white  = CRGB::White;
  50.   CRGB blue   = CRGB::Blue;
  51.  
  52.   currentPalette = CRGBPalette16(
  53.     red, red, red, red, red,
  54.     white, white, white, white, white, white,
  55.     blue, blue, blue, blue, blue );
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement