Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A flag
- #include "FastLED.h"
- #define LED_PIN 12
- #define CLK_PIN 11
- #define NUM_LEDS 20
- #define BRIGHTNESS 64
- #define LED_TYPE APA102
- #define COLOR_ORDER BGR
- CRGB leds[NUM_LEDS];
- int indexspeed = 2;
- int indexinc = 25;
- uint8_t updates_per_second = 100;
- CRGBPalette16 currentPalette;
- TBlendType currentBlending;
- void setup() {
- delay( 1000 ); // power-up safety delay
- FastLED.addLeds<LED_TYPE, LED_PIN, CLK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- SetupFlagPalette();
- }
- void loop() {
- static uint8_t startIndex = 0;
- startIndex = startIndex + indexspeed; /* motion speed */
- FillLEDsFromPaletteColors(startIndex);
- FastLED.show();
- FastLED.delay(1000 / updates_per_second);
- }
- void FillLEDsFromPaletteColors(uint8_t colorIndex) {
- for( int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette(currentPalette, colorIndex, 255, currentBlending);
- colorIndex += indexinc; // How quickly we change colours
- }
- }
- // This function sets up a palette of red white and blue.
- void SetupFlagPalette() {
- CRGB red = CRGB::Red;
- CRGB white = CRGB::White;
- CRGB blue = CRGB::Blue;
- currentPalette = CRGBPalette16(
- red, red, red, red, red,
- white, white, white, white, white, white,
- blue, blue, blue, blue, blue );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement